コード例 #1
0
ファイル: test_dictization.py プロジェクト: kindly/ckantest
    def test_03_package_to_api1(self):

        context = {"model": model, "session": model.Session}

        pkg = model.Session.query(model.Package).filter_by(name="annakarenina").first()

        pprint(package_to_api1(pkg, context))
        pprint(pkg.as_dict())
        asdict = pkg.as_dict()
        asdict["download_url"] = asdict["resources"][0]["url"]

        assert package_to_api1(pkg, context) == asdict
コード例 #2
0
ファイル: test_dictization.py プロジェクト: pedroburon/ckan
    def test_03_package_to_api1(self):

        context = {"model": model, "session": model.Session}

        pkg = model.Session.query(
            model.Package).filter_by(name='annakarenina').first()

        pprint(package_to_api1(pkg, context))
        pprint(pkg.as_dict())
        asdict = pkg.as_dict()
        asdict['download_url'] = asdict['resources'][0]['url']

        assert package_to_api1(pkg, context) == asdict
コード例 #3
0
ファイル: test_dictization.py プロジェクト: AltisCorp/ckan
    def test_03_package_to_api1(self):

        context = {"model": model,
                 "session": model.Session}

        pkg = model.Session.query(model.Package).filter_by(name='annakarenina').first()

        pprint(package_to_api1(pkg, context))
        pprint(pkg.as_dict())
        asdict = pkg.as_dict()
        asdict['download_url'] = asdict['resources'][0]['url']
        asdict['license_title'] = u'Other (Open)'

        assert package_to_api1(pkg, context) == asdict
コード例 #4
0
ファイル: update.py プロジェクト: icmurray/ckan
def package_update_rest(context, data_dict):

    model = context['model']
    id = data_dict.get("id")
    request_id = context['id']
    api = context.get('api_version') or '1'
    pkg = model.Package.get(request_id)

    if not pkg:
        raise NotFound

    if id and id != pkg.id:
        pkg_from_data = model.Package.get(id)
        if pkg_from_data != pkg:
            error_dict = {id:('Cannot change value of key from %s to %s. '
                'This key is read-only') % (pkg.id, id)}
            raise ValidationError(error_dict)

    context["package"] = pkg
    context["allow_partial_update"] = True
    dictized_package = model_save.package_api_to_dict(data_dict, context)

    check_access('package_update_rest', context, dictized_package)

    dictized_after = get_action('package_update')(context, dictized_package)

    pkg = context['package']

    if api == '1':
        package_dict = model_dictize.package_to_api1(pkg, context)
    else:
        package_dict = model_dictize.package_to_api2(pkg, context)

    return package_dict
コード例 #5
0
def package_update_rest(context, data_dict):

    model = context['model']
    id = data_dict.get("id")
    request_id = context['id']
    api = context.get('api_version') or '1'
    pkg = model.Package.get(request_id)

    if not pkg:
        raise NotFound

    if id and id != pkg.id:
        pkg_from_data = model.Package.get(id)
        if pkg_from_data != pkg:
            error_dict = {
                id: ('Cannot change value of key from %s to %s. '
                     'This key is read-only') % (pkg.id, id)
            }
            raise ValidationError(error_dict)

    context["package"] = pkg
    context["allow_partial_update"] = True
    dictized_package = package_api_to_dict(data_dict, context)
    dictized_after = package_update(context, dictized_package)

    pkg = context['package']

    if api == '1':
        package_dict = package_to_api1(pkg, context)
    else:
        package_dict = package_to_api2(pkg, context)

    return package_dict
コード例 #6
0
    def test_03_package_to_api1(self):

        context = {"model": model, "session": model.Session}

        pkg = model.Session.query(model.Package).filter_by(name="annakarenina").first()

        pprint(package_to_api1(pkg, context))
        pprint(pkg.as_dict())
        asdict = pkg.as_dict()
        asdict["download_url"] = asdict["resources"][0]["url"]
        asdict["license_title"] = u"Other (Open)"

        dictize = package_to_api1(pkg, context)
        # the is_dict method doesn't care about organizations
        del dictize["organization"]
        assert dictize == asdict
コード例 #7
0
ファイル: update.py プロジェクト: zydio/ckan
def package_update_rest(context, data_dict):

    model = context["model"]
    id = data_dict.get("id")
    request_id = context["id"]
    api = context.get("api_version") or "1"
    pkg = model.Package.get(request_id)

    if not pkg:
        raise NotFound

    if id and id != pkg.id:
        pkg_from_data = model.Package.get(id)
        if pkg_from_data != pkg:
            error_dict = {id: ("Cannot change value of key from %s to %s. " "This key is read-only") % (pkg.id, id)}
            raise ValidationError(error_dict)

    context["package"] = pkg
    context["allow_partial_update"] = True
    dictized_package = package_api_to_dict(data_dict, context)

    check_access("package_update_rest", context, dictized_package)

    dictized_after = package_update(context, dictized_package)

    pkg = context["package"]

    if api == "1":
        package_dict = package_to_api1(pkg, context)
    else:
        package_dict = package_to_api2(pkg, context)

    return package_dict
