def check_not_set(dirname): local_state = LocalStateFile.load_for_directory(dirname) requirement = DownloadRequirement(registry=RequirementsRegistry(), env_var=ENV_VAR, url='http://example.com', filename=ENV_VAR) status = requirement.check_status(dict(PROJECT_DIR=dirname), local_state, 'default', UserConfigOverrides()) assert not status assert "Environment variable {} is not set.".format(ENV_VAR) == status.status_description
def test_description_property(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item=dict(url='http://example.com/', description="hi"), problems=problems) assert [] == problems assert kwargs['description'] == 'hi' req = DownloadRequirement(RequirementsRegistry(), **kwargs) assert req.title == 'FOO'
def test_use_unzip_if_url_ends_in_zip(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item='http://example.com/bar.zip', problems=problems) assert [] == problems assert kwargs['filename'] == 'bar' assert kwargs['url'] == 'http://example.com/bar.zip' assert kwargs['unzip'] req = DownloadRequirement(RequirementsRegistry(), **kwargs) assert req.filename == 'bar' assert req.url == 'http://example.com/bar.zip' assert req.unzip
def downloaded_file_valid(dirname): local_state = LocalStateFile.load_for_directory(dirname) filename = os.path.join(dirname, 'data.zip') requirement = DownloadRequirement(registry=RequirementsRegistry(), env_var=ENV_VAR, url='http://localhost/data.zip', filename='data.zip') status = requirement.check_status({ ENV_VAR: filename, 'PROJECT_DIR': dirname }, local_state, 'default', UserConfigOverrides()) assert status assert 'File downloaded to {}'.format(filename) == status.status_description
def check_missing_filename(dirname): local_state = LocalStateFile.load_for_directory(dirname) filename = '/data.zip' requirement = DownloadRequirement(registry=RequirementsRegistry(), env_var=ENV_VAR, url='http://localhost/data.zip', filename='data.zip') status = requirement.check_status({ ENV_VAR: filename, 'PROJECT_DIR': dirname }, local_state, 'default', UserConfigOverrides()) assert not status assert 'File not found: {}'.format(filename) == status.status_description
def test_allow_manual_override_of_use_unzip_if_url_ends_in_zip(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item=dict(url='http://example.com/bar.zip', unzip=False), problems=problems) assert [] == problems assert kwargs['filename'] == 'bar.zip' assert kwargs['url'] == 'http://example.com/bar.zip' assert not kwargs['unzip'] req = DownloadRequirement(RequirementsRegistry(), **kwargs) assert req.filename == 'bar.zip' assert req.url == 'http://example.com/bar.zip' assert not req.unzip
def test_unzip_is_not_a_bool(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item=dict(url='http://example.com/', unzip=[]), problems=problems) assert ["Value of 'unzip' for download item FOO should be a boolean, not []."] == problems assert kwargs is None
def test_description_is_not_a_string(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item=dict(url='http://example.com/', description=[]), problems=problems) assert ["'description' field for download item FOO is not a string"] == problems assert kwargs is None
def test_use_variable_name_for_filename(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item='http://example.com/', problems=problems) assert [] == problems assert kwargs['filename'] == 'FOO' assert kwargs['url'] == 'http://example.com/' assert not kwargs['unzip']
def test_checksum_is_not_a_string(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item=dict(url='http://example.com/', md5=[]), problems=problems) assert ['Checksum value for FOO should be a string not [].'] == problems assert kwargs is None
def test_download_item_is_none_not_a_string_or_dict(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item=None, problems=problems) assert [ "Download name FOO should be followed by a URL string or a dictionary describing the download." ] == problems assert kwargs is None
def test_no_unzip_if_url_ends_in_zip_and_filename_also_does(): problems = [] kwargs = DownloadRequirement._parse(varname='FOO', item=dict(url='http://example.com/bar.zip', filename='something.zip'), problems=problems) assert [] == problems assert kwargs['filename'] == 'something.zip' assert kwargs['url'] == 'http://example.com/bar.zip' assert not kwargs['unzip']
def _download_requirement(): return DownloadRequirement(registry=RequirementsRegistry(), env_var="DATAFILE", url='http://localhost/data.csv', filename='data.csv')