def test_fixtures(self):
     inpath = 'tests/fixtures/ckan_resource.json'
     exppath = 'tests/fixtures/frictionless_resource.json'
     indict = json.load(open(inpath))
     exp = json.load(open(exppath))
     out = converter.resource(indict)
     assert out == exp
 def test_resource_keys_pass_through(self):
     indict = {
         'id': 'xxx',
         'name': 'abc',
         'description': 'GDPs list',
         'format': 'CSV',
         'hash': 'e785c0883d7a104330e69aee73d4f235',
         'schema': {
             'fields': [
                 {
                     'name': 'id',
                     'type': 'integer'
                 },
                 {
                     'name': 'title',
                     'type': 'string'
                 },
             ]
         },
         # random
         'adfajka': 'aaaa',
         '1dafak': 'abbbb'
     }
     exp = indict
     out = converter.resource(indict)
     assert out == exp
 def test_keys_are_removed_that_should_be(self):
     indict = {
         "package_id": "xxx",
         "position": 2,
         "datastore_active": True,
         "state": "active"
     }
     exp = {}
     out = converter.resource(indict)
     assert out == exp
 def test_resource_path_is_set_even_for_uploaded_resources(self):
     indict = {
         "url": "http://www.somewhere.com/data.csv",
         "url_type": "upload"
     }
     exp = {
         'path': 'http://www.somewhere.com/data.csv',
         'url_type': "upload"
     }
     out = converter.resource(indict)
     assert out == exp
    def test_values_are_unjsonified(self):
        '''Test values which are jsonified dict or arrays are unjsonified'''
        schema = {"fields": [{"name": "abc", "type": "string"}]}
        indict = {
            "schema": json.dumps(schema),
            "otherval": json.dumps(schema),
            "x": "{'abc': 1"
        }
        exp = {
            "schema": schema,
            "otherval": schema,
            # fake json object - not really ... but looks like it ...
            "x": "{'abc': 1"
        }
        out = converter.resource(indict)
        assert out == exp

        indict = {"x": "hello world", "y": "1.3"}
        exp = {"x": "hello world", "y": "1.3"}
        out = converter.resource(indict)
        assert out == exp
 def test_resource_mapping(self):
     indict = {
         "url": "http://www.somewhere.com/data.csv",
         "size": 110,
         "mimetype": "text/csv"
     }
     exp = {
         "path": "http://www.somewhere.com/data.csv",
         "bytes": 110,
         "mediatype": "text/csv"
     }
     out = converter.resource(indict)
     assert out == exp
 def test_all_keys_are_passed_through(self):
     indict = {
         'description': 'GDPs list',
         'schema': {
             'fields': [
                 {
                     'name': 'id',
                     'type': 'integer'
                 },
                 {
                     'name': 'title',
                     'type': 'string'
                 },
             ]
         },
         # random
         'adfajka': 'aaaa',
         '1dafak': 'abbbb'
     }
     exp = indict
     out = converter.resource(indict)
     assert out == exp
 def test_nulls_are_stripped(self):
     indict = {'abc': 'xxx', 'size': None, 'xyz': None}
     exp = {'abc': 'xxx'}
     out = converter.resource(indict)
     assert out == exp