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
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
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
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
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
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
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
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")))
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
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)
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
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
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
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
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
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
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
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
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")))
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")))
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")))