Пример #1
0
 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")
Пример #2
0
 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
Пример #3
0
 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
Пример #4
0
 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")
Пример #5
0
    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")