def test_resolve_attr_build(self, basic_factory): """ Tests that resolving an associated field with a specific attribute works properly. """ assoc = AssociationField(basic_factory, "basic", attr="basic") assert True == assoc.resolve("build")
def test_resolve_scope_build(self, basic_factory): """ Tests that resolving on a ``build`` request properly works. """ assoc = AssociationField(basic_factory, "basic") result = assoc.resolve("build") assert not result.saved
def test_resolve_scope_create(self, basic_factory): """ Tests that resolving on a ``create`` request properly works. """ assoc = AssociationField(basic_factory, "basic") result = assoc.resolve("create") assert result.saved
def test_resolve_scope_attributes(self, basic_factory): """ Tests that resolving based on the attribute scope properly works. """ assoc = AssociationField(basic_factory, "basic") assert basic_factory.attributes("basic") == assoc.resolve("attributes")
def test_resolve_attr_bad_factory(self): """ Tests that resolving an associated field with a model builder that doesn't support "getattr" will raise an exception. """ class Builder(object): @classmethod def build(cls, model_cls, attributes): return BasicBuilder.build(model_cls, attributes) @classmethod def create(cls, model_cls, attributes): return BasicBuilder.create(model_cls, attributes) class Factory(BasicFactory): _model_builder = Builder assoc = AssociationField(Factory(), "basic", attr="basic") assert True == assoc.resolve("attributes") with pytest.raises(InvalidModelBuilderError): assoc.resolve("build")