Ticket #15130: 15130-tests.diff

File 15130-tests.diff, 2.4 KB (added by Ramiro Morales, 9 years ago)

Tests (as an additon to the Djago test suite) that don't fail

  • tests/modeltests/validation/test_unique.py

    diff -r 4ef7bacebcda tests/modeltests/validation/test_unique.py
    a b  
    149149            self.fail("unique_for_month checks shouldn't trigger when the associated DateField is None.")
    150150        except:
    151151            self.fail("unique_for_month checks shouldn't explode when the associated DateField is None.")
     152
     153class MultiDbUniqueTests(TestCase):
     154    multi_db = True
     155
     156    def test_unique_checks_multi_db_isolation(self):
     157        UniqueFieldsModel(unique_charfield='Hello world', unique_integerfield=42, non_unique_field=3).save(using='default')
     158        UniqueFieldsModel(unique_charfield='Hello world', unique_integerfield=42, non_unique_field=3).save(using='other')
     159        self.assertEqual(UniqueFieldsModel.objects.using('default').count(), 1)
     160        self.assertEqual(UniqueFieldsModel.objects.using('other').count(), 1)
     161
     162        UniqueTogetherModel(cfield='Hello world', ifield=42, efield='user@example.org').save(using='default')
     163        UniqueTogetherModel(cfield='Hello world', ifield=42, efield='user@example.org').save(using='other')
     164        self.assertEqual(UniqueTogetherModel.objects.using('default').count(), 1)
     165        self.assertEqual(UniqueTogetherModel.objects.using('other').count(), 1)
     166
     167        today = datetime.date.today()
     168        now = datetime.datetime.now()
     169        UniqueForDateModel(start_date=today, end_date=now, count=314, order=21, name='Foo').save(using='default')
     170        UniqueForDateModel(start_date=today, end_date=now, count=314, order=21, name='Foo').save(using='other')
     171        self.assertEqual(UniqueForDateModel.objects.using('default').count(), 1)
     172        self.assertEqual(UniqueForDateModel.objects.using('other').count(), 1)
  • tests/modeltests/validation/tests.py

    diff -r 4ef7bacebcda tests/modeltests/validation/tests.py
    a b  
    77# Import other tests for this package.
    88from modeltests.validation.validators import TestModelsWithValidators
    99from modeltests.validation.test_unique import (GetUniqueCheckTests,
    10     PerformUniqueChecksTest)
     10    PerformUniqueChecksTest, MultiDbUniqueTests)
    1111from modeltests.validation.test_custom_messages import CustomMessagesTest
    1212
    1313
Back to Top