def test_query_filters_model_objects_by_subclass(self):
        item_1 = Car(speed=1)
        item_2 = Sedan(speed=2)
        item_3 = Car(speed=3)

        item_2.sedan = item_2

        self.mock_set.add(item_1, item_2, item_3)
        results = list(self.mock_set.filter(sedan__isnull=False))

        assert results == [item_2]
示例#2
0
    def test_query_filters_model_objects(self):
        item_1 = Car(speed=1)
        item_2 = Sedan(speed=2)
        item_3 = Car(speed=3)

        item_2.sedan = item_2

        self.mock_set.add(item_1, item_2, item_3)
        results = list(self.mock_set.filter(speed=3))

        assert results == [item_3]
    def test_query_filters_model_objects_by_bad_field(self):
        item_1 = Car(speed=1)
        item_2 = Sedan(speed=2)
        item_3 = Car(speed=3)

        item_2.sedan = item_2

        self.mock_set.add(item_1, item_2, item_3)
        with self.assertRaisesRegexp(
                FieldError,
                r"Cannot resolve keyword 'bad_field' into field\. "
                r"Choices are 'id', 'make', 'make_id', 'model', 'passengers', 'sedan', 'speed', 'variations'\."):
            self.mock_set.filter(bad_field='bogus')
示例#4
0
    def test_query_filters_model_objects_by_bad_field(self):
        item_1 = Car(speed=1)
        item_2 = Sedan(speed=2)
        item_3 = Car(speed=3)

        item_2.sedan = item_2

        self.mock_set.add(item_1, item_2, item_3)
        with self.assertRaisesRegexp(
                FieldError, r"Cannot resolve keyword 'bad_field' into field\. "
                r"Choices are 'id', 'make', 'make_id', 'model', 'passengers', 'sedan', 'speed', 'variations'\."
        ):
            self.mock_set.filter(bad_field='bogus')
示例#5
0
    def test_set_on_individual_object(self):
        car = Car()
        car2 = Car()
        car.sedan = Sedan()

        with self.assertRaises(Car.sedan.RelatedObjectDoesNotExist):
            car2.sedan
示例#6
0
    def test_set(self):
        car = Car()
        sedan = Sedan()
        car.sedan = sedan

        self.assertIs(car.sedan, sedan)
示例#7
0
    def test_mocked_relations_parent(self):
        sedan = Sedan(speed=95)

        self.assertEqual(0, sedan.passengers.count())
示例#8
0
    def test_parent(self):
        sedan = Sedan(speed=95)

        self.assertEqual(0, sedan.passengers.count())