| 152 | |
| 153 | class 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) |