def test_nothing_changing(self): tm = TestModel() tm.boolean = False tm.characters = 'testing' tm.save() self.assertFalse(tm.save_stale())
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())
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(), {})
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_dirty_fields(self): tm = TestModel() # initial state shouldn't be dirty self.assertEqual(tm.dirty_fields, tuple()) # changing values should flag them as dirty tm.boolean = False tm.characters = 'testing' self.assertEqual(set(tm.dirty_fields), set(('boolean', 'characters'))) # resetting them to original values should unflag tm.boolean = True self.assertEqual(tm.dirty_fields, ('characters', ))
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', ))
def test_dirty_fields(self): tm = TestModel() # initial state shouldn't be dirty self.assertEqual(tm.get_dirty_fields(), {}) # changing values should flag them as dirty tm.boolean = False tm.characters = 'testing' self.assertEqual(tm.get_dirty_fields(), { 'boolean': True, 'characters': '' }) # resetting them to original values should unflag tm.boolean = True self.assertEqual(tm.get_dirty_fields(), {'characters': ''})
def test_dirty_fields(self): tm = TestModel() # initial state shouldn't be dirty self.assertEqual(tm.get_dirty_fields(), {}) # changing values should flag them as dirty tm.boolean = False tm.characters = 'testing' self.assertEqual(tm.get_dirty_fields(), { 'boolean': True, 'characters': '' }) # resetting them to original values should unflag tm.boolean = True self.assertEqual(tm.get_dirty_fields(), { 'characters': '' })
def test_dirty_fields(self): tm = TestModel() # initial state shouldn't be dirty self.assertEqual(tm.get_dirty_fields(), {}) # changing values should flag them as dirty tm.boolean = False tm.characters = 'testing' self.assertEqual(tm.get_dirty_fields(), { 'boolean': True, 'characters': '' }) changes = get_changes(tm) self.assertEqual(changes['boolean']['existing'], True) self.assertEqual(changes['boolean']['new'], False) self.assertEqual(changes['characters']['existing'], '') self.assertEqual(changes['characters']['new'], 'testing')