def test_exerciselog_collision(self): # create a new exercise log with the same exercise_id and user, but different points/attempts exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user) exerciselog.points = self.NEW_POINTS exerciselog.attempts = self.NEW_ATTEMPTS # try saving the new ExerciseLog: this is where the collision will happen, hopefully leading to a merge exerciselog.save() # get a new reference to the existing ExerciseLog exerciselog2 = ExerciseLog.objects.get(id=self.original_exerciselog.id) # make sure the ExerciseLog has been properly merged self.assertEqual(exerciselog.points, max(self.ORIGINAL_POINTS, self.NEW_POINTS), "The ExerciseLog's points were not properly merged.") self.assertEqual(exerciselog.attempts, max(self.ORIGINAL_ATTEMPTS, self.NEW_ATTEMPTS), "The ExerciseLog's attempts have already changed.")