Ejemplo n.º 1
0
RESOURCE_TYPES = ('file', 'file.upload', 'api', 'documentation',
                  'image', 'visualization')


resource = {
    'id': str,
    'position': int,
    'name': All(DefaultTo(''), str),
    'description': All(str, normalize_string),
    'format': All(str, Lower),
    'mimetype': Any(All(str, Lower), None),
    'size': Any(Coerce(int), None),
    'hash': Any(All(str, hash), None),
    'created': All(str, to_date),
    'last_modified': Any(All(str, to_date), None),
    'url': All(str, is_url()),
    'resource_type': All(empty_none,
                         DefaultTo('file'),
                         str,
                         Any(*RESOURCE_TYPES)
                         ),
}

tag = {
    'id': str,
    Optional('vocabulary_id'): Any(str, None),
    Optional('display_name'): str,
    'name': All(str, normalize_tag),
    Optional('state'): str,
}
Ejemplo n.º 2
0
 def test_valid_url_with_default_scheme(self):
     f = filters.is_url()
     assert f('somewhere.com/path') == 'http://somewhere.com/path'
Ejemplo n.º 3
0
 'organization':
 basestring,
 'private':
 boolean,
 'resources':
 All(force_list, [{
     'name':
     basestring,
     'description':
     All(basestring, normalize_string),
     'format':
     All(basestring, Lower, Any('cle', 'csv', 'pdf', 'txt')),
     Optional('last_modified'):
     All(basestring, to_date),
     'url':
     All(basestring, is_url(full=True)),
 }]),
 'state':
 Any(basestring, None),
 'supplier':
 basestring,
 'tags':
 All(basestring, taglist),
 'temporal_coverage_from':
 None,
 'temporal_coverage_to':
 None,
 'territorial_coverage': {
     'territorial_coverage_code':
     All(basestring, Lower, In(ZONES.keys())),
     'territorial_coverage_granularity':
Ejemplo n.º 4
0
 def test_allowed_scheme_not_allowed(self):
     f = filters.is_url()
     with self.assertRaises(Invalid):
         f('not-allowed://somewhere.com')
Ejemplo n.º 5
0
 def test_allowed_scheme_not_allowed(self):
     f = filters.is_url()
     with pytest.raises(Invalid):
         f('not-allowed://somewhere.com')
Ejemplo n.º 6
0
 def test_valid_url_with_defaults(self):
     f = filters.is_url()
     self.assertEqual(f('https://somewhere.com/path'),
                      'https://somewhere.com/path')
Ejemplo n.º 7
0
        }],
        'frequency': All(Lower, In(FREQUENCIES.keys())),
        'groups': Any(None, All(Lower, 'agriculture et alimentation')),
        'id': basestring,
        'license_id': Any('fr-lo'),
        'maintainer': Any(basestring, None),
        'maintainer_email': Any(All(basestring, email), None),
        'notes': All(basestring, normalize_string),
        'organization': basestring,
        'private': boolean,
        'resources': All(force_list, [{
            'name': basestring,
            'description': All(basestring, normalize_string),
            'format': All(basestring, Lower, Any('cle', 'csv', 'pdf', 'txt')),
            Optional('last_modified'): All(basestring, to_date),
            'url': All(basestring, is_url(full=True)),
        }]),
        'state': Any(basestring, None),
        'supplier': basestring,
        'tags': All(basestring, taglist),
        'temporal_coverage_from': None,
        'temporal_coverage_to': None,
        'territorial_coverage': {
            'territorial_coverage_code':
            All(basestring, Lower, In(ZONES.keys())),
            'territorial_coverage_granularity':
            All(basestring, Lower, In(GRANULARITIES.keys())),
        },
        'title': basestring,
    },
}, required=True, extra=True)
Ejemplo n.º 8
0
 def test_valid_url_with_default_scheme(self):
     f = filters.is_url()
     assert f('somewhere.com/path') == 'http://somewhere.com/path'
Ejemplo n.º 9
0
                  'image', 'visualization')

ALLOWED_RESOURCE_TYPES = ('file', 'file.upload', 'api', 'metadata')

resource = {
    'id': basestring,
    'position': int,
    'name': All(DefaultTo(''), basestring),
    'description': All(basestring, normalize_string),
    'format': All(basestring, Lower),
    'mimetype': Any(All(basestring, Lower), None),
    'size': Any(Coerce(int), None),
    'hash': Any(All(basestring, hash), None),
    'created': All(basestring, to_date),
    'last_modified': Any(All(basestring, to_date), None),
    'url': All(basestring, is_url()),
    'resource_type': All(empty_none,
                         DefaultTo('file'),
                         basestring,
                         Any(*RESOURCE_TYPES)
                         ),
}

tag = {
    'id': basestring,
    'vocabulary_id': Any(basestring, None),
    'display_name': basestring,
    'name': All(basestring, normalize_tag),
    'state': basestring,
}
Ejemplo n.º 10
0
 'maintainer_email':
 Any(All(str, email), None),
 'notes':
 All(str, normalize_string),
 'organization':
 str,
 'private':
 boolean,
 'resources':
 All(force_list,
     [{
         'name': str,
         'description': All(str, normalize_string),
         'format': All(str, Lower, Any('cle', 'csv', 'pdf', 'txt')),
         Optional('last_modified'): All(str, to_date),
         'url': All(str, is_url(full=True)),
     }]),
 'state':
 Any(str, None),
 'supplier':
 str,
 'tags':
 All(str, taglist),
 'temporal_coverage_from':
 None,
 'temporal_coverage_to':
 None,
 'territorial_coverage': {
     'territorial_coverage_code':
     All(str, Lower, In(ZONES.keys())),
     'territorial_coverage_granularity':