Example #1
0
    def test_nothing_changing(self):
        tm = TestModel()
        tm.boolean = False
        tm.characters = 'testing'
        tm.save()

        self.assertFalse(tm.save_stale())
Example #2
0
 def test_sweeping(self):
     tm = TestModel()
     tm.boolean = False
     tm.characters = 'testing'
     self.assertEqual(set(tm.dirty_fields), set(('boolean', 'characters')))
     tm.save()
     self.assertEqual(tm.dirty_fields, tuple())
Example #3
0
 def test_sweeping(self):
     tm = TestModel()
     tm.boolean = False
     tm.characters = 'testing'
     self.assertEqual(tm.get_dirty_fields(), {
         'boolean': True,
         'characters': ''
     })
     tm.save()
     self.assertEqual(tm.get_dirty_fields(), {})
Example #4
0
 def test_sweeping(self):
     tm = TestModel()
     tm.boolean = False
     tm.characters = 'testing'
     self.assertEqual(_changes(tm, _to_dict(tm)), {
         'boolean': True,
         'characters': ''
     })
     tm.save()
     self.assertEqual(_changes(tm, _to_dict(tm)), {})
 def test_sweeping(self):
     tm = TestModel()
     tm.boolean = False
     tm.characters = 'testing'
     self.assertEqual(tm.get_dirty_fields(), {
         'boolean': True,
         'characters': ''
     })
     tm.save()
     self.assertEqual(tm.get_dirty_fields(), {})
Example #6
0
 def test_sweeping(self):
     tm = TestModel()
     tm.boolean = False
     tm.characters = 'testing'
     self.assertEqual(_changes(tm, _to_dict(tm)), {
         'boolean': True,
         'characters': ''
     })
     tm.save()
     self.assertEqual(_changes(tm, _to_dict(tm)), {})
Example #7
0
    def test_foreign_key(self):
        tm = TestModel()
        tm.save()
        self.assertEqual(tm.get_dirty_fields(), {})

        foreign_model = ForeignTestModel(name="Foreign")
        foreign_model.save()
        tm.foreign = foreign_model
        self.assertEqual(tm.get_dirty_fields(), {
                'foreign_id': None})
        tm.save()
        self.assertEqual(tm.get_dirty_fields(), {})
Example #8
0
    def test_foreignkeys(self):
        ftm1 = ForeignTestModel.objects.create(characters="foreign1")
        ftm2 = ForeignTestModel.objects.create(characters="foreign2")

        tm = TestModel()
        tm.boolean = False
        tm.characters = 'testing'
        tm.foreign_test_model = ftm1
        self.assertEqual(set(tm.dirty_fields), set(('boolean', 'characters', 'foreign_test_model')))
        tm.save()

        self.assertEqual(tm.dirty_fields, tuple())
        tm.foreign_test_model = ftm2
        self.assertEqual(tm.dirty_fields, ('foreign_test_model', ))
        tm.foreign_test_model.characters = "foreign2.0"
        self.assertEqual(tm.foreign_test_model.dirty_fields, ('characters', ))
Example #9
0
    def test_is_dirty(self):
        tm = TestModel()
        self.assertTrue(tm.is_dirty())

        tm.save()
        self.assertFalse(tm.is_dirty())

        m = TestModelWithForeignKey()
        self.assertTrue(m.is_dirty())

        m.save()
        self.assertFalse(m.is_dirty())

        m.fkey = tm
        self.assertTrue(m.is_dirty())

        m.save()
        self.assertFalse(m.is_dirty())

        m = TestModelWithForeignKey.objects.create(
            fkey=TestModel.objects.create(), )
        self.assertFalse(m.is_dirty())
        m.fkey.boolean = not m.fkey.boolean
        self.assertFalse(m.is_dirty())
Example #10
0
    def test_many_to_many(self):
        tm = TestModel()
        tm.save()
        self.assertEqual(tm.get_dirty_fields(), {})

        m2m_model = ManyToManyTestModel(name="m2m")
        m2m_model.save()
        tm.many_to_many.add(m2m_model)
        self.assertEqual(tm.get_dirty_fields(), {
                'many_to_many': set() })
        tm.save()
        self.assertEqual(tm.get_dirty_fields(), {})

        second_m2m_model = ManyToManyTestModel(name="m2m_second")
        second_m2m_model.save()
        tm.many_to_many.add(second_m2m_model)
        self.assertEqual(tm.get_dirty_fields(), {
                'many_to_many': set([m2m_model.pk]) })
        tm.save()