Example #1
0
    def test_step_status_is_collected_and_reported(self, format_summary, stderr):
        # pylint: disable=W0621
        #   W0621   Redefining name ... from outer scope (format_summary)
        feature = Mock()
        scenario = Mock()
        steps = [Mock(), Mock(), Mock(), Mock(), Mock()]
        steps[0].status = "failed"
        steps[0].__iter__ = Mock(return_value=iter([]))
        steps[1].status = "undefined"
        steps[1].__iter__ = Mock(return_value=iter([]))
        steps[2].status = "passed"
        steps[2].__iter__ = Mock(return_value=iter([]))
        steps[3].status = "passed"
        steps[3].__iter__ = Mock(return_value=iter([]))
        steps[4].status = None
        steps[4].__iter__ = Mock(return_value=iter([]))
        feature.status = "failed"
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter([scenario]))
        scenario.status = "failed"
        scenario.__iter__ = Mock(return_value=iter(steps))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {"passed": 2, "failed": 1, "skipped": 1, "untested": 0, "undefined": 1}

        eq_(format_summary.call_args_list[2][0], ("step", expected))
Example #2
0
    def test_step_status_is_collected_and_reported(self, format_summary, stdout):
        feature = Mock()
        scenario = Mock()
        steps = [Mock(), Mock(), Mock(), Mock(), Mock()]
        steps[0].status = Status.failed
        steps[0].__iter__ = Mock(return_value=iter([]))
        steps[1].status = Status.passed
        steps[1].__iter__ = Mock(return_value=iter([]))
        steps[2].status = Status.passed
        steps[2].__iter__ = Mock(return_value=iter([]))
        steps[3].status = Status.skipped
        steps[4].__iter__ = Mock(return_value=iter([]))
        steps[4].status = Status.undefined
        steps[4].__iter__ = Mock(return_value=iter([]))
        feature.status = Status.failed
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter([scenario]))
        scenario.status = Status.failed
        scenario.__iter__ = Mock(return_value=iter(steps))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {
            Status.passed.name: 2,
            Status.failed.name: 1,
            Status.skipped.name: 1,
            Status.untested.name: 0,
            Status.undefined.name: 1,
        }

        eq_(format_summary.call_args_list[2][0], ("step", expected))
Example #3
0
    def _fake_popen(self, stdout, stderr, sleeptime):
        def wait_stdout(self):
            import time

            for line in stdout.splitlines():
                time.sleep(sleeptime)
                yield line

        def wait_stderr(self):
            import time

            for line in stderr.splitlines():
                time.sleep(sleeptime)
                yield line

        m = Mock(spec=subprocess.Popen)
        sout = Mock()
        sout.read = stdout
        sout.__iter__ = wait_stdout

        serr = Mock()
        serr.read = stderr
        serr.__iter__ = wait_stderr

        m.return_value.stdout = sout
        m.return_value.stderr = serr
        return m
Example #4
0
def test_checkout_deliveries_with_shipping_method(monkeypatch):
    shipping_cost = 5
    items_cost = 5

    partition = Mock(
        is_shipping_required=MagicMock(return_value=True),
        get_total=Mock(return_value=Price(items_cost, currency=settings.DEFAULT_CURRENCY)),
        get_price_per_item=Mock(return_value=Price(items_cost, currency=settings.DEFAULT_CURRENCY)),
    )

    def f():
        yield partition

    partition.__iter__ = Mock(return_value=f())
    cart = Mock(partition=Mock(return_value=[partition]), currency=settings.DEFAULT_CURRENCY)

    shipping_method_mock = Mock(get_total=Mock(return_value=Price(shipping_cost, currency=settings.DEFAULT_CURRENCY)))
    monkeypatch.setattr(Checkout, "shipping_method", shipping_method_mock)

    checkout = Checkout(cart, AnonymousUser(), "tracking_code")

    deliveries = list(checkout.deliveries)
    assert deliveries[0][1] == Price(shipping_cost, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][2] == Price(items_cost + shipping_cost, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][0][0][0] == partition
    def test_magic_methods_isolated_between_mocks(self):
        mock1 = Mock()
        mock2 = Mock()

        mock1.__iter__ = Mock(return_value=iter([]))
        self.assertEqual(list(mock1), [])
        self.assertRaises(TypeError, lambda: list(mock2))
