Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_local_with_relative_resources_paths_is_safe():
package = Package('data/datapackage_with_foo.txt_resource.json', {})
assert package.safe()
def test_init_raises_if_url_isnt_a_json():
url = 'http://someplace.com/datapackage.json'
body = 'Not a JSON'
httpretty.register_uri(httpretty.GET, url, body=body, content_type='application/json')
with pytest.raises(exceptions.DataPackageException):
Package(url)
def test_base_path_defaults_to_none():
assert Package().base_path is None
def test_init_accepts_dicts():
descriptor = {
'profile': 'data-package',
}
package = Package(descriptor)
assert package.descriptor == descriptor
def test_should_raise_if_zipfile_raised_LargeZipFile(zipfile_mock, tmpfile):
zipfile_mock.side_effect = zipfile.LargeZipFile()
package = Package({}, {})
with pytest.raises(exceptions.DataPackageException):
package.save(tmpfile)
def test_generates_filenames_for_named_resources(self, tmpfile):
descriptor = {
'name': 'proverbs',
'resources': [
{'name': 'proverbs', 'format': 'TXT', 'path': 'unicode.txt'},
{'name': 'proverbs_without_format', 'path': 'unicode.txt'}
]
}
schema = {}
dp = datapackage.DataPackage(
descriptor, schema, default_base_path='tests/fixtures')
dp.save(tmpfile)
with zipfile.ZipFile(tmpfile, 'r') as z:
assert 'data/proverbs.txt' in z.namelist()
assert 'data/proverbs_without_format' in z.namelist()
def setUp(self):
# GIVEN datapackage that can be treated as valid by the dpm
self.valid_dp = datapackage.DataPackage({
"name": "some-datapackage",
"resources": [
{"name": "some-resource", "path": "./data/some_data.csv", }
]
},
default_base_path='.')
patch('dpm.client.DataPackage', lambda *a: self.valid_dp).start()
patch('dpm.client.exists', lambda *a: True).start()
def test_schema(self):
descriptor = {}
schema = {'foo': 'bar'}
dp = datapackage.DataPackage(descriptor, schema=schema)
assert dp.schema.to_dict() == schema
def test_resources_are_empty_tuple_by_default(self):
descriptor = {}
dp = datapackage.DataPackage(descriptor)
assert dp.resources == ()
def test_base_path_cant_be_set_directly(self):
dp = datapackage.DataPackage()
with pytest.raises(AttributeError):
dp.base_path = 'foo'