'Ensure that an existing document is updated instead of be
overwritten.'

def test_update(self):

    person = self.Person(name='Test    User', age=30)
    person.save()
    same_person = self.Person(name='Test')
    same_person.id = person.id
    same_person.save()
    self.assertEqual(self.Person.objects.count(), 1)
    person.reload()
    same_person.reload()
    self.assertEqual(person, same_person)
    self.assertEqual(person.name, same_person.name)
    self.assertEqual(person.age, same_person.age)
    self.assertEqual(person.name, 'Test')
    self.assertEqual(person.age, 30)
    person = self.Person.objects.only('name').get()
    person.name = 'User'
    person.save()
    person.reload()
    self.assertEqual(person.name, 'User')
    self.assertEqual(person.age, 30)
    person = self.Person.objects.exclude('name').get()
    person.age = 21
    person.save()
    person.reload()
    self.assertEqual(person.name, 'User')
    self.assertEqual(person.age, 21)
    person = self.Person.objects.only('name').get()
    person.name = 'Test'
    person.age = 30
    person.save()
    person.reload()
    self.assertEqual(person.name, 'Test')
    self.assertEqual(person.age, 30)
    person = self.Person.objects.exclude('name').get()
    person.name = 'User'
    person.age = 21
    person.save()
    person.reload()
    self.assertEqual(person.name, 'User')
    self.assertEqual(person.age, 21)
    person = self.Person.objects.exclude('name').get()
    person.age = None
    person.save()
    person.reload()
    self.assertEqual(person.name, 'User')
    self.assertEqual(person.age, None)
    person = self.Person.objects.get()
    person.name = None
    person.age = None
    person.save()
    person.reload()
    self.assertEqual(person.name, None)
    self.assertEqual(person.age, None)
