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 _download_requirement(): return DownloadRequirement(registry=RequirementsRegistry(), env_var="DATAFILE", url='http://localhost/data.csv', filename='data.csv')