Ejemplo n.º 1
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]
Ejemplo n.º 2
0
    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]
Ejemplo n.º 3
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')
Ejemplo n.º 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')