Ticket #24290: 24290.diff

File 24290.diff, 9.2 KB (added by Joel Burton, 10 years ago)

Patch

  • tests/postgres_tests/test_array.py

    diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
    index 020b3165..f8503c8c 100644
    a b import json  
    33import unittest
    44import uuid
    55
    6 from django.contrib.postgres.fields import ArrayField
    7 from django.contrib.postgres.forms import SimpleArrayField, SplitArrayField
     6try:
     7    import psycopg2
     8except ImportError:
     9    psycopg2 = None
     10
     11if psycopg2:
     12    from django.contrib.postgres.fields import ArrayField
     13    from django.contrib.postgres.forms import SimpleArrayField, SplitArrayField
     14
    815from django.core import exceptions, serializers
    916from django.core.management import call_command
    1017from django.db import models, IntegrityError, connection
    from django import forms  
    1219from django.test import TestCase, override_settings
    1320from django.utils import timezone
    1421
    15 from .models import (
    16     IntegerArrayModel, NullableIntegerArrayModel, CharArrayModel,
    17     DateTimeArrayModel, NestedIntegerArrayModel, OtherTypesArrayModel,
    18     ArrayFieldSubclass,
     22if psycopg2:
     23    from .models import (
     24        IntegerArrayModel, NullableIntegerArrayModel, CharArrayModel,
     25        DateTimeArrayModel, NestedIntegerArrayModel, OtherTypesArrayModel,
     26        ArrayFieldSubclass,
    1927)
    2028
    21 
     29@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    2230@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
    2331class TestSaveLoad(TestCase):
    2432
    class TestSaveLoad(TestCase):  
    95103        self.assertEqual(instance.decimals, loaded.decimals)
    96104
    97105
     106@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    98107@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
    99108class TestQuerying(TestCase):
    100109
    class TestQuerying(TestCase):  
    227236        )
    228237
    229238
     239@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    230240class TestChecks(TestCase):
    231241
    232242    def test_field_checks(self):
    class TestChecks(TestCase):  
    244254        self.assertEqual(errors[0].id, 'postgres.E002')
    245255
    246256
     257@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    247258class TestMigrations(TestCase):
    248259
    249260    def test_deconstruct(self):
    class TestMigrations(TestCase):  
    282293        call_command('migrate', 'postgres_tests', verbosity=0)
    283294
    284295
     296@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    285297@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
    286298class TestSerialization(TestCase):
    287299    test_data = '[{"fields": {"field": "[\\"1\\", \\"2\\"]"}, "model": "postgres_tests.integerarraymodel", "pk": null}]'
    class TestSerialization(TestCase):  
    296308        self.assertEqual(instance.field, [1, 2])
    297309
    298310
     311@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    299312class TestValidation(TestCase):
    300313
    301314    def test_unbounded(self):
    class TestValidation(TestCase):  
    326339        self.assertEqual(cm.exception.messages[0], 'Nested arrays must have the same length.')
    327340
    328341
     342@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    329343class TestSimpleFormField(TestCase):
    330344
    331345    def test_valid(self):
    class TestSimpleFormField(TestCase):  
    398412        self.assertEqual(form_field.max_length, 4)
    399413
    400414
     415@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    401416class TestSplitFormField(TestCase):
    402417
    403418    def test_valid(self):
  • tests/postgres_tests/test_hstore.py

    diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py
    index ac22f322..eece6113 100644
    a b  
    11import json
    22import unittest
    33
    4 from django.contrib.postgres import forms
    5 from django.contrib.postgres.fields import HStoreField
    6 from django.contrib.postgres.validators import KeysValidator
     4try:
     5    import psycopg2
     6except ImportError:
     7    psycopg2 = None
     8
     9if 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
    714from django.core import exceptions, serializers
    815from django.db import connection
    916from django.test import TestCase
    1017
    11 from .models import HStoreModel
     18if psycopg2:
     19    from .models import HStoreModel
    1220
    1321
     22@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    1423@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
    1524class SimpleTests(TestCase):
    1625    apps = ['django.contrib.postgres']
    class SimpleTests(TestCase):  
    3645        self.assertEqual(reloaded.field, value)
    3746
    3847
     48@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    3949@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
    4050class TestQuerying(TestCase):
    4151
    class TestQuerying(TestCase):  
    115125        )
    116126
    117127
     128@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    118129@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
    119130class TestSerialization(TestCase):
    120131    test_data = '[{"fields": {"field": "{\\"a\\": \\"b\\"}"}, "model": "postgres_tests.hstoremodel", "pk": null}]'
    class TestSerialization(TestCase):  
    129140        self.assertEqual(instance.field, {'a': 'b'})
    130141
    131142
     143@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    132144class TestValidation(TestCase):
    133145
    134146    def test_not_a_string(self):
    class TestValidation(TestCase):  
    139151        self.assertEqual(cm.exception.message % cm.exception.params, 'The value of "a" is not a string.')
    140152
    141153
     154@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    142155class TestFormField(TestCase):
    143156
    144157    def test_valid(self):
    class TestFormField(TestCase):  
    169182        self.assertIsInstance(form_field, forms.HStoreField)
    170183
    171184
     185@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    172186class TestValidator(TestCase):
    173187
    174188    def test_simple_valid(self):
  • tests/postgres_tests/test_ranges.py

    diff --git a/tests/postgres_tests/test_ranges.py b/tests/postgres_tests/test_ranges.py
    index bc15987b..ab11c64c 100644
    a b import json  
    33import unittest
    44
    55from 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
     7try:
     8    import psycopg2
     9except ImportError:
     10    psycopg2 = None
     11
     12if 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
    816from django.core import exceptions, serializers
    917from django.db import connection
    1018from django.test import TestCase
    1119from django.utils import timezone
    1220
    13 from psycopg2.extras import NumericRange, DateTimeTZRange, DateRange
     21if psycopg2:
     22    from psycopg2.extras import NumericRange, DateTimeTZRange, DateRange
    1423
    15 from .models import RangesModel
     24    from .models import RangesModel
    1625
    1726
    1827def skipUnlessPG92(test):
    def skipUnlessPG92(test):  
    2433    return test
    2534
    2635
     36@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    2737@skipUnlessPG92
    2838class TestSaveLoad(TestCase):
    2939
    class TestSaveLoad(TestCase):  
    8696        self.assertEqual(None, loaded.ints)
    8797
    8898
     99@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    89100@skipUnlessPG92
    90101class TestQuerying(TestCase):
    91102
    class TestQuerying(TestCase):  
    190201        )
    191202
    192203
     204@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    193205@skipUnlessPG92
    194206class TestSerialization(TestCase):
    195207    test_data = (
    class TestSerialization(TestCase):  
    215227        self.assertEqual(instance.dates, None)
    216228
    217229
     230@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    218231class TestValidators(TestCase):
    219232
    220233    def test_max(self):
    class TestValidators(TestCase):  
    234247        self.assertEqual(cm.exception.code, 'min_value')
    235248
    236249
     250@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    237251class TestFormField(TestCase):
    238252
    239253    def test_valid_integer(self):
    class TestFormField(TestCase):  
    376390        self.assertIsInstance(form_field, pg_forms.DateTimeRangeField)
    377391
    378392
     393@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    379394class TestWidget(TestCase):
    380395    def test_range_widget(self):
    381396        f = pg_forms.ranges.DateTimeRangeField()
  • tests/postgres_tests/test_unaccent.py

    diff --git a/tests/postgres_tests/test_unaccent.py b/tests/postgres_tests/test_unaccent.py
    index 47ccbda5..b15a9741 100644
    a b import unittest  
    66from django.db import connection
    77from django.test import TestCase, modify_settings
    88
    9 from .models import CharFieldModel, TextFieldModel
     9try:
     10    import psycopg2
     11except ImportError:
     12    psycopg2 = None
    1013
     14if psycopg2:
     15    from .models import CharFieldModel, TextFieldModel
     16else:
     17    CharFieldModel = None
     18    TextFieldModel = None
    1119
     20
     21@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    1222@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
    1323@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
    1424class UnaccentTest(TestCase):
    class UnaccentTest(TestCase):  
    5767        )
    5868
    5969
     70@unittest.skipIf(psycopg2 is None, 'PostgreSQL required')
    6071class UnaccentTextFieldTest(UnaccentTest):
    6172    """
    6273    TextField should have the exact same behavior as CharField
Back to Top