launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #07175
[Merge] lp:~jtv/maas/djangotestcase into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/djangotestcase into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/djangotestcase/+merge/102720
Discussed with Gavin & Raphaël.
TestCaseBase is our one real universal test-case class (out of a great many) but the provisioning-server code can't import it. That's because it shares a module with the Django-enabled TestCase.
This branch renames the django-enabled test-case class to DjangoTestCase, in its own module with some of its derivatives; TestCaseBase becomes TestCase. In all probability, some of our tests have thus moved from a Django-enabled TestCase to a djangoless one. But as long as they'll still run, it should be fine.
Jeroen
--
https://code.launchpad.net/~jtv/maas/djangotestcase/+merge/102720
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/djangotestcase into lp:maas.
=== modified file 'src/maas/tests/test_maas.py'
--- src/maas/tests/test_maas.py 2012-04-16 10:00:51 +0000
+++ src/maas/tests/test_maas.py 2012-04-19 16:26:18 +0000
@@ -28,11 +28,11 @@
import_local_settings,
import_settings,
)
+from maastesting.djangotestcase import DjangoTestCase
from maastesting.factory import factory
-from maastesting.testcase import TestCase
-
-
-class TestSettingsHelpers(TestCase):
+
+
+class TestSettingsHelpers(DjangoTestCase):
"""Test Django settings helper functions."""
def test_find_settings(self):
=== modified file 'src/maasserver/testing/testcase.py'
--- src/maasserver/testing/testcase.py 2012-04-17 13:45:55 +0000
+++ src/maasserver/testing/testcase.py 2012-04-19 16:26:18 +0000
@@ -20,10 +20,10 @@
from django.core.cache import cache
from maasserver.testing import reset_fake_provisioning_api_proxy
from maasserver.testing.factory import factory
-import maastesting.testcase
-
-
-class TestCase(maastesting.testcase.TestCase):
+import maastesting.djangotestcase
+
+
+class TestCase(maastesting.djangotestcase.DjangoTestCase):
def setUp(self):
super(TestCase, self).setUp()
@@ -31,7 +31,8 @@
self.addCleanup(reset_fake_provisioning_api_proxy)
-class TestModelTestCase(TestCase, maastesting.testcase.TestModelTestCase):
+class TestModelTestCase(TestCase,
+ maastesting.djangotestcase.TestModelTestCase):
pass
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-04-18 09:42:59 +0000
+++ src/maasserver/tests/test_api.py 2012-04-19 16:26:18 +0000
@@ -50,7 +50,7 @@
LoggedInTestCase,
TestCase,
)
-from maastesting.testcase import TransactionTestCase
+from maastesting.djangotestcase import TransactionTestCase
from metadataserver.models import (
NodeKey,
NodeUserData,
=== modified file 'src/maasserver/tests/test_commands.py'
--- src/maasserver/tests/test_commands.py 2012-04-17 13:46:17 +0000
+++ src/maasserver/tests/test_commands.py 2012-04-19 16:26:18 +0000
@@ -22,10 +22,10 @@
from django.core.management import call_command
from maasserver.models import FileStorage
from maasserver.testing.factory import factory
-from maastesting.testcase import TestCase
-
-
-class TestCommands(TestCase):
+from maastesting.djangotestcase import DjangoTestCase
+
+
+class TestCommands(DjangoTestCase):
"""Happy-path integration testing for custom commands.
Detailed testing does not belong here. If there's any complexity at all
=== modified file 'src/maasserver/tests/test_maasavahi.py'
--- src/maasserver/tests/test_maasavahi.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/tests/test_maasavahi.py 2012-04-19 16:26:18 +0000
@@ -23,7 +23,7 @@
Config,
config_manager,
)
-from maastesting.testcase import TestCase
+from maastesting.djangotestcase import DjangoTestCase
class MockZeroconfServiceFactory:
@@ -58,7 +58,7 @@
self.calls.append('unpublish')
-class TestMAASAvahiService(TestCase):
+class TestMAASAvahiService(DjangoTestCase):
def setup_mock_avahi(self):
# Unregister other signals from Config, otherwise
=== modified file 'src/maastesting/testcase.py'
--- src/maastesting/testcase.py 2012-04-16 10:00:51 +0000
+++ src/maastesting/testcase.py 2012-04-19 16:26:18 +0000
@@ -12,21 +12,16 @@
__metaclass__ = type
__all__ = [
'TestCase',
- 'TestModelTestCase',
- 'TransactionTestCase',
]
import unittest
-from django.conf import settings
-from django.core.management.commands import syncdb
-from django.db.models import loading
-import django.test
import testresources
import testtools
-class TestCaseBase(testtools.TestCase):
+class TestCase(testtools.TestCase):
+ """Base `TestCase` for MAAS. Supports test resources and fixtures."""
# testresources.ResourcedTestCase does something similar to this class
# (with respect to setUpResources and tearDownResources) but it explicitly
# up-calls to unittest.TestCase instead of using super() even though it is
@@ -36,7 +31,7 @@
resources = ()
def setUp(self):
- super(TestCaseBase, self).setUp()
+ super(TestCase, self).setUp()
self.setUpResources()
def setUpResources(self):
@@ -45,7 +40,7 @@
def tearDown(self):
self.tearDownResources()
- super(TestCaseBase, self).tearDown()
+ super(TestCase, self).tearDown()
def tearDownResources(self):
testresources.tearDownResources(
@@ -54,63 +49,3 @@
# Django's implementation for this seems to be broken and was
# probably only added to support compatibility with python 2.6.
assertItemsEqual = unittest.TestCase.assertItemsEqual
-
-
-class TestCase(TestCaseBase, django.test.TestCase):
- """`TestCase` for Metal as a Service.
-
- Supports test resources and fixtures.
- """
-
- def assertAttributes(self, tested_object, attributes):
- """Check multiple attributes of `tested_objects` against a dict.
-
- :param tested_object: Any object whose attributes should be checked.
- :param attributes: A dict of attributes to test, and their expected
- values. Only these attributes will be checked.
- """
- matcher = testtools.matchers.MatchesStructure.byEquality(**attributes)
- self.assertThat(tested_object, matcher)
-
-
-class TransactionTestCase(TestCaseBase, django.test.TransactionTestCase):
- """`TransactionTestCase` for Metal as a Service.
-
- A version of TestCase that supports transactions.
-
- The basic Django TestCase class uses transactions to speed up tests
- so this class should be used when tests involve transactions.
- """
-
-
-class TestModelTestCase(TestCase):
- """A custom test case that adds support for test-only models.
-
- For instance, if you want to have a model object used solely for testing
- in your application 'myapp1' you would create a test case that uses
- TestModelTestCase as its base class and:
- - initialize self.app with 'myapp1.tests'
- - define the models used for testing in myapp1.tests.models
-
- This way the models defined in myapp1.tests.models will be available in
- this test case (and this test case only).
- """
-
- # Set the appropriate application to be loaded.
- app = None
-
- def _pre_setup(self):
- # Add the models to the db.
- self._original_installed_apps = list(settings.INSTALLED_APPS)
- assert self.app is not None, "TestCase.app must be defined!"
- settings.INSTALLED_APPS.append(self.app)
- loading.cache.loaded = False
- # Use Django's 'syncdb' rather than South's.
- syncdb.Command().handle_noargs(verbosity=0, interactive=False)
- super(TestModelTestCase, self)._pre_setup()
-
- def _post_teardown(self):
- super(TestModelTestCase, self)._post_teardown()
- # Restore the settings.
- settings.INSTALLED_APPS = self._original_installed_apps
- loading.cache.loaded = False
=== modified file 'src/metadataserver/tests/test_api.py'
--- src/metadataserver/tests/test_api.py 2012-04-16 10:00:51 +0000
+++ src/metadataserver/tests/test_api.py 2012-04-19 16:26:18 +0000
@@ -25,7 +25,7 @@
from maasserver.testing import reload_object
from maasserver.testing.factory import factory
from maasserver.testing.oauthclient import OAuthAuthenticatedClient
-from maastesting.testcase import TestCase
+from maastesting.djangotestcase import DjangoTestCase
from metadataserver.api import (
check_version,
get_node_for_request,
@@ -43,7 +43,7 @@
from provisioningserver.testing.factory import ProvisioningFakeFactory
-class TestHelpers(TestCase):
+class TestHelpers(DjangoTestCase):
"""Tests for the API helper functions."""
def fake_request(self, **kwargs):
@@ -86,7 +86,7 @@
get_node_for_request, self.fake_request())
-class TestViews(TestCase, ProvisioningFakeFactory):
+class TestViews(DjangoTestCase, ProvisioningFakeFactory):
"""Tests for the API views."""
def make_node_client(self, node=None):
=== modified file 'src/metadataserver/tests/test_models.py'
--- src/metadataserver/tests/test_models.py 2012-04-16 10:00:51 +0000
+++ src/metadataserver/tests/test_models.py 2012-04-19 16:26:18 +0000
@@ -15,7 +15,7 @@
from django.db import IntegrityError
from django.http import Http404
from maasserver.testing.factory import factory
-from maastesting.testcase import TestCase
+from maastesting.djangotestcase import DjangoTestCase
from metadataserver.models import (
NodeCommissionResult,
NodeKey,
@@ -23,7 +23,7 @@
)
-class TestNodeKeyManager(TestCase):
+class TestNodeKeyManager(DjangoTestCase):
"""Test NodeKeyManager."""
def setUp(self):
@@ -72,7 +72,7 @@
NodeKey.objects.get_node_for_key(key)).key)
-class TestNodeUserDataManager(TestCase):
+class TestNodeUserDataManager(DjangoTestCase):
"""Test NodeUserDataManager."""
def setUp(self):
@@ -137,7 +137,7 @@
self.assertTrue(NodeUserData.objects.has_user_data(node))
-class TestNodeCommissionResult(TestCase):
+class TestNodeCommissionResult(DjangoTestCase):
"""Test the NodeCommissionResult model."""
def test_can_store_data(self):
@@ -166,7 +166,7 @@
self.assertEqual(ncr1.name, ncr2.name)
-class TestNodeCommissionResultManager(TestCase):
+class TestNodeCommissionResultManager(DjangoTestCase):
"""Test the manager utility for NodeCommissionResult."""
def test_clear_results_removes_rows(self):