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

        self.assertFalse(tm.save_stale())
示例#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())
示例#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(), {})
示例#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)), {})
示例#5
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(), {})
示例#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)), {})
示例#7
0
    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', ))
示例#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', ))
示例#9
0
    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': ''})
示例#10
0
    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': ''
        })
示例#11
0
    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')