def openness_score(pkg):
    score = 0
    fmt = schema_description.resource_field_by_id['format']['choices_by_key']
    for r in pkg['resources']:
        if r['resource_type'] != 'file' and r['resource_type'] != 'api':
            continue
        resource_score = fmt[r['format']]['openness_score']
        if boolean_validator(r.get('data_includes_uris', ''), {}):
            resource_score = 4
            if boolean_validator(r.get('data_includes_links', ''), {}):
                resource_score = 5
        score = max(score, resource_score)
    return score
Beispiel #2
0
def openness_score(pkg):
    score = 0
    fmt = schema_description.resource_field_by_id['format']['choices_by_key']
    for r in pkg['resources']:
        if r['resource_type'] != 'file' and r['resource_type'] != 'api':
            continue
        resource_score = fmt[r['format']]['openness_score']
        if boolean_validator(r.get('data_includes_uris', ''), {}):
            resource_score = 4
            if boolean_validator(r.get('data_includes_links', ''), {}):
                resource_score = 5
        score = max(score, resource_score)
    return score
def _trim_package(pkg):
    """
    remove keys from pkg that we don't care about when comparing
    or updating/creating packages.  Also try to convert types and
    create missing fields that will be present in package_show.
    """
    # XXX full of custom hacks and deep knowledge of our schema :-(
    if not pkg:
        return
    for k in ['extras', 'metadata_modified', 'metadata_created',
            'revision_id', 'revision_timestamp', 'organization',
            'version', 'tracking_summary',
            'tags', # just because we don't use them
            'num_tags', 'num_resources', 'maintainer',
            'isopen', 'relationships_as_object', 'license_title',
            'license_title_fra', 'license_url_fra', 'license_url',
            'author',
            'groups', # just because we don't use them
            'relationships_as_subject', 'department_number',
            # FIXME: remove these when we can:
            'resource_type',
            # new in 2.3:
            'creator_user_id',
            ]:
        if k in pkg:
            del pkg[k]
    for r in pkg['resources']:
        for k in ['package_id', 'revision_id',
                'revision_timestamp', 'cache_last_updated',
                'webstore_last_updated', 'state', 'hash',
                'description', 'tracking_summary', 'mimetype_inner',
                'mimetype', 'cache_url', 'created', 'webstore_url',
                'last_modified', 'position']:
            if k in r:
                del r[k]
        for k in ['name', 'size']:
            if k not in r:
                r[k] = None
    for k in ['private']:
        pkg[k] = boolean_validator(unicode(pkg.get(k, '')), None)
    if 'name' not in pkg:
        pkg['name'] = pkg['id']
    if 'type' not in pkg:
        pkg['type'] = 'dataset'
    if 'state' not in pkg:
        pkg['state'] = 'active'
    for k in ['url']:
        if k not in pkg:
            pkg[k] = ''
    for name, lang, field in schema_description.dataset_field_iter():
        if field['type'] == 'date':
            try:
                pkg[name] = str(isodate(pkg[name], None)) if pkg.get(name) else ''
            except Invalid:
                pass # not for us to fail validation
        elif field['type'] == 'url':
            if not pkg.get(name): # be consistent about what an empty url is
                pkg[name] = ""
        elif field['type'] == 'fixed' and name in pkg:
            del pkg[name]
Beispiel #4
0
 def test_missing(self):
     assert_equals(validators.boolean_validator('', None), False)
Beispiel #5
0
 def test_bool_false(self):
     assert_equals(validators.boolean_validator(False, None), False)
Beispiel #6
0
 def test_bool_true(self):
     assert_equals(validators.boolean_validator(True, None), True)
Beispiel #7
0
 def test_string_false(self):
     assert_equals(validators.boolean_validator('f', None), False)
Beispiel #8
0
 def test_string_true(self):
     assert_equals(validators.boolean_validator('true', None), True)
     assert_equals(validators.boolean_validator('yes', None), True)
     assert_equals(validators.boolean_validator('t', None), True)
     assert_equals(validators.boolean_validator('y', None), True)
     assert_equals(validators.boolean_validator('1', None), True)
Beispiel #9
0
def test_bool_false():
    assert not validators.boolean_validator(False, None)
