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]
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')
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')
def test_set_on_individual_object(self): car = Car() car2 = Car() car.sedan = Sedan() with self.assertRaises(Car.sedan.RelatedObjectDoesNotExist): car2.sedan
def test_set(self): car = Car() sedan = Sedan() car.sedan = sedan self.assertIs(car.sedan, sedan)
def test_mocked_relations_parent(self): sedan = Sedan(speed=95) self.assertEqual(0, sedan.passengers.count())
def test_parent(self): sedan = Sedan(speed=95) self.assertEqual(0, sedan.passengers.count())