diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 020b3165..f8503c8c 100644
a
|
b
|
import json
|
3 | 3 | import unittest |
4 | 4 | import uuid |
5 | 5 | |
6 | | from django.contrib.postgres.fields import ArrayField |
7 | | from django.contrib.postgres.forms import SimpleArrayField, SplitArrayField |
| 6 | try: |
| 7 | import psycopg2 |
| 8 | except ImportError: |
| 9 | psycopg2 = None |
| 10 | |
| 11 | if psycopg2: |
| 12 | from django.contrib.postgres.fields import ArrayField |
| 13 | from django.contrib.postgres.forms import SimpleArrayField, SplitArrayField |
| 14 | |
8 | 15 | from django.core import exceptions, serializers |
9 | 16 | from django.core.management import call_command |
10 | 17 | from django.db import models, IntegrityError, connection |
… |
… |
from django import forms
|
12 | 19 | from django.test import TestCase, override_settings |
13 | 20 | from django.utils import timezone |
14 | 21 | |
15 | | from .models import ( |
16 | | IntegerArrayModel, NullableIntegerArrayModel, CharArrayModel, |
17 | | DateTimeArrayModel, NestedIntegerArrayModel, OtherTypesArrayModel, |
18 | | ArrayFieldSubclass, |
| 22 | if psycopg2: |
| 23 | from .models import ( |
| 24 | IntegerArrayModel, NullableIntegerArrayModel, CharArrayModel, |
| 25 | DateTimeArrayModel, NestedIntegerArrayModel, OtherTypesArrayModel, |
| 26 | ArrayFieldSubclass, |
19 | 27 | ) |
20 | 28 | |
21 | | |
| 29 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
22 | 30 | @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') |
23 | 31 | class TestSaveLoad(TestCase): |
24 | 32 | |
… |
… |
class TestSaveLoad(TestCase):
|
95 | 103 | self.assertEqual(instance.decimals, loaded.decimals) |
96 | 104 | |
97 | 105 | |
| 106 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
98 | 107 | @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') |
99 | 108 | class TestQuerying(TestCase): |
100 | 109 | |
… |
… |
class TestQuerying(TestCase):
|
227 | 236 | ) |
228 | 237 | |
229 | 238 | |
| 239 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
230 | 240 | class TestChecks(TestCase): |
231 | 241 | |
232 | 242 | def test_field_checks(self): |
… |
… |
class TestChecks(TestCase):
|
244 | 254 | self.assertEqual(errors[0].id, 'postgres.E002') |
245 | 255 | |
246 | 256 | |
| 257 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
247 | 258 | class TestMigrations(TestCase): |
248 | 259 | |
249 | 260 | def test_deconstruct(self): |
… |
… |
class TestMigrations(TestCase):
|
282 | 293 | call_command('migrate', 'postgres_tests', verbosity=0) |
283 | 294 | |
284 | 295 | |
| 296 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
285 | 297 | @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') |
286 | 298 | class TestSerialization(TestCase): |
287 | 299 | test_data = '[{"fields": {"field": "[\\"1\\", \\"2\\"]"}, "model": "postgres_tests.integerarraymodel", "pk": null}]' |
… |
… |
class TestSerialization(TestCase):
|
296 | 308 | self.assertEqual(instance.field, [1, 2]) |
297 | 309 | |
298 | 310 | |
| 311 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
299 | 312 | class TestValidation(TestCase): |
300 | 313 | |
301 | 314 | def test_unbounded(self): |
… |
… |
class TestValidation(TestCase):
|
326 | 339 | self.assertEqual(cm.exception.messages[0], 'Nested arrays must have the same length.') |
327 | 340 | |
328 | 341 | |
| 342 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
329 | 343 | class TestSimpleFormField(TestCase): |
330 | 344 | |
331 | 345 | def test_valid(self): |
… |
… |
class TestSimpleFormField(TestCase):
|
398 | 412 | self.assertEqual(form_field.max_length, 4) |
399 | 413 | |
400 | 414 | |
| 415 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
401 | 416 | class TestSplitFormField(TestCase): |
402 | 417 | |
403 | 418 | def test_valid(self): |
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py
index ac22f322..eece6113 100644
a
|
b
|
|
1 | 1 | import json |
2 | 2 | import unittest |
3 | 3 | |
4 | | from django.contrib.postgres import forms |
5 | | from django.contrib.postgres.fields import HStoreField |
6 | | from django.contrib.postgres.validators import KeysValidator |
| 4 | try: |
| 5 | import psycopg2 |
| 6 | except ImportError: |
| 7 | psycopg2 = None |
| 8 | |
| 9 | if psycopg2: |
| 10 | from django.contrib.postgres import forms |
| 11 | from django.contrib.postgres.fields import HStoreField |
| 12 | from django.contrib.postgres.validators import KeysValidator |
| 13 | |
7 | 14 | from django.core import exceptions, serializers |
8 | 15 | from django.db import connection |
9 | 16 | from django.test import TestCase |
10 | 17 | |
11 | | from .models import HStoreModel |
| 18 | if psycopg2: |
| 19 | from .models import HStoreModel |
12 | 20 | |
13 | 21 | |
| 22 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
14 | 23 | @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') |
15 | 24 | class SimpleTests(TestCase): |
16 | 25 | apps = ['django.contrib.postgres'] |
… |
… |
class SimpleTests(TestCase):
|
36 | 45 | self.assertEqual(reloaded.field, value) |
37 | 46 | |
38 | 47 | |
| 48 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
39 | 49 | @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') |
40 | 50 | class TestQuerying(TestCase): |
41 | 51 | |
… |
… |
class TestQuerying(TestCase):
|
115 | 125 | ) |
116 | 126 | |
117 | 127 | |
| 128 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
118 | 129 | @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') |
119 | 130 | class TestSerialization(TestCase): |
120 | 131 | test_data = '[{"fields": {"field": "{\\"a\\": \\"b\\"}"}, "model": "postgres_tests.hstoremodel", "pk": null}]' |
… |
… |
class TestSerialization(TestCase):
|
129 | 140 | self.assertEqual(instance.field, {'a': 'b'}) |
130 | 141 | |
131 | 142 | |
| 143 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
132 | 144 | class TestValidation(TestCase): |
133 | 145 | |
134 | 146 | def test_not_a_string(self): |
… |
… |
class TestValidation(TestCase):
|
139 | 151 | self.assertEqual(cm.exception.message % cm.exception.params, 'The value of "a" is not a string.') |
140 | 152 | |
141 | 153 | |
| 154 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
142 | 155 | class TestFormField(TestCase): |
143 | 156 | |
144 | 157 | def test_valid(self): |
… |
… |
class TestFormField(TestCase):
|
169 | 182 | self.assertIsInstance(form_field, forms.HStoreField) |
170 | 183 | |
171 | 184 | |
| 185 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
172 | 186 | class TestValidator(TestCase): |
173 | 187 | |
174 | 188 | def test_simple_valid(self): |
diff --git a/tests/postgres_tests/test_ranges.py b/tests/postgres_tests/test_ranges.py
index bc15987b..ab11c64c 100644
a
|
b
|
import json
|
3 | 3 | import unittest |
4 | 4 | |
5 | 5 | from django import forms |
6 | | from django.contrib.postgres import forms as pg_forms, fields as pg_fields |
7 | | from django.contrib.postgres.validators import RangeMaxValueValidator, RangeMinValueValidator |
| 6 | |
| 7 | try: |
| 8 | import psycopg2 |
| 9 | except ImportError: |
| 10 | psycopg2 = None |
| 11 | |
| 12 | if psycopg2: |
| 13 | from django.contrib.postgres import forms as pg_forms, fields as pg_fields |
| 14 | from django.contrib.postgres.validators import RangeMaxValueValidator, RangeMinValueValidator |
| 15 | |
8 | 16 | from django.core import exceptions, serializers |
9 | 17 | from django.db import connection |
10 | 18 | from django.test import TestCase |
11 | 19 | from django.utils import timezone |
12 | 20 | |
13 | | from psycopg2.extras import NumericRange, DateTimeTZRange, DateRange |
| 21 | if psycopg2: |
| 22 | from psycopg2.extras import NumericRange, DateTimeTZRange, DateRange |
14 | 23 | |
15 | | from .models import RangesModel |
| 24 | from .models import RangesModel |
16 | 25 | |
17 | 26 | |
18 | 27 | def skipUnlessPG92(test): |
… |
… |
def skipUnlessPG92(test):
|
24 | 33 | return test |
25 | 34 | |
26 | 35 | |
| 36 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
27 | 37 | @skipUnlessPG92 |
28 | 38 | class TestSaveLoad(TestCase): |
29 | 39 | |
… |
… |
class TestSaveLoad(TestCase):
|
86 | 96 | self.assertEqual(None, loaded.ints) |
87 | 97 | |
88 | 98 | |
| 99 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
89 | 100 | @skipUnlessPG92 |
90 | 101 | class TestQuerying(TestCase): |
91 | 102 | |
… |
… |
class TestQuerying(TestCase):
|
190 | 201 | ) |
191 | 202 | |
192 | 203 | |
| 204 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
193 | 205 | @skipUnlessPG92 |
194 | 206 | class TestSerialization(TestCase): |
195 | 207 | test_data = ( |
… |
… |
class TestSerialization(TestCase):
|
215 | 227 | self.assertEqual(instance.dates, None) |
216 | 228 | |
217 | 229 | |
| 230 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
218 | 231 | class TestValidators(TestCase): |
219 | 232 | |
220 | 233 | def test_max(self): |
… |
… |
class TestValidators(TestCase):
|
234 | 247 | self.assertEqual(cm.exception.code, 'min_value') |
235 | 248 | |
236 | 249 | |
| 250 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
237 | 251 | class TestFormField(TestCase): |
238 | 252 | |
239 | 253 | def test_valid_integer(self): |
… |
… |
class TestFormField(TestCase):
|
376 | 390 | self.assertIsInstance(form_field, pg_forms.DateTimeRangeField) |
377 | 391 | |
378 | 392 | |
| 393 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
379 | 394 | class TestWidget(TestCase): |
380 | 395 | def test_range_widget(self): |
381 | 396 | f = pg_forms.ranges.DateTimeRangeField() |
diff --git a/tests/postgres_tests/test_unaccent.py b/tests/postgres_tests/test_unaccent.py
index 47ccbda5..b15a9741 100644
a
|
b
|
import unittest
|
6 | 6 | from django.db import connection |
7 | 7 | from django.test import TestCase, modify_settings |
8 | 8 | |
9 | | from .models import CharFieldModel, TextFieldModel |
| 9 | try: |
| 10 | import psycopg2 |
| 11 | except ImportError: |
| 12 | psycopg2 = None |
10 | 13 | |
| 14 | if psycopg2: |
| 15 | from .models import CharFieldModel, TextFieldModel |
| 16 | else: |
| 17 | CharFieldModel = None |
| 18 | TextFieldModel = None |
11 | 19 | |
| 20 | |
| 21 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
12 | 22 | @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') |
13 | 23 | @modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}) |
14 | 24 | class UnaccentTest(TestCase): |
… |
… |
class UnaccentTest(TestCase):
|
57 | 67 | ) |
58 | 68 | |
59 | 69 | |
| 70 | @unittest.skipIf(psycopg2 is None, 'PostgreSQL required') |
60 | 71 | class UnaccentTextFieldTest(UnaccentTest): |
61 | 72 | """ |
62 | 73 | TextField should have the exact same behavior as CharField |