1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
From: Michael Fladischer <FladischerMichael@fladi.at>
Date: Tue, 29 Nov 2016 13:34:15 +0100
Subject: Skip postgresql and mysql tests.
---
tests/test_app/tests/test_api.py | 15 +++++++++++++++
tests/test_app/tests/test_commands.py | 18 ++++++++++++++++++
tests/test_app/tests/test_models.py | 24 ++++++++++++++++++++++++
tests/test_project/settings.py | 27 +++++++++++++++++++++------
4 files changed, 78 insertions(+), 6 deletions(-)
diff --git a/tests/test_app/tests/test_api.py b/tests/test_app/tests/test_api.py
index c7301c1..b1e2ef8 100644
--- a/tests/test_app/tests/test_api.py
+++ b/tests/test_app/tests/test_api.py
@@ -1,3 +1,4 @@
+import unittest
from datetime import timedelta
from django.contrib.auth.models import User
from django.db import models
@@ -12,6 +13,16 @@ try:
except ImportError:
from mock import MagicMock
+try:
+ import psycopg2
+except ImportError:
+ psycopg2 = None
+
+try:
+ import MySQLdb
+except ImportError:
+ MySQLdb = None
+
class SaveTest(TestModelMixin, TestBase):
@@ -159,6 +170,8 @@ class CreateRevisionManageManuallyTest(TestModelMixin, TestBase):
class CreateRevisionDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testCreateRevisionMultiDb(self):
with reversion.create_revision(using="mysql"), reversion.create_revision(using="postgres"):
obj = TestModel.objects.create()
@@ -319,6 +332,8 @@ class AddMetaTest(TestModelMixin, TestBase):
with self.assertRaises(reversion.RevisionManagementError):
reversion.add_meta(TestMeta, name="meta v1")
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testAddMetaMultDb(self):
with reversion.create_revision(using="mysql"), reversion.create_revision(using="postgres"):
obj = TestModel.objects.create()
diff --git a/tests/test_app/tests/test_commands.py b/tests/test_app/tests/test_commands.py
index b1ceed5..0c3090b 100644
--- a/tests/test_app/tests/test_commands.py
+++ b/tests/test_app/tests/test_commands.py
@@ -1,4 +1,5 @@
import json
+import unittest
from datetime import timedelta
from django.core.management import CommandError
from django.utils import timezone
@@ -6,6 +7,16 @@ import reversion
from test_app.models import TestModel
from test_app.tests.base import TestBase, TestModelMixin
+try:
+ import psycopg2
+except ImportError:
+ psycopg2 = None
+
+try:
+ import MySQLdb
+except ImportError:
+ MySQLdb = None
+
class CreateInitialRevisionsTest(TestModelMixin, TestBase):
@@ -53,12 +64,14 @@ class CreateInitialRevisionsAppLabelTest(TestModelMixin, TestBase):
class CreateInitialRevisionsDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testCreateInitialRevisionsDb(self):
obj = TestModel.objects.create()
self.callCommand("createinitialrevisions", using="postgres")
self.assertNoRevision()
self.assertSingleRevision((obj,), comment="Initial version.", using="postgres")
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testCreateInitialRevisionsDbMySql(self):
obj = TestModel.objects.create()
self.callCommand("createinitialrevisions", using="mysql")
@@ -68,6 +81,7 @@ class CreateInitialRevisionsDbTest(TestModelMixin, TestBase):
class CreateInitialRevisionsModelDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testCreateInitialRevisionsModelDb(self):
obj = TestModel.objects.db_manager("postgres").create()
self.callCommand("createinitialrevisions", model_db="postgres")
@@ -135,18 +149,21 @@ class DeleteRevisionsAppLabelTest(TestModelMixin, TestBase):
class DeleteRevisionsDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testDeleteRevisionsDb(self):
with reversion.create_revision(using="postgres"):
TestModel.objects.create()
self.callCommand("deleterevisions", using="postgres")
self.assertNoRevision(using="postgres")
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testDeleteRevisionsDbMySql(self):
with reversion.create_revision(using="mysql"):
TestModel.objects.create()
self.callCommand("deleterevisions", using="mysql")
self.assertNoRevision(using="mysql")
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testDeleteRevisionsDbNoMatch(self):
with reversion.create_revision():
obj = TestModel.objects.create()
@@ -156,6 +173,7 @@ class DeleteRevisionsDbTest(TestModelMixin, TestBase):
class DeleteRevisionsModelDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testDeleteRevisionsModelDb(self):
with reversion.create_revision():
TestModel.objects.db_manager("postgres").create()
diff --git a/tests/test_app/tests/test_models.py b/tests/test_app/tests/test_models.py
index d426fae..aec5317 100644
--- a/tests/test_app/tests/test_models.py
+++ b/tests/test_app/tests/test_models.py
@@ -1,3 +1,4 @@
+import unittest
from django.utils.encoding import force_text
import reversion
from reversion.models import Version
@@ -7,6 +8,16 @@ from test_app.models import (
)
from test_app.tests.base import TestBase, TestModelMixin, TestModelParentMixin
+try:
+ import psycopg2
+except ImportError:
+ psycopg2 = None
+
+try:
+ import MySQLdb
+except ImportError:
+ MySQLdb = None
+
class GetForModelTest(TestModelMixin, TestBase):
@@ -18,11 +29,13 @@ class GetForModelTest(TestModelMixin, TestBase):
class GetForModelDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetForModelDb(self):
with reversion.create_revision(using="postgres"):
obj = TestModel.objects.create()
self.assertEqual(Version.objects.using("postgres").get_for_model(obj.__class__).count(), 1)
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testGetForModelDbMySql(self):
with reversion.create_revision(using="mysql"):
obj = TestModel.objects.create()
@@ -60,12 +73,14 @@ class GetForObjectTest(TestModelMixin, TestBase):
class GetForObjectDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetForObjectDb(self):
with reversion.create_revision(using="postgres"):
obj = TestModel.objects.create()
self.assertEqual(Version.objects.get_for_object(obj).count(), 0)
self.assertEqual(Version.objects.using("postgres").get_for_object(obj).count(), 1)
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testGetForObjectDbMySql(self):
with reversion.create_revision(using="mysql"):
obj = TestModel.objects.create()
@@ -75,6 +90,7 @@ class GetForObjectDbTest(TestModelMixin, TestBase):
class GetForObjectModelDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetForObjectModelDb(self):
with reversion.create_revision():
obj = TestModel.objects.db_manager("postgres").create()
@@ -131,6 +147,7 @@ class GetForObjectReferenceTest(TestModelMixin, TestBase):
class GetForObjectReferenceDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetForObjectReferenceModelDb(self):
with reversion.create_revision(using="postgres"):
obj = TestModel.objects.create()
@@ -140,12 +157,14 @@ class GetForObjectReferenceDbTest(TestModelMixin, TestBase):
class GetForObjectReferenceModelDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetForObjectReferenceModelDb(self):
with reversion.create_revision():
obj = TestModel.objects.db_manager("postgres").create()
self.assertEqual(Version.objects.get_for_object_reference(TestModel, obj.pk).count(), 0)
self.assertEqual(Version.objects.get_for_object_reference(TestModel, obj.pk, model_db="postgres").count(), 1)
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testGetForObjectReferenceModelDbMySql(self):
with reversion.create_revision():
obj = TestModel.objects.db_manager("mysql").create()
@@ -180,6 +199,7 @@ class GetDeletedTest(TestModelMixin, TestBase):
self.assertEqual(Version.objects.get_deleted(TestModel)[0].object_id, force_text(pk_2))
self.assertEqual(Version.objects.get_deleted(TestModel)[1].object_id, force_text(pk_1))
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetDeletedPostgres(self):
with reversion.create_revision(using="postgres"):
obj = TestModel.objects.using("postgres").create()
@@ -188,6 +208,7 @@ class GetDeletedTest(TestModelMixin, TestBase):
obj.delete()
self.assertEqual(Version.objects.using("postgres").get_deleted(TestModel, model_db="postgres").count(), 1)
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testGetDeletedMySQL(self):
with reversion.create_revision(using="mysql"):
obj = TestModel.objects.using("mysql").create()
@@ -199,6 +220,7 @@ class GetDeletedTest(TestModelMixin, TestBase):
class GetDeletedDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetDeletedDb(self):
with reversion.create_revision(using="postgres"):
obj = TestModel.objects.create()
@@ -206,6 +228,7 @@ class GetDeletedDbTest(TestModelMixin, TestBase):
self.assertEqual(Version.objects.get_deleted(TestModel).count(), 0)
self.assertEqual(Version.objects.using("postgres").get_deleted(TestModel).count(), 1)
+ @unittest.skipIf(not MySQLdb, "MySQLdb not installed")
def testGetDeletedDbMySql(self):
with reversion.create_revision(using="mysql"):
obj = TestModel.objects.create()
@@ -216,6 +239,7 @@ class GetDeletedDbTest(TestModelMixin, TestBase):
class GetDeletedModelDbTest(TestModelMixin, TestBase):
+ @unittest.skipIf(not psycopg2, "psycopg2 not installed")
def testGetDeletedModelDb(self):
with reversion.create_revision():
obj = TestModel.objects.db_manager("postgres").create()
diff --git a/tests/test_project/settings.py b/tests/test_project/settings.py
index 2df52e2..79191fb 100644
--- a/tests/test_project/settings.py
+++ b/tests/test_project/settings.py
@@ -13,6 +13,17 @@ https://docs.djangoproject.com/en/dev/ref/settings/
import os
import getpass
+try:
+ import psycopg2
+except ImportError:
+ psycopg2 = None
+
+try:
+ import MySQLdb
+except ImportError:
+ MySQLdb = None
+
+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -80,20 +91,24 @@ DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
- },
- "postgres": {
+ }
+}
+
+if psycopg2:
+ DATABASES["postgres"] = {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.environ.get("DJANGO_DATABASE_NAME_POSTGRES", "test_project"),
"USER": os.environ.get("DJANGO_DATABASE_USER_POSTGRES", getpass.getuser()),
"PASSWORD": os.environ.get("DJANGO_DATABASE_PASSWORD_POSTGRES", ""),
- },
- "mysql": {
+ }
+
+if MySQLdb:
+ DATABASES["mysql"] = {
"ENGINE": "django.db.backends.mysql",
"NAME": os.environ.get("DJANGO_DATABASE_NAME_MYSQL", "test_project"),
"USER": os.environ.get("DJANGO_DATABASE_USER_MYSQL", getpass.getuser()),
"PASSWORD": os.environ.get("DJANGO_DATABASE_PASSWORD_MYSQL", ""),
- },
-}
+ }
# Password validation
|