def test_unresolved_placeholders(): # no errors should be raised here -- instead a placeholder is created field = _convert_field_from_spec("attr", (create_model("Model", size=int), None)) assert any( isinstance(x, Placeholder) for x in get_global_registry(PydanticObjectType)._registry.values())
def test_register_object_field_and_get_for_graphene_field(): Foo, GraphFoo = _get_dummy_classes() r = get_global_registry(PydanticObjectType) field = r.get_object_field_for_graphene_field(GraphFoo, "name") assert field is not None assert field.type_ == str assert field.name == "name"
def test_unresolved_placeholders(): # no errors should be raised here -- instead a placeholder is created field = _convert_field_from_spec("attr", (create_model("Model", size=int), None)) assert any( isinstance(x, Placeholder) for x in get_global_registry(PydanticObjectType)._registry.values()) # this is a runtime error waiting to happen, but what can we do about it? assert field.type is None
def get_object_type(model) -> PydanticObjectType: """Construct object types in order, using caching etc""" reg = registry.get_global_registry() classes = get_pydantic_models_in_order(model) for klass in classes: if reg.get_type_for_model(klass): continue pydantic_oject = type( klass.__name__, (PydanticObjectType, ), {"Meta": type("Meta", (object, ), {"model": klass})}, ) assert reg.get_type_for_model(klass), klass return reg.get_type_for_model(model)
def _convert_field_from_spec(name, type_spec_or_default): return convert_pydantic_field( _get_field_from_spec(name, type_spec_or_default), get_global_registry(PydanticObjectType), )
def test_register_and_get_type_for_model(): Foo, GraphFoo = _get_dummy_classes() r = get_global_registry(PydanticObjectType) r.register(GraphFoo) assert r.get_type_for_model(Foo) is GraphFoo
def test_reset_global_registry(): get_global_registry(PydanticInputObjectType) assert registry.registry.get(PydanticInputObjectType) is not None reset_global_registry(PydanticInputObjectType) assert registry.registry.get(PydanticInputObjectType) is None
def test_get_global_registry_for_input(): assert isinstance(get_global_registry(PydanticInputObjectType), Registry)
def test_get_global_registry(): assert isinstance(get_global_registry(PydanticObjectType), Registry)
def test_reset_global_registry(): get_global_registry() assert registry.registry is not None reset_global_registry() assert registry.registry is None
def test_get_global_registry(): assert isinstance(get_global_registry(), Registry)