Beispiel #1
0
def test_checksum_is_not_a_string():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item=dict(url='http://example.com/', md5=[]),
                               problems=problems,
                               requirements=requirements)
    assert ['Checksum value for FOO should be a string not [].'] == problems
    assert len(requirements) == 0
Beispiel #2
0
 def check_not_set(dirname):
     local_state = LocalStateFile.load_for_directory(dirname)
     requirement = DownloadRequirement(registry=PluginRegistry(),
                                       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
Beispiel #3
0
def test_unzip_is_not_a_bool():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item=dict(url='http://example.com/', unzip=[]),
                               problems=problems,
                               requirements=requirements)
    assert [
        "Value of 'unzip' for download item FOO should be a boolean, not []."
    ] == problems
    assert len(requirements) == 0
Beispiel #4
0
def test_download_item_is_none_not_a_string_or_dict():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item=None,
                               problems=problems,
                               requirements=requirements)
    assert [
        "Download name FOO should be followed by a URL string or a dictionary describing the download."
    ] == problems
    assert len(requirements) == 0
Beispiel #5
0
def test_description_is_not_a_string():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item=dict(url='http://example.com/',
                                         description=[]),
                               problems=problems,
                               requirements=requirements)
    assert ["'description' field for download item FOO is not a string"
            ] == problems
    assert len(requirements) == 0
Beispiel #6
0
def test_use_unzip_if_url_ends_in_zip():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item='http://example.com/bar.zip',
                               problems=problems,
                               requirements=requirements)
    assert [] == problems
    assert len(requirements) == 1
    assert requirements[0].filename == 'bar'
    assert requirements[0].url == 'http://example.com/bar.zip'
    assert requirements[0].unzip
Beispiel #7
0
def test_description_property():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item=dict(url='http://example.com/',
                                         description="hi"),
                               problems=problems,
                               requirements=requirements)
    assert [] == problems
    assert len(requirements) == 1
    assert requirements[0].title == 'FOO'
    assert requirements[0].description == 'hi'
Beispiel #8
0
def test_use_variable_name_for_filename():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item='http://example.com/',
                               problems=problems,
                               requirements=requirements)
    assert [] == problems
    assert len(requirements) == 1
    assert requirements[0].filename == 'FOO'
    assert requirements[0].url == 'http://example.com/'
    assert not requirements[0].unzip
Beispiel #9
0
def test_no_unzip_if_url_ends_in_zip_and_filename_also_does():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item=dict(url='http://example.com/bar.zip',
                                         filename='something.zip'),
                               problems=problems,
                               requirements=requirements)
    assert [] == problems
    assert len(requirements) == 1
    assert requirements[0].filename == 'something.zip'
    assert requirements[0].url == 'http://example.com/bar.zip'
    assert not requirements[0].unzip
Beispiel #10
0
def test_allow_manual_override_of_use_unzip_if_url_ends_in_zip():
    problems = []
    requirements = []
    DownloadRequirement._parse(PluginRegistry(),
                               varname='FOO',
                               item=dict(url='http://example.com/bar.zip',
                                         unzip=False),
                               problems=problems,
                               requirements=requirements)
    assert [] == problems
    assert len(requirements) == 1
    assert requirements[0].filename == 'bar.zip'
    assert requirements[0].url == 'http://example.com/bar.zip'
    assert not requirements[0].unzip
Beispiel #11
0
 def downloaded_file_valid(dirname):
     local_state = LocalStateFile.load_for_directory(dirname)
     filename = os.path.join(dirname, 'data.zip')
     requirement = DownloadRequirement(registry=PluginRegistry(),
                                       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
Beispiel #12
0
 def check_missing_filename(dirname):
     local_state = LocalStateFile.load_for_directory(dirname)
     filename = '/data.zip'
     requirement = DownloadRequirement(registry=PluginRegistry(),
                                       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
Beispiel #13
0
def _download_requirement():
    return DownloadRequirement(registry=PluginRegistry(),
                               env_var="DATAFILE",
                               url='http://localhost/data.csv',
                               filename='data.csv')