コード例 #8
0
    def test_04_package_to_api1_with_relationship(self):

        context = {"model": model,
                 "session": model.Session}

        create = CreateTestData

        create.create_family_test_data()
        pkg = model.Session.query(model.Package).filter_by(name='homer').one()

        as_dict = pkg.as_dict()
        as_dict['license_title'] = None
        as_dict['num_tags'] = 0
        as_dict['num_resources'] = 0
        dictize = package_to_api1(pkg, context)

        as_dict["relationships"].sort(key=lambda x:x.items())
        dictize["relationships"].sort(key=lambda x:x.items())

        # the is_dict method doesn't care about organizations
        del dictize['organization']
        as_dict_string = pformat(as_dict)
        dictize_string = pformat(dictize)
        print(as_dict_string)
        print(dictize_string)

        assert as_dict == dictize, "\n".join(unified_diff(as_dict_string.split("\n"), dictize_string.split("\n")))
コード例 #9
0
ファイル: test_dictization.py プロジェクト: usuariobkp/ckan
    def test_03_package_to_api1(self):

        context = {"model": model,
                 "session": model.Session}

        pkg = model.Session.query(model.Package).filter_by(name='annakarenina').first()

        pprint(package_to_api1(pkg, context))
        pprint(pkg.as_dict())
        asdict = pkg.as_dict()
        asdict['download_url'] = asdict['resources'][0]['url']
        asdict['license_title'] = u'Other (Open)'

        dictize = package_to_api1(pkg, context)
        # the is_dict method doesn't care about organizations
        del dictize['organization']
        assert dictize == asdict
コード例 #10
0
ファイル: __init__.py プロジェクト: kindly/ckantest
 def notify(self, entity, operation):
     if operation != DomainObjectOperation.deleted:
         dispatch_by_operation(entity.__class__.__name__, 
                               package_to_api1(entity, {'model': model}),
                               operation)
     elif operation == DomainObjectOperation.deleted:
         dispatch_by_operation(entity.__class__.__name__, 
                               {'id': entity.id}, operation)
     else:
         log.warn("Discarded Sync. indexing for: %s" % entity)
コード例 #11
0
ファイル: get.py プロジェクト: AdamJensen-dk/ckan-drupal
def package_show_rest(context, data_dict):

    package_show(context, data_dict)

    api = context.get('api_version') or '1'
    pkg = context['package']

    if api == '1':
        package_dict = package_to_api1(pkg, context)
    else:
        package_dict = package_to_api2(pkg, context)

    return package_dict
コード例 #12
0
def package_show_rest(context, data_dict):

    package_show(context, data_dict)

    api = context.get('api_version') or '1'
    pkg = context['package']

    if api == '1':
        package_dict = package_to_api1(pkg, context)
    else:
        package_dict = package_to_api2(pkg, context)

    return package_dict
コード例 #13
0
    def test_package_to_api1(self):
        CreateTestData.create()
        context = {"model": model, "session": model.Session}
        pkg = model.Package.get("annakarenina")
        asdict = pkg.as_dict()
        asdict["download_url"] = asdict["resources"][0]["url"]
        asdict["license_title"] = u"Other (Open)"
        asdict["num_tags"] = 3
        asdict["num_resources"] = 2

        dictize = package_to_api1(pkg, context)
        # the is_dict method doesn't care about organizations
        del dictize["organization"]
        assert dictize == asdict
コード例 #14
0
ファイル: get.py プロジェクト: jakebarnwell/PythonGenerator
def package_show_rest(context, data_dict):

    check_access('package_show_rest', context, data_dict)

    logic.get_action('package_show')(context, data_dict)

    api = context.get('api_version') or '1'
    pkg = context['package']

    if api == '1':
        package_dict = model_dictize.package_to_api1(pkg, context)
    else:
        package_dict = model_dictize.package_to_api2(pkg, context)

    return package_dict
コード例 #15
0
ファイル: get.py プロジェクト: jasonzou/ckan
def package_show_rest(context, data_dict):

    check_access("package_show_rest", context, data_dict)

    package_show(context, data_dict)

    api = context.get("api_version") or "1"
    pkg = context["package"]

    if api == "1":
        package_dict = package_to_api1(pkg, context)
    else:
        package_dict = package_to_api2(pkg, context)

    return package_dict
コード例 #16
0
ファイル: get.py プロジェクト: jakebarnwell/PythonGenerator
def package_show_rest(context, data_dict):

    check_access('package_show_rest',context, data_dict)

    logic.get_action('package_show')(context, data_dict)

    api = context.get('api_version') or '1'
    pkg = context['package']

    if api == '1':
        package_dict = model_dictize.package_to_api1(pkg, context)
    else:
        package_dict = model_dictize.package_to_api2(pkg, context)

    return package_dict
