| 152 | |
| 153 | class MultiDbUniqueTests(TestCase): |
| 154 | multi_db = True |
| 155 | |
| 156 | def test_unique_checks_multi_db_with_uniqfieldsmodel(self): |
| 157 | UniqueFieldsModel(unique_charfield='Hello world', unique_integerfield=42, non_unique_field=3).save(using='default') |
| 158 | u = UniqueFieldsModel(unique_charfield='Hello world', unique_integerfield=42, non_unique_field=3) |
| 159 | u._state.db = 'other' |
| 160 | self.assertEqual(u.validate_unique(), None) |
| 161 | u.save() |
| 162 | self.assertEqual(UniqueFieldsModel.objects.using('default').count(), 1) |
| 163 | self.assertEqual(UniqueFieldsModel.objects.using('other').count(), 1) |
| 164 | |
| 165 | def test_unique_checks_multi_db_with_uniquetogethermodel(self): |
| 166 | UniqueTogetherModel(cfield='Hello world', ifield=42, efield='user@example.org').save(using='default') |
| 167 | u = UniqueTogetherModel(cfield='Hello world', ifield=42, efield='user@example.org') |
| 168 | u._state.db = 'other' |
| 169 | self.assertEqual(u.validate_unique(), None) |
| 170 | u.save() |
| 171 | self.assertEqual(UniqueTogetherModel.objects.using('default').count(), 1) |
| 172 | self.assertEqual(UniqueTogetherModel.objects.using('other').count(), 1) |
| 173 | |
| 174 | def test_unique_checks_multi_db_with_uniquefordatemodel(self): |
| 175 | today = datetime.date.today() |
| 176 | now = datetime.datetime.now() |
| 177 | UniqueForDateModel(start_date=today, end_date=now, count=314, order=21, name='Foo').save(using='default') |
| 178 | u = UniqueForDateModel(start_date=today, end_date=now, count=314, order=21, name='Foo') |
| 179 | u._state.db = 'other' |
| 180 | self.assertEqual(u.validate_unique(), None) |
| 181 | u.save() |
| 182 | self.assertEqual(UniqueForDateModel.objects.using('default').count(), 1) |
| 183 | self.assertEqual(UniqueForDateModel.objects.using('other').count(), 1) |