From 3aae9c8a1970c3fa9d03c42b4b4065d403e42990 Mon Sep 17 00:00:00 2001 From: Samuel Spencer Date: Mon, 1 Feb 2016 22:02:42 +0000 Subject: [PATCH] added tests for #58 --- tests/models.py | 10 +++++++++- tests/test_factory_car_models.py | 6 +++--- tests/test_factory_car_reverse_models.py | 16 ++++++++++++---- tests/test_utils/test_data.py | 22 ++++++++++++++-------- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/tests/models.py b/tests/models.py index 8e8eac3..c19ff4d 100644 --- a/tests/models.py +++ b/tests/models.py @@ -43,7 +43,13 @@ def __str__(self): """ @python_2_unicode_compatible -class Factory(models.Model): +class Building(models.Model): + address = models.CharField(max_length=128) + def __str__(self): + return self.address + +@python_2_unicode_compatible +class Factory(Building): name = models.CharField(max_length=128) def __str__(self): return self.name @@ -67,6 +73,8 @@ def __str__(self): class Person(models.Model): name = models.CharField(max_length=100) pets = models.ManyToManyField(Pet, blank=True) + # If you work someone, its at a build, but maybe not a factory! + workplace = models.ForeignKey(Building, related_name="workers", null=True) def __str__(self): return self.name diff --git a/tests/test_factory_car_models.py b/tests/test_factory_car_models.py index d5d08e1..41821be 100644 --- a/tests/test_factory_car_models.py +++ b/tests/test_factory_car_models.py @@ -71,7 +71,7 @@ def test_initial_state(self): self.assertEqual(Revision.objects.all().count(), 3) self.assertEqual(len(self.version_ids), 3) - self.assertEqual(Version.objects.all().count(), 10) + self.assertEqual(Version.objects.all().count(), 17) def test_select_compare(self): response = self.client.get("/admin/tests/car/%s/history/" % self.car.pk) @@ -160,14 +160,14 @@ def test_deleted_objects(self): https://travis-ci.org/jedie/django-reversion-compare/builds/72317520 """ with reversion.create_revision(): - factory1 = Factory.objects.create(name="factory one") + factory1 = Factory.objects.create(name="factory one", address="1 Fake Plaza") car = Car.objects.create( name="car", manufacturer=factory1 ) with reversion.create_revision(): - factory2 = Factory.objects.create(name="factory two") + factory2 = Factory.objects.create(name="factory two", address="1 Fake Plaza") car.manufacturer=factory2 car.save() diff --git a/tests/test_factory_car_reverse_models.py b/tests/test_factory_car_reverse_models.py index a3ab1b9..96a8975 100644 --- a/tests/test_factory_car_reverse_models.py +++ b/tests/test_factory_car_reverse_models.py @@ -42,7 +42,7 @@ from reversion_compare import helpers -from .models import Factory, Car +from .models import Factory, Car, Person from .test_utils.test_cases import BaseTestCase from .test_utils.test_data import TestData @@ -56,10 +56,12 @@ class FactoryCarReverseRelationModelTest(BaseTestCase): so no relation data would be stored """ def setUp(self): + reversion.unregister(Person) reversion.unregister(Car) reversion.unregister(Factory) - reversion.register(Factory, follow=["cars"]) + reversion.register(Factory, follow=["building_ptr","cars","workers"]) reversion.register(Car) + reversion.register(Person) super(FactoryCarReverseRelationModelTest, self).setUp() test_data = TestData(verbose=False) @@ -72,7 +74,7 @@ def test_initial_state(self): self.assertTrue(reversion.is_registered(Car)) self.assertEqual(Revision.objects.all().count(), 3) self.assertEqual(len(self.version_ids), 3) - self.assertEqual(Version.objects.all().count(), 13) + self.assertEqual(Version.objects.all().count(), 19) def test_select_compare(self): response = self.client.get("/admin/tests/factory/%s/history/" % self.factory.pk) @@ -103,5 +105,11 @@ def test_diff1(self): motor-car one from factory one supplier(s):

''', - '
version 2: discontinued car-three, add car-four
', # edit comment + ''' +

+ + Bob Bobertson
+

+ ''', + '
version 2: discontinued car-three, add car-four, add Bob the worker
', # edit comment ) + diff --git a/tests/test_utils/test_data.py b/tests/test_utils/test_data.py index bf1e38e..66dd1ef 100644 --- a/tests/test_utils/test_data.py +++ b/tests/test_utils/test_data.py @@ -108,10 +108,10 @@ def create_Simple_data(self): def create_FactoryCar_data(self): with reversion.create_revision(): - manufacture = Factory.objects.create(name="factory one") - supplier1 = Factory.objects.create(name="always the same supplier") - supplier2 = Factory.objects.create(name="would be deleted supplier") - supplier3 = Factory.objects.create(name="would be removed supplier") + manufacture = Factory.objects.create(name="factory one", address="1 Fake Plaza") + supplier1 = Factory.objects.create(name="always the same supplier", address="1 Fake Plaza") + supplier2 = Factory.objects.create(name="would be deleted supplier", address="1 Fake Plaza") + supplier3 = Factory.objects.create(name="would be removed supplier", address="1 Fake Plaza") car = Car.objects.create( name="motor-car one", manufacturer=manufacture @@ -140,7 +140,7 @@ def create_FactoryCar_data(self): manufacture.name = "factory I" manufacture.save() supplier2.delete() # - would be deleted supplier - supplier4 = Factory.objects.create(name="new, would be renamed supplier") + supplier4 = Factory.objects.create(name="new, would be renamed supplier", address="1 Fake Plaza") car.supplier.add(supplier4) # + new, would be renamed supplier car.supplier.remove(supplier3) # - would be removed supplier car.save() @@ -181,8 +181,8 @@ def create_Factory_reverse_relation_data(self): from django.db import transaction with transaction.atomic(), reversion.create_revision(): - manufacturer = Factory.objects.create(name="factory one") - different_manufacturer = Factory.objects.create(name="factory two") + manufacturer = Factory.objects.create(name="factory one", address="1 Fake Plaza") + different_manufacturer = Factory.objects.create(name="factory two", address="1 Fake Plaza") car1 = Car.objects.create( name="motor-car one", manufacturer=manufacturer @@ -224,8 +224,14 @@ def create_Factory_reverse_relation_data(self): manufacturer=manufacturer ) car4.save() + + worker1 = Person.objects.create( + name="Bob Bobertson", + workplace=manufacturer + ) + manufacturer.save() - reversion.set_comment("version 2: discontinued car-three, add car-four") + reversion.set_comment("version 2: discontinued car-three, add car-four, add Bob the worker") if self.verbose: print("version 2:", manufacturer)