summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Williams <neil.williams@linaro.org>2015-11-03 13:28:51 +0000
committerNeil Williams <neil.williams@linaro.org>2015-11-13 11:09:02 +0000
commite1b93591d1f8c187a951d832f767a8c16c6192e5 (patch)
treeb1595790e510b0929b8e6f6c379e205666d8b873
parent3d9637a293f713838362f0e7865fa7bd6f858a4c (diff)
LAVA-402 Update transaction management in unit tests
Port the unit test support (only) to atomic transactions. Bump version and django dependency Debian bug: #801930 Change-Id: I12baf1ac998c9e89dea82689220ed8d97cf07aa3
-rw-r--r--.gitreview5
-rw-r--r--django_testscenarios/tests.py42
-rwxr-xr-xsetup.py4
3 files changed, 28 insertions, 23 deletions
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..c9e4b9b
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=review.linaro.org
+port=29418
+project=lava/django-testscenarios
+
diff --git a/django_testscenarios/tests.py b/django_testscenarios/tests.py
index 5fad151..c65b3f7 100644
--- a/django_testscenarios/tests.py
+++ b/django_testscenarios/tests.py
@@ -1,6 +1,7 @@
-# Copyright (C) 2010, 2011 Linaro Limited
+# Copyright (C) 2010, 2011, 2015 Linaro Limited
#
# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+# Neil Williams <neil.williams@linaro.org>
#
# This file is part of django-testscenarios.
#
@@ -40,6 +41,7 @@ class TestModel(models.Model):
Model for testing database configuration/initialization
"""
field = models.CharField(max_length=10, null=True)
+ broken = models.IntegerField(default=1)
class ScenarioParametersAreVisibleChecks(object):
@@ -69,6 +71,7 @@ class PlainDatabaseChecks(object):
class TransactionChecks(object):
+ @transaction.atomic
def _create_object(self):
self.obj = TestModel.objects.create(field=None)
self.pk = self.obj.pk
@@ -76,28 +79,25 @@ class TransactionChecks(object):
def _reload_object(self):
self.obj = TestModel.objects.get(pk=self.pk)
- def _commit_and_reload(self):
- transaction.commit()
- self._reload_object()
-
- def _rollback_and_reload(self):
- transaction.rollback()
- self._reload_object()
-
def test_transaction_handling(self):
- transaction.enter_transaction_management()
- transaction.managed(True)
- try:
+ with transaction.atomic():
self._create_object()
- self._commit_and_reload()
- self.assertEqual(self.obj.field, None)
- self.obj.field = "something"
- self.obj.save()
- self._rollback_and_reload()
- self.assertEqual(self.obj.field, None)
- finally:
- transaction.rollback()
- transaction.leave_transaction_management()
+ self._reload_object()
+ self.assertEqual(self.obj.field, None)
+ self.obj.field = "something"
+ self.obj.save()
+ try:
+ self.obj.broken = 'not an integer'
+ except ValueError:
+ pass
+ try:
+ with transaction.atomic():
+ self.obj.save()
+ except ValueError:
+ pass
+ self._reload_object()
+ self.assertEqual(self.obj.broken, 1)
+ self.assertNotEqual(self.obj.field, None)
# Non-transaction tests
diff --git a/setup.py b/setup.py
index e2ea563..26523f5 100755
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ from setuptools import setup
setup(
name='django-testscenarios',
- version="0.7.4",
+ version="0.8",
author="Linaro Limited",
author_email="lava-team@linaro.org",
description="Test scenarios for Django",
@@ -45,7 +45,7 @@ setup(
'django_testscenarios',
],
install_requires=[
- 'django >= 1.6',
+ 'django >= 1.7',
'django-testproject >= 0.1.1',
'testtools >= 0.9.2',
'testscenarios >= 0.1',