Example #6
0
    def test_scenario_outline_status_is_collected_and_reported(self, stderr, format_summary):
        # FIX: issue40
        # ENSURE: ScenarioOutline's scenarios are walked and collected.
        feature = Mock()
        scenarios = [ScenarioOutline(u"<string>", 0, u"scenario_outline", u"name"), Mock(), Mock(), Mock()]
        subscenarios = [Mock(), Mock(), Mock(), Mock()]
        subscenarios[0].status = "passed"
        subscenarios[0].__iter__ = Mock(return_value=iter([]))
        subscenarios[1].status = "failed"
        subscenarios[1].__iter__ = Mock(return_value=iter([]))
        subscenarios[2].status = "failed"
        subscenarios[2].__iter__ = Mock(return_value=iter([]))
        subscenarios[3].status = "skipped"
        subscenarios[3].__iter__ = Mock(return_value=iter([]))
        scenarios[0]._scenarios = subscenarios
        scenarios[1].status = "failed"
        scenarios[1].__iter__ = Mock(return_value=iter([]))
        scenarios[2].status = "skipped"
        scenarios[2].__iter__ = Mock(return_value=iter([]))
        scenarios[3].status = "passed"
        scenarios[3].__iter__ = Mock(return_value=iter([]))
        feature.status = "failed"
        feature.duration = 12.4
        feature.__iter__ = Mock(return_value=iter(scenarios))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {"passed": 2, "failed": 3, "skipped": 2, "untested": 0}

        eq_(format_summary.call_args_list[1][0], ("scenario", expected))
Example #7
0
    def testMagicMethodsIsolatedBetweenMocks(self):
        mock1 = Mock()
        mock2 = Mock()

        mock1.__iter__ = Mock(return_value=iter([]))
        self.assertEqual(list(mock1), [])
        self.assertRaises(TypeError, lambda: list(mock2))
Example #8
0
    def test_scenario_status_is_collected_and_reported(self, format_summary, stderr):
        feature = Mock()
        scenarios = [Mock(), Mock(), Mock(), Mock(), Mock()]
        scenarios[0].status = "failed"
        scenarios[0].__iter__ = Mock(return_value=iter([]))
        scenarios[1].status = "failed"
        scenarios[1].__iter__ = Mock(return_value=iter([]))
        scenarios[2].status = "skipped"
        scenarios[2].__iter__ = Mock(return_value=iter([]))
        scenarios[3].status = "passed"
        scenarios[3].__iter__ = Mock(return_value=iter([]))
        scenarios[4].status = None
        scenarios[4].__iter__ = Mock(return_value=iter([]))
        feature.status = "failed"
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter(scenarios))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {"passed": 1, "failed": 2, "skipped": 2, "untested": 0}

        eq_(format_summary.call_args_list[1][0], ("scenario", expected))
Example #9
0
def test_catter():
    fs = Filesystem(DB(":memory:"))
    fs.root().add_file("zeroes", [test_asset_ids])

    asset = Mock()
    asset.__enter__ = Mock(return_value=asset)
    asset.__exit__ = Mock(return_value=False)
    asset.status = Mock(return_value=proto.AssetStatus(size=1024 * 1024, status=proto.SUCCESS))
    asset.__iter__ = Mock(return_value=("\x00" * (128 * 1024) for _ in range(8)))

    bithorde = Mock()
    bithorde.open = Mock(return_value=asset)
    cat = Cat(fs, bithorde)

    sha = sha1()
    for chunk in cat(P("zeroes")):
        sha.update(chunk)
    assert_equals(sha.hexdigest(), "3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3")

    with assert_raises(FNotFound):
        for chunk in cat(P("NON-EXISTING")):
            pass

    asset.status = Mock(return_value=proto.AssetStatus(status=proto.NOTFOUND))
    with assert_raises(NotFoundError):
        for chunk in cat(P("zeroes")):
            pass
