Common cross-app utils
Common
Helper functions for unit and integration tests
- class common.testUtils.TestHelpers
Bases:
object
Helper function for various test classes below
- classmethod copy_with_new_name(jsonFileToCopy, newName, newFilenamePrefix=None)
Copies the file to a tempfile, but changes the name. Returns the tempfile
- classmethod create_non_admin_api_user()
Basic setup for tests: create a non-admin API user
- classmethod create_request_mock(data, statusCode)
Creates a mock function call for the requests library
- classmethod does_fieldfile_equal_file(fsFilePath, fieldFile)
Does the FieldFile (django field) equal the file at fsFilePath?
- classmethod generate_random_valid_json_of_size(numBytes)
Generates a valid but strange JSON of size num_bytes and returns the filename
- classmethod get_email_reg_link(outbox)
Gets the auth regisration link from the email outbox
- classmethod get_headless_browser()
Returns a headless browser
- classmethod get_latest_upload()
Returns the last-uploaded json config
- classmethod get_multiwinner_upload_response(client)
Uploads the multiwinner json file and returns a response
- classmethod give_auth(user, auths)
Gives auth or list of auths to the current user, then refetches user from the db
- classmethod login(client)
Forces a login. Creates a user as needed, and returns that user
- classmethod login_with_scrape_permissions(client)
Logs in and creates permissions needed to run scraper
- classmethod logout(client)
Logs out (if logged in)
- classmethod make_multi_scraper()
Creates a multi-scraper object. You must mock out requests.get if you plan to scrape.
- classmethod make_scraper()
Creates a scraper object. You must mock out requests.get if you plan to scrape.
- classmethod mock_scraper_url_with_file(requestMock, url='mock://scrape', filename='testData/oneRound.json')
Creates a valid response from the server
- classmethod modify_json_with(jsonFilename, modifierFunc)
Given a modifierFunc which modifies the data in the given file, updates the json file and returns a Tempfile holding the new data
- classmethod setup_host_mocks(testClass)
Mock out get_host (since tests don’t set it but visualizer depends on it
- classmethod silence_logging_spam()
Clean up output of misc libraries
Utility functions shared across views, in either movie or visualizer apps
- class common.viewUtils.DefaultConfig
Bases:
object
A simplified JsonConfig with just the default values. Use this to pass to functions that require a config if you do not have or need a config (e.g. in validators).
- common.viewUtils.default_iframe_height(numCandidates)
How tall should the iframe be for a vis with this # of candidates?
- common.viewUtils.get_data_for_graph(graph, config)
Helper function for get_data_for_view: convert the graph to data to be passed on to JS.
- common.viewUtils.get_data_for_round_describer(graph, config)
Helper function for get_data_for_view: convert the round describer to data to be passed on to JS
- common.viewUtils.get_data_for_view(config)
All data needed to pass on to the visualize or visualizeembedded view
- common.viewUtils.get_embed_html(embedlyUrl, maxwidth, maxheight)
Given the absolute URL to the visualizeEmbedly page, returns the UTF-8 encoded HTML needed to embed that page in an iframe.
- common.viewUtils.get_script_to_disable_animations()
Disables transitions on the current page
- common.viewUtils.request_to_domain(request)
Gets the domain name from the request