Beispiel #10
0
 def test_string_false(self):
     assert_equals(validators.boolean_validator('f', None), False)
Beispiel #11
0
 def test_bool_false(self):
     assert_equals(validators.boolean_validator(False, None), False)
Beispiel #12
0
 def test_bool_true(self):
     assert_equals(validators.boolean_validator(True, None), True)
Beispiel #13
0
def _trim_package(pkg):
    """
    remove keys from pkg that we don't care about when comparing
    or updating/creating packages.  Also try to convert types and
    create missing fields that will be present in package_show.
    """
    # XXX full of custom hacks and deep knowledge of our schema :-(
    if not pkg:
        return
    for k in ['extras', 'metadata_modified', 'metadata_created',
            'revision_id', 'revision_timestamp', 'organization',
            'version', 'tracking_summary',
            'tags', # just because we don't use them
            'num_tags', 'num_resources', 'maintainer',
            'isopen', 'relationships_as_object', 'license_title',
            'license_title_fra', 'license_url_fra', 'license_url',
            'maintainer_email', 'author',
            'groups', # just because we don't use them
            'relationships_as_subject', 'department_number',
            # FIXME: remove these when we can:
            'resource_type',
            ]:
        if k in pkg:
            del pkg[k]
    for r in pkg['resources']:
        for k in ['resource_group_id', 'revision_id',
                'revision_timestamp', 'cache_last_updated',
                'webstore_last_updated', 'id', 'state', 'hash',
                'description', 'tracking_summary', 'mimetype_inner',
                'mimetype', 'cache_url', 'created', 'webstore_url',
                'last_modified', 'position', ]:
            if k in r:
                del r[k]
        for k in ['name', 'size']:
            if k not in r:
                r[k] = None
    for k in ['ready_to_publish', 'private']:
        pkg[k] = boolean_validator(unicode(pkg.get(k, '')), None)
    if 'name' not in pkg:
        pkg['name'] = pkg['id']
    if 'type' not in pkg:
        pkg['type'] = 'dataset'
    if 'state' not in pkg:
        pkg['state'] = 'active'
    for k in ['url']:
        if k not in pkg:
            pkg[k] = ''
    for name, lang, field in schema_description.dataset_field_iter():
        if field['type'] == 'date':
            try:
                pkg[name] = str(isodate(pkg[name], None)) if pkg.get(name) else ''
            except Invalid:
                pass # not for us to fail validation
        elif field['type'] == 'tag_vocabulary' and not isinstance(
                pkg.get(name), list):
            pkg[name] = convert_pilot_uuid_list(field)(pkg.get(name, []))
        elif field['type'] == 'url':
            if not pkg.get(name): # be consistent about what an empty url is
                pkg[name] = ""
        elif field['type'] == 'fixed' and name in pkg:
            del pkg[name]
Beispiel #14
0
def test_string_false():
    assert not validators.boolean_validator("f", None)
Beispiel #15
0
def test_string_true():
    assert validators.boolean_validator("true", None)
    assert validators.boolean_validator("yes", None)
    assert validators.boolean_validator("t", None)
    assert validators.boolean_validator("y", None)
    assert validators.boolean_validator("1", None)
Beispiel #16
0
def test_none():
    assert not validators.boolean_validator(None, None)
Beispiel #17
0
def test_missing():
    assert not validators.boolean_validator("", None)
Beispiel #18
0
 def test_none(self):
     assert_equals(validators.boolean_validator(None, None), False)
Beispiel #19
0
 def test_string_true(self):
     assert_equals(validators.boolean_validator('true', None), True)
     assert_equals(validators.boolean_validator('yes', None), True)
     assert_equals(validators.boolean_validator('t', None), True)
     assert_equals(validators.boolean_validator('y', None), True)
     assert_equals(validators.boolean_validator('1', None), True)
Beispiel #20
0
 def test_none(self):
     assert_equals(validators.boolean_validator(None, None), False)
Beispiel #21
0
 def test_missing(self):
     assert_equals(validators.boolean_validator('', None), False)
Beispiel #22
0
def test_bool_true():
    assert validators.boolean_validator(True, None)