Example #10
0
    def test_scenario_outline_status_is_collected_and_reported(self, stdout, format_summary):
        feature = Mock()
        scenarios = [ScenarioOutline(u"<string>", 0, u"scenario_outline", u"name"), Mock(), Mock(), Mock()]
        subscenarios = [Mock(), Mock(), Mock(), Mock()]
        subscenarios[0].status = Status.passed
        subscenarios[0].__iter__ = Mock(return_value=iter([]))
        subscenarios[1].status = Status.failed
        subscenarios[1].__iter__ = Mock(return_value=iter([]))
        subscenarios[2].status = Status.failed
        subscenarios[2].__iter__ = Mock(return_value=iter([]))
        subscenarios[3].status = Status.skipped
        subscenarios[3].__iter__ = Mock(return_value=iter([]))
        scenarios[0]._scenarios = subscenarios
        scenarios[1].status = Status.failed
        scenarios[1].__iter__ = Mock(return_value=iter([]))
        scenarios[2].status = Status.skipped
        scenarios[2].__iter__ = Mock(return_value=iter([]))
        scenarios[3].status = Status.passed
        scenarios[3].__iter__ = Mock(return_value=iter([]))
        feature.status = Status.failed
        feature.duration = 12.4
        feature.__iter__ = Mock(return_value=iter(scenarios))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {Status.passed.name: 2, Status.failed.name: 3, Status.skipped.name: 2, Status.untested.name: 0}

        eq_(format_summary.call_args_list[1][0], ("scenario", expected))
    def test_magic_methods_and_spec_set(self):
        class Iterable(object):
            def __iter__(self):
                pass

        mock = Mock(spec_set=Iterable)
        self.assertRaises(AttributeError, lambda: mock.__iter__)

        mock.__iter__ = Mock(return_value=iter([]))
        self.assertEqual(list(mock), [])

        class NonIterable(object):
            pass

        mock = Mock(spec_set=NonIterable)
        self.assertRaises(AttributeError, lambda: mock.__iter__)

        def set_int():
            mock.__int__ = Mock(return_value=iter([]))

        self.assertRaises(AttributeError, set_int)

        mock = MagicMock(spec_set=Iterable)
        self.assertEqual(list(mock), [])
        self.assertRaises(AttributeError, set_int)
    def test_bound_methods(self):
        m = Mock()

        # XXXX should this be an expected failure instead?

        # this seems like it should work, but is hard to do without introducing
        # other api inconsistencies. Failure message could be better though.
        m.__iter__ = [3].__iter__
        self.assertRaises(TypeError, iter, m)
Example #13
0
    def test_set_admin(self):
        user = "user"
        MockAdmin = Mock()
        MockAdmin.__iter__ = Mock(return_value=iter([user]))
        mock_set_secure_cookie = Mock()

        with patch.object(settings, "ADMINISTRATORS", MockAdmin):
            with patch.object(self.auth_handler, "set_secure_cookie", mock_set_secure_cookie):
                self.auth_handler.set_admin(user)

        mock_set_secure_cookie.assert_called_once_with("admin", "true")
Example #14
0
 def queryset(self):
     """Mock "queryset" of instances with numeric id and unicode repr."""
     o1 = Mock()
     o1.pk = 1
     o1.__unicode__ = lambda self: "one"
     o2 = Mock()
     o2.pk = 2
     o2.__unicode__ = lambda self: "two"
     qs = Mock()
     qs.__iter__ = lambda self: iter([o1, o2])
     qs.all.return_value = qs
     return qs
Example #15
0
    def test_set_admin_not_administrator(self):
        # Mock auth_handler.clear_cookie
        user = "user"
        MockAdmin = Mock()
        MockAdmin.__iter__ = Mock(return_value=iter([]))
        mock_clear_cookie = Mock()

        with patch.object(settings, "ADMINISTRATORS", MockAdmin):
            with patch.object(self.auth_handler, "clear_cookie", mock_clear_cookie):
                self.auth_handler.set_admin(user)

        mock_clear_cookie.assert_called_once_with("admin")
Example #16
0
    def testLenContainsIter(self):
        mock = Mock()

        self.assertRaises(TypeError, len, mock)
        self.assertRaises(TypeError, iter, mock)
        self.assertRaises(TypeError, lambda: "foo" in mock)

        mock.__len__ = lambda s: 6
        self.assertEqual(len(mock), 6)

        mock.__contains__ = lambda s, o: o == 3
        self.assertTrue(3 in mock)
        self.assertFalse(6 in mock)

        mock.__iter__ = lambda s: iter("foobarbaz")
        self.assertEqual(list(mock), list("foobarbaz"))
