def test_validate_zipball_has_no_md5_dir(ZipFile, is_zipfile, *ignored): """ If zipball doesn't contain md5 directory, returns False """ is_zipfile.return_value = True path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' ZipFile.return_value.namelist.return_value = [] with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_zipball_contains_non_dir_md5(ZipFile, is_zipfile, *ignored): """ If zipball contains md5 path that isn't a dir, returns False """ is_zipfile.return_value = True path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' ZipFile.return_value.namelist.return_value = [ '202ab62b551f6d7fc002f65652525544'] with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_zipball_contains_index_html(ZipFile, is_zipfile, get_metadata, metadata): is_zipfile.return_value = True path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' ZipFile.return_value.namelist.return_value = [ '202ab62b551f6d7fc002f65652525544/'] get_metadata.return_value = metadata with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_zipball_invalid_meta(ZipFile, is_zipfile, get_metadata): """ If zipball doesn't contain valid metadata keys, returns False """ is_zipfile.return_value = True path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' ZipFile.return_value.namelist.return_value = [ '202ab62b551f6d7fc002f65652525544/', '202ab62b551f6d7fc002f65652525544/index.html'] get_metadata.side_effect = mod.metadata.MetadataError('msg', {}) with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_zipball_contains_info_json(ZipFile, is_zipfile, get_metadata): """ If zipball doesn't contain info.json, returns False """ is_zipfile.return_value = True path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' ZipFile.return_value.namelist.return_value = [ '202ab62b551f6d7fc002f65652525544/'] get_metadata.side_effect = KeyError() with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_zipball_valid(exists, ZipFile, is_zipfile, get_metadata, metadata): exists.return_value = True is_zipfile.return_value = True path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' ZipFile.return_value.namelist.return_value = [ '202ab62b551f6d7fc002f65652525544/', '202ab62b551f6d7fc002f65652525544/index.html'] get_metadata.return_value = metadata assert mod.validate(path) is get_metadata.return_value
def test_validate_zipball_not_zipfile(is_zipfile, *ignored): """ If path does not point to a valid zipfile, returns False """ is_zipfile.return_value = False path = '/var/spool/downloads/content/202ab62b551f6d7fc002f65652525544.zip' with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_zipball_wrong_name(*ignored): """ If filename isn't MD5 hash, returns False """ path = '/var/spool/downloads/content/foo.zip' with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_wrong_extension(*ignored): """ If extension isn't .zip, returns False """ path = '/var/spool/downloads/foo.txt' with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_path_does_not_exists(exists): """ If path does not exist, raise ValidationError """ path = '/var/spool/downloads/foo.txt' exists.return_value = False with pytest.raises(mod.ValidationError): mod.validate(path)
def test_validate_no_path(*ignored): """ If path is empty or None, raise ValidationError """ for path in ('', None): with pytest.raises(mod.ValidationError): mod.validate(path)