コード例 #17
0
    def test_03_package_to_api1(self):

        context = {"model": model, "session": model.Session}

        pkg = (model.Session.query(
            model.Package).filter_by(name="annakarenina").first())

        asdict = pkg.as_dict()
        asdict["download_url"] = asdict["resources"][0]["url"]
        asdict["license_title"] = u"Other (Open)"
        asdict["num_tags"] = 3
        asdict["num_resources"] = 2

        dictize = package_to_api1(pkg, context)
        # the is_dict method doesn't care about organizations
        del dictize["organization"]
        assert dictize == asdict
コード例 #18
0
def package_create_rest(context, data_dict):

    api = context.get('api_version') or '1'

    dictized_package = package_api_to_dict(data_dict, context)
    dictized_after = package_create(context, dictized_package)

    pkg = context['package']

    if api == '1':
        package_dict = package_to_api1(pkg, context)
    else:
        package_dict = package_to_api2(pkg, context)

    data_dict['id'] = pkg.id

    return package_dict
コード例 #19
0
ファイル: create.py プロジェクト: AdamJensen-dk/ckan-drupal
def package_create_rest(context, data_dict):

    api = context.get('api_version') or '1'

    dictized_package = package_api_to_dict(data_dict, context)
    dictized_after = package_create(context, dictized_package) 

    pkg = context['package']

    if api == '1':
        package_dict = package_to_api1(pkg, context)
    else:
        package_dict = package_to_api2(pkg, context)

    data_dict['id'] = pkg.id

    return package_dict
コード例 #20
0
ファイル: create.py プロジェクト: icmurray/ckan
def package_create_rest(context, data_dict):

    api = context.get('api_version') or '1'

    check_access('package_create_rest', context, data_dict)

    dictized_package = model_save.package_api_to_dict(data_dict, context)
    dictized_after = get_action('package_create')(context, dictized_package)

    pkg = context['package']

    if api == '1':
        package_dict = model_dictize.package_to_api1(pkg, context)
    else:
        package_dict = model_dictize.package_to_api2(pkg, context)

    data_dict['id'] = pkg.id

    return package_dict
コード例 #21
0
def package_create_rest(context, data_dict):

    api = context.get('api_version') or '1'

    check_access('package_create_rest', context, data_dict)

    dictized_package = model_save.package_api_to_dict(data_dict, context)
    dictized_after = get_action('package_create')(context, dictized_package)

    pkg = context['package']

    if api == '1':
        package_dict = model_dictize.package_to_api1(pkg, context)
    else:
        package_dict = model_dictize.package_to_api2(pkg, context)

    data_dict['id'] = pkg.id

    return package_dict
コード例 #22
0
    def test_package_to_api1_with_relationship(self):
        context = {"model": model, "session": model.Session}
        CreateTestData.create_family_test_data()
        pkg = model.Package.get("homer")

        as_dict = dict(pkg.as_dict())
        as_dict["license_title"] = None
        as_dict["num_tags"] = 0
        as_dict["num_resources"] = 0
        dictize = package_to_api1(pkg, context)

        as_dict["relationships"].sort(key=lambda x: list(x.items()))
        dictize["relationships"].sort(key=lambda x: list(x.items()))
        # the is_dict method doesn't care about organizations
        del dictize["organization"]
        as_dict_string = pformat(as_dict)
        dictize_string = pformat(dictize)

        assert as_dict == dictize, "\n".join(
            unified_diff(as_dict_string.split("\n"),
                         dictize_string.split("\n")))
コード例 #23
0
ファイル: test_dictization.py プロジェクト: kindly/ckantest
    def test_04_package_to_api1_with_relationship(self):

        context = {"model": model, "session": model.Session}

        create = CreateTestData

        create.create_family_test_data()
        pkg = model.Session.query(model.Package).filter_by(name="homer").one()

        as_dict = pkg.as_dict()
        dictize = package_to_api1(pkg, context)

        as_dict["relationships"].sort(key=lambda x: x.items())
        dictize["relationships"].sort(key=lambda x: x.items())

        as_dict_string = pformat(as_dict)
        dictize_string = pformat(dictize)
        print as_dict_string
        print dictize_string

        assert as_dict == dictize, "\n".join(unified_diff(as_dict_string.split("\n"), dictize_string.split("\n")))
コード例 #24
0
ファイル: test_dictization.py プロジェクト: pedroburon/ckan
    def test_04_package_to_api1_with_relationship(self):

        context = {"model": model, "session": model.Session}

        create = CreateTestData

        create.create_family_test_data()
        pkg = model.Session.query(model.Package).filter_by(name='homer').one()

        as_dict = pkg.as_dict()
        dictize = package_to_api1(pkg, context)

        as_dict["relationships"].sort(key=lambda x: x.items())
        dictize["relationships"].sort(key=lambda x: x.items())

        as_dict_string = pformat(as_dict)
        dictize_string = pformat(dictize)
        print as_dict_string
        print dictize_string

        assert as_dict == dictize, "\n".join(
            unified_diff(as_dict_string.split("\n"),
                         dictize_string.split("\n")))