diff --git a/reversion_compare_tests/test_factory_car_reverse_models.py b/reversion_compare_tests/test_factory_car_reverse_models.py index 87af1f9..86e4230 100644 --- a/reversion_compare_tests/test_factory_car_reverse_models.py +++ b/reversion_compare_tests/test_factory_car_reverse_models.py @@ -11,15 +11,22 @@ * models.OneToOneField() * models.IntegerField() - :copyleft: 2012-2016 by the django-reversion-compare team, see AUTHORS for more details. + :copyleft: 2012-2017 by the django-reversion-compare team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. """ from __future__ import absolute_import, division, print_function -from reversion import is_registered -from reversion import unregister, revisions -from reversion.models import Version, Revision +from django.db import connection +from django.test.utils import CaptureQueriesContext + +from reversion import is_registered, revisions, unregister +from reversion.models import Revision, Version + +from .models import Car, Factory, Person +from .test_utils.db_queries import print_db_queries +from .test_utils.test_cases import BaseTestCase +from .test_utils.test_data import TestData try: import django_tools @@ -31,9 +38,6 @@ ) % err raise ImportError(msg) -from .models import Factory, Car, Person -from .test_utils.test_cases import BaseTestCase -from .test_utils.test_data import TestData class FactoryCarReverseRelationModelTest(BaseTestCase): @@ -81,11 +85,7 @@ def test_select_compare(self): '' % self.version_ids[2], ) - def test_diff1(self): - response = self.client.get( - "/admin/reversion_compare_tests/factory/%s/history/compare/" % self.factory.pk, - data={"version_id2": self.version_ids[1], "version_id1": self.version_ids[2]} - ) + def assert_diff1(self, response): # debug_response(response) # from django-tools self.assertContainsHtml( response, @@ -103,3 +103,25 @@ def test_diff1(self): ''', '
version 2: discontinued car-three, add car-four, add Bob the worker', # edit comment ) + + def test_diff1(self): + response = self.client.get( + "/admin/reversion_compare_tests/factory/%s/history/compare/" % self.factory.pk, + data={"version_id2": self.version_ids[1], "version_id1": self.version_ids[2]} + ) + self.assert_diff1(response) + + def test_select_compare1_queries(self): + with CaptureQueriesContext(connection) as queries: + response = self.client.get( + "/admin/reversion_compare_tests/factory/%s/history/compare/" % self.factory.pk, + data={"version_id2": self.version_ids[1], "version_id1": self.version_ids[2]} + ) + self.assert_diff1(response) + + # print_db_queries(queries.captured_queries) + # total queries....: 37 + # unique queries...: 28 + # duplicate queries: 9 + + self.assertLess(len(queries.captured_queries), 37+2) # real+buffer diff --git a/reversion_compare_tests/test_utils/db_queries.py b/reversion_compare_tests/test_utils/db_queries.py new file mode 100644 index 0000000..a3aaade --- /dev/null +++ b/reversion_compare_tests/test_utils/db_queries.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +""" + django-reversion-compare unittests + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyleft: 2017 by the django-reversion-compare team, see AUTHORS for more details. + :created: 2017 by Jens Diemer
simply change the CharField text.', # edit comment ) - + + def test_select_compare_and_diff(self): + response = self.client.get("/test_view/%s" % self.item1.pk, data={ + "version_id2": self.version_ids1[0], + "version_id1": self.version_ids1[1] + }) + self.assert_select_compare_and_diff(response) + + def test_select_compare_and_diff_queries(self): + with CaptureQueriesContext(connection) as queries: + response = self.client.get("/test_view/%s" % self.item1.pk, data={ + "version_id2": self.version_ids1[0], + "version_id1": self.version_ids1[1] + }) + self.assert_select_compare_and_diff(response) + + # print_db_queries(queries.captured_queries) + # total queries....: 15 + # unique queries...: 9 + # duplicate queries: 6 + self.assertLess(len(queries.captured_queries), 15+2) # real+buffer + def test_prev_next_buttons(self): base_url = "/test_view/%s" % self.item2.pk for i in range(4):