Пример #1
0
 def test_addition_parameter_write_out(self):
     """Check that additional parameters are correctly stored"""
     
     result = _audit_model(self.profile, dict(foo=None), dict(foo='bar'))
     
     assert_not_equal(result, None,
                      "A change should result in a database object being "
                      "created")
     
     saved_record = self.fetch_record_by_id(result)
Пример #2
0
 def test_no_changes_same_values(self):
     """Check that passing two identical dicts results in a no-op"""
     
     result = _audit_model(self.profile,
                          {'foo': 1, 'bar': 'wibble', 'empty': None,
                            'my_date': datetime(2001, 1, 1, 9, 12)},
                          {'foo': 1, 'bar': 'wibble', 'empty': None,
                            'my_date': datetime(2001, 1, 1, 9, 12)})
     
     eq_(result, None, "No changes should not result in anything being "
         "written to the database")
Пример #3
0
 def test_single_change_no_other_diff(self):
     """Check that a single changed value is correctly recorded"""
     
     result = _audit_model(self.profile, dict(foo=None), dict(foo='bar'))
     
     assert_not_equal(result, None,
                      "A change should result in a database object being "
                      "created")
     
     saved_record = self.fetch_record_by_id(result)
     
     eq_(saved_record['foo'], 'bar',
         "The saved record should contain a single difference key")
Пример #4
0
 def test_model_data_write_out(self):
     """Check the correct data is written out for the model"""
     
     result = _audit_model(self.profile, dict(foo=None), dict(foo='bar'))
     
     assert_not_equal(result, None,
                      "A change should result in a database object being "
                      "created")
     
     saved_record = self.fetch_record_by_id(result)
     
     eq_(saved_record['object_app'], self.profile._meta.app_label)
     eq_(saved_record['object_model'], self.profile._meta.object_name)
     eq_(saved_record['object_pk'], self.profile.pk)
Пример #5
0
 def test_multi_change_no_others(self):
     """Check that multiple changed values are correctly recorded when there are no other items"""
     
     result = _audit_model(self.profile, dict(foo=None, wibble=0),
                          dict(foo='bar', wibble=1))
     
     assert_not_equal(result, None,
                      "A change should result in a database object being "
                      "created")
     
     saved_record = self.fetch_record_by_id(result)
     
     eq_(saved_record['foo'], 'bar',
         "The saved record should contain a difference for key `foo`")
     
     eq_(saved_record['wibble'], 1,
         "The saved record should contain a difference for key `wibble`")
Пример #6
0
 def test_single_change_others_same(self):
     """Check that a single changed value is correctly recorded when there are no other differences"""
     
     result = _audit_model(self.profile, dict(foo=None, wibble=0),
                          dict(foo='bar', wibble=0))
     
     assert_not_equal(result, None,
                      "A change should result in a database object being "
                      "created")
     
     saved_record = self.fetch_record_by_id(result)
     
     eq_(saved_record['foo'], 'bar',
         "The saved record should contain a single difference key")
     
     ok_('wibble' not in saved_record, "There should be no "
         "record of changes to the `wibble` key")
Пример #7
0
 def test_date_stamping(self):
     """Check that a date stamp is stored in along with the record"""
     
     result = _audit_model(self.profile, dict(foo=None), dict(foo='bar'))
     
     assert_not_equal(result, None,
                      "A change should result in a database object being "
                      "created")
     
     saved_record = self.fetch_record_by_id(result)
     
     record_date_stamp = saved_record['audit_date_stamp']
     
     now = datetime.utcnow()
     
     ok_((now - timedelta(seconds=1)) < record_date_stamp < now,
         "Date stamp should be almost the same as now (now: %s, got: %s"
         % (now, record_date_stamp))
Пример #8
0
 def test_multi_change_others_same(self):
     """Check that multiple changed values are correctly recorded when there are no other differences"""
     
     result = _audit_model(self.profile, dict(foo=None, wibble=0, body_count=1.00),
                          dict(foo='bar', wibble=1, body_count=1.00))
     
     assert_not_equal(result, None,
                      "A change should result in a database object being "
                      "created")
     
     saved_record = self.fetch_record_by_id(result)
     
     eq_(saved_record['foo'], 'bar',
         "The saved record should contain a difference for key `foo`")
     
     eq_(saved_record['wibble'], 1,
         "The saved record should contain a difference for key `wibble`")
     
     ok_('body_count' not in saved_record, "There should be no "
         "record of changes to the `body_count` key")
Пример #9
0
 def test_no_changes_empty_dicts(self):
     """Check that passing two empty value dicts results in a no-op"""
     result = _audit_model(self.profile, {}, {})
     
     eq_(result, None, "No changes should not result in anything being "
         "written to the database")