1. pombredanne
  2. django-multi-schema

Commits

Matthew Schinckel  committed 8a49d89

fixes for test only.
Was testing object identity only using pk.
this is no longer valid when object pks are no longer guaranteed
unique across schemata.

  • Participants
  • Parent commits e503496
  • Branches default

Comments (0)

Files changed (2)

File multi_schema/models.py

View file
     def save(self, *args, **kwargs):
         self._meta.get_field_by_name('schema')[0].run_validators(self.schema)
         
-        if self.tracker.previous('schema') is None:
+        if self.tracker.previous('schema') is None or 'force_insert' in kwargs:
             try:
                 Schema.objects.get(schema=self.schema)
             except Schema.DoesNotExist:

File multi_schema/tests/test_objects_are_partitioned.py

View file
         
         second.activate()
         self.assertEquals(0, AwareModel.objects.count())
-        AwareModel.objects.create(name="Foo object")
-        self.assertNotEqual(foo, AwareModel.objects.get(name=foo.name))
+        AwareModel.objects.create(name="Baz object")
+        self.assertRaises(AwareModel.DoesNotExist, AwareModel.objects.get, name='Foo object')
         
         # TODO: Make this work?
         # second.deactivate()
         # self.assertEquals(0, AwareModel.objects.count())
         
         first.activate()
-        self.assertEquals(foo, AwareModel.objects.get(name=foo.name))
+        self.assertRaises(AwareModel.DoesNotExist, AwareModel.objects.get, name='Baz object')
         
     def test_multi_schema_manager(self):
         first = Schema.objects.create(name='first', schema='first')
         second = Schema.objects.create(name='second', schema='second')
         
         first.activate()
-        foo = AwareModel.objects.create(name="Foo object")
-        bar = AwareModel.objects.create(name="Bar object")
+        foo = AwareModel.objects.create(name="Foo object").name
+        bar = AwareModel.objects.create(name="Bar object").name
         
         second.activate()
-        baz = AwareModel.objects.create(name="Baz object")
+        baz = AwareModel.objects.create(name="Baz object").name
         
         second.deactivate()
         
         self.assertEquals(3, len(list(AwareModel.objects.from_schemata(Schema.objects.all()))))
         
-        self.assertEquals([baz], list(AwareModel.objects.from_schemata(second)))
-        self.assertNotIn(baz, list(AwareModel.objects.from_schemata(first)))
+        self.assertEquals([baz], [x.name for x in AwareModel.objects.from_schemata(second)])
+        self.assertNotIn(baz, [x.name for x in AwareModel.objects.from_schemata(first)])
     
     def test_naive_objects_are_created_in_public_schema(self):
         first = Schema.objects.create(name='first', schema='first')