Beispiel #1
0
 def test_unchanged_data(self):
     """
     Test to determine if correct value is generated if a field has not changed.
     """
     from django_contenthistory.handlers import BaseHistoryHandler
     
     handler = BaseHistoryHandler(ContentType.objects.get_for_model(User))
     current_user = User(username = '******')
     final_user = User(username = '******')
     target_field = ModelField(name = 'username', mode = ModelField.TEXT, content = self.tracked_content)
     target_field.save()
     created, object_id, data, modified = handler.get_data(current_user, final_user)
     self.assertFalse(modified)
     self.assertFalse(created)
     target_field.delete()
Beispiel #2
0
 def test_associate_revision_fields(self):
     """
     Determines if the correct fields are being associated correctly with an edit.
     """
     target_field = ModelField(name = 'username', mode = ModelField.TEXT, content = self.tracked_content)
     target_field.save()
     model_history = ModelHistory(object_id = self.test_user.id, 
                                  content_type = ContentType.objects.get_for_model(User),
                                  created = False,
                                  data = json.dumps({'username':'******'}),
                                  user = self.test_user)
     final_edit = utils.associate_revision_fields(model_history)
     self.assertTrue(final_edit.fields)
     self.assertEqual(final_edit.fields[0]['name'], 'username')
     self.assertEqual(final_edit.fields[0]['content'], 'hanbox')
     target_field.delete()
Beispiel #3
0
 def test_base_handler(self):
     """
     Tests the standard handler for data handling and tracked content
     registration.
     """
     from django_contenthistory.handlers import BaseHistoryHandler
     
     handler = BaseHistoryHandler(ContentType.objects.get_for_model(User))
     current_user = User(username = '******')
     final_user = User(username = '******')
     target_field = ModelField(name = 'username', mode = ModelField.TEXT, content = self.tracked_content)
     target_field.save()
     created, object_id, data, modified = handler.get_data(current_user, final_user)
     self.assertTrue(modified)
     self.assertFalse(created)
     self.assertEqual(json.loads(data).get('username'), utils.generate_diff('genghisu', 'hanbox'))
     target_field.delete()