Example #17
0
def test_checkout_deliveries():
    partition = Mock(
        get_total=Mock(return_value=Price(10, currency=settings.DEFAULT_CURRENCY)),
        get_price_per_item=Mock(return_value=Price(10, currency=settings.DEFAULT_CURRENCY)),
    )

    def f():
        yield partition

    partition.__iter__ = Mock(return_value=f())
    cart = Mock(partition=Mock(return_value=[partition]), currency=settings.DEFAULT_CURRENCY)
    checkout = Checkout(cart, AnonymousUser(), "tracking_code")
    deliveries = list(checkout.deliveries)
    assert deliveries[0][1] == Price(0, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][2] == partition.get_total()
    assert deliveries[0][0][0][0] == partition
    def test_len_contains_iter(self):
        mock = Mock()

        self.assertRaises(TypeError, len, mock)
        self.assertRaises(TypeError, iter, mock)
        self.assertRaises(TypeError, lambda: "foo" in mock)

        mock.__len__ = lambda s: 6
        self.assertEqual(len(mock), 6)

        mock.__contains__ = lambda s, o: o == 3
        self.assertIn(3, mock)
        self.assertNotIn(6, mock)

        mock.__iter__ = lambda s: iter("foobarbaz")
        self.assertEqual(list(mock), list("foobarbaz"))
    def test_dir(self):
        mock = Mock()
        attrs = set(dir(mock))
        type_attrs = set([m for m in dir(Mock) if not m.startswith("_")])

        # all public attributes from the type are included
        self.assertEqual(set(), type_attrs - attrs)

        # creates these attributes
        mock.a, mock.b
        self.assertIn("a", dir(mock))
        self.assertIn("b", dir(mock))

        # instance attributes
        mock.c = mock.d = None
        self.assertIn("c", dir(mock))
        self.assertIn("d", dir(mock))

        # magic methods
        mock.__iter__ = lambda s: iter([])
        self.assertIn("__iter__", dir(mock))
Example #20
0
    def test_parses_feature_files_and_appends_to_feature_list(self, abspath, parse_file):
        feature_files = ["one", "two", "three"]
        feature = Mock()
        feature.tags = []
        feature.__iter__ = Mock(return_value=iter([]))
        feature.run.return_value = False
        self.runner.feature_files.return_value = feature_files
        abspath.side_effect = lambda x: x.upper()
        self.config.lang = "fritz"
        self.config.format = ["plain"]
        self.config.output.encoding = None
        self.config.exclude = lambda s: False
        self.config.junit = False
        self.config.summary = False
        parse_file.return_value = feature

        self.runner.run_with_paths()

        expected_parse_file_args = [((x.upper(),), {"language": "fritz"}) for x in feature_files]
        eq_(parse_file.call_args_list, expected_parse_file_args)
        eq_(self.runner.features, [feature] * 3)
    def it_saves_collections_as_m2m_relations(self):
        # prepare the app structure
        Doc1Model = Mock(name="doc1_model")

        class Doc1(Document):
            id = fields.NumberField()

            class Meta:
                backend_type = "django"
                model = Doc1Model

        class Doc1Col(Collection):
            document = Doc1

        Doc2Model = Mock(name="doc2_model")

        class Doc2(Document):
            id = fields.NumberField()
            # The bool field tests an edge case where boolean fields with a
            # default value of False are ignored unfortunately
            bool = fields.BooleanField(default=False)
            col = fields.CollectionField(Doc1Col)

            class Meta:
                backend_type = "django"
                model = Doc2Model

        request = {"id": 1, "col": [{"id": 1}, {"id": 2}]}

        # now mock the underlying model store
        mock_doc2 = Mock(name="mock_doc2_model")
        mock_doc1_1 = Mock(name="mock_doc1_1")
        mock_doc1_2 = Mock(name="mock_doc1_2")

        Doc2Model.objects.get.return_value = mock_doc2

        collection_model = [mock_doc1_2, mock_doc1_1]

        def se(*args, **kwargs):
            return collection_model.pop()

        # I have to mock a queryset for each collection, cause I run an exclude
        # on it everytime I iterate through an item of the collection
        qs_col = Mock(name="queryset")
        qs_col.__len__ = Mock(return_value=2)
        qs_col.__getitem__ = Mock()
        qs_col.__iter__ = Mock(return_value=iter([mock_doc1_1, mock_doc1_2]))

        qs_cola = Mock(name="queryset-exclude_cola")
        qs_cola.__len__ = Mock(return_value=1)
        qs_cola.__getitem__ = Mock()
        qs_cola.__iter__ = Mock(return_value=iter([mock_doc1_2]))

        qs_col.exclude.return_value = qs_cola
        qs_colb = Mock(name="queryset-exclude_colb")
        qs_colb.__len__ = Mock(return_value=1)
        qs_colb.__getitem__ = Mock()
        qs_colb.__iter__ = Mock(return_value=iter([]))
        qs_cola.exclude.return_value = qs_colb

        mock_doc2.col = Mock()
        mock_doc2.col.__dict__["model"] = Doc1Model
        mock_doc2.col.get.side_effect = se
        mock_doc2.col.get.return_value = True
        mock_doc2.col.all.return_value = qs_col

        doc = Doc2(request)

        eq_(2, len(doc.col.collection_set))

        doc.save()

        eq_(True, mock_doc2.col.get.called)
        eq_(True, Doc2Model.objects.get.called)
        Doc2Model.objects.get.assert_called_once_with(id=1)
    def it_can_delete_items_from_a_m2m_relation(self):
        Model1 = Mock()
        Model2 = Mock()

        class Doc1(Document):
            id = fields.NumberField()

            class Meta:
                backend_type = "django"
                model = Model1

        class Col1(Collection):
            document = Doc1

        class Doc2(Document):
            id = fields.NumberField()
            col1 = fields.CollectionField(Col1)

            class Meta:
                backend_type = "django"
                model = Model2

        # First return an existing model instance
        mock_doc1a = Mock()
        mock_doc1a.id = 1
        mock_doc1a.__dict__["model"] = Model1

        mock_doc1b = Mock()
        mock_doc1b.id = 2
        mock_doc1b.__dict__["model"] = Model1

        m2m_relation = Mock(name="m2m_relation")
        mock_doc2 = Mock()
        mock_doc2.col1 = m2m_relation
        mock_doc2.id = 3
        mock_doc2.col1.__dict__["model"] = Model1

        # The fetch for the foreign document will raise a BackendDoesNotExist
        # and therefore creates a new model instance
        Model2.objects.get.return_value = mock_doc2

        Queryset = Mock(name="queryset")
        Queryset.__len__ = Mock(return_value=2)
        Queryset.__getitem__ = Mock()
        Queryset.__iter__ = Mock(return_value=iter([mock_doc1a, mock_doc1b]))
        m2m_relation.all.return_value = Queryset

        doc = Doc2({"id": 1, "col1": []})
        doc.save()

        # If the collection is empty we make sure that the backend instances
        # are delete too
        eq_(True, mock_doc1a.delete.called)
        eq_(True, mock_doc1b.delete.called)

        mock_doc1a.reset_mock()
        mock_doc1b.reset_mock()
        m2m_relation.all.reset_mock()

        Queryset1 = Mock(name="queryset1")
        Queryset1.__len__ = Mock(return_value=2)
        Queryset1.__getitem__ = Mock()
        Queryset1.__iter__ = Mock(return_value=iter([mock_doc1a, mock_doc1b]))
        Queryset2 = Mock(name="queryset2")
        Queryset2.__len__ = Mock(return_value=1)
        Queryset2.__getitem__ = Mock()
        Queryset2.__iter__ = Mock(return_value=iter([mock_doc1b]))

        m2m_relation.all.return_value = Queryset1
        Queryset1.exclude.return_value = Queryset2

        doc = Doc2({"id": 1, "col1": [{"id": 1}]})
        doc.save()

        m2m_relation.get.assert_called_once_with(id=1)
        eq_(True, mock_doc1b.delete.called)
    def it_can_save_nested_collections_on_the_django_backend(self):
        # Prepare an environment where you have a collection nesting another
        # collection
        Doc1Model = Mock(name="DjangoModel1")

        class Doc1(Document):
            id = fields.NumberField()

            class Meta:
                backend_type = "django"
                model = Doc1Model

        class Doc1Collection(Collection):
            document = Doc1

        Doc2Model = Mock(name="DjangoModel2")

        class Doc2(Document):
            id = fields.NumberField()
            name = fields.StringField()
            doc1 = fields.CollectionField(Doc1Collection)

            class Meta:
                backend_type = "django"
                model = Doc2Model

            def map_doc1_field(self):
                return "doc1_map"

        class Doc2Collection(Collection):
            document = Doc2

        Doc3Model = Mock(name="DjangoModel3")

        class Doc3(Document):
            id = fields.NumberField()
            doc2 = fields.CollectionField(Doc2Collection)

            class Meta:
                backend_type = "django"
                model = Doc3Model

        post_data = {"id": 1, "doc2": [{"id": 2, "name": "miss kitty", "doc1": [{"id": 3}]}]}

        # create the document structure
        doc3 = Doc3(post_data)

        # and verify some expectations
        ok_(isinstance(doc3.doc2, Doc2Collection))
        eq_(1, len(doc3.doc2.collection_set))
        ok_(isinstance(doc3.doc2.collection_set[0], Doc2))
        temp_doc = doc3.doc2.collection_set[0]
        eq_("miss kitty", temp_doc.name)
        ok_(isinstance(temp_doc.doc1, Doc1Collection))

        # Now mock the django backend properly
        Doc1Model.DoesNotExist = Exception
        Doc2Model.DoesNotExist = Exception
        Doc3Model.DoesNotExist = Exception

        Doc3Model.objects.get.side_effect = Doc3Model.DoesNotExist
        mock_doc3 = Mock(name="Doc3")
        mock_doc3.id = 1
        mock_doc3.doc2 = Mock()
        mock_doc3.doc2.__dict__["model"] = Doc2Model
        Doc3Model.return_value = mock_doc3
        mock_doc2 = Mock()
        mock_doc2.__dict__["model"] = Doc2Model
        mock_doc2.id = 2
        mock_doc2.doc1_map = Mock(name="doc1_map")
        mock_doc2.doc1_map.__dict__["model"] = Doc1Model

        # I have to mock a queryset for each collection, cause I run an exclude
        # on it everytime I iterate through an item of the collection
        qs_doc2 = Mock(name="queryset2")
        qs_doc2.__len__ = Mock(return_value=1)
        qs_doc2.__getitem__ = Mock()
        qs_doc2.__iter__ = Mock(return_value=iter([mock_doc2]))
        qs_doc2a = Mock(name="queryset-exclude_doc2")
        qs_doc2a.__iter__ = Mock(return_value=iter([]))
        qs_doc2.exclude.return_value = qs_doc2a

        mock_doc3.doc2.all.return_value = qs_doc2
        mock_doc3.doc2.create.return_value = mock_doc2
        mock_doc3.doc2.get.return_value = mock_doc2
        mock_doc1 = Mock()
        mock_doc1.__dict__["model"] = Doc1Model
        mock_doc1.id = 3

        qs_doc1 = Mock(name="queryset1")
        qs_doc1.__len__ = Mock(return_value=1)
        qs_doc1.__getitem__ = Mock()
        qs_doc1.__iter__ = Mock(return_value=iter([mock_doc1]))

        qs_doc1a = Mock(name="queryset-exclude_doc1")
        qs_doc1a.__len__ = Mock(return_value=0)
        qs_doc1a.__getitem__ = Mock()
        qs_doc1a.__iter__ = Mock(return_value=iter([]))
        qs_doc1.exclude.return_value = qs_doc1a

        mock_doc2.doc1_map.all.return_value = qs_doc1
        mock_doc2.doc1_map.get.return_value = mock_doc1
        mock_doc2.doc1_map.create.return_value = mock_doc1

        # saving the model should create all nested relations too
        doc3.save()

        # make sure the right methods have been called.
        ok_(mock_doc2.doc1_map.get.called)
        ok_(mock_doc3.doc2.get.called)
        ok_(Doc3Model.called)
Example #24
0
 def _query_call(self, endpoint, query_string):
     data = self._results[query_string]
     result = Mock()
     result.variables = data[0]
     result.__iter__ = lambda self: iter(data[1])
     return result