Ejemplo n.º 1
0
 def test_table_save_changed_records_success(self):
     """Test save_changed_records. """
     record_dict = {
         'testitema': 'a1',
         'testitemb': 'b1',
         'testitemc': 'c1',
         'value': '10,000'
     }
     r = TestData()
     r.set_fk_labels_objects()
     r.set_from_record_dict(record_dict)
     # First test modifying an existing record
     t = AssessTable(TestData, "")
     t.load(False, [])
     t.changed_records = {r.get_key(): r}
     t.save_changed_records(t.changed_records)
     t = AssessTable(TestData, "proposed")
     # Load proposed records
     t.load(False, [])
     self.assertEqual(t.records[r.get_key()], r)
     # Then delete the old (id=1) new record (id=13) and insert it to test insertion as well
     TestData.objects.filter(id=1).delete()
     TestData.objects.filter(id=13).delete()
     t.load(False, [])
     t.changed_records = {r.get_key(): r}
     t.save_changed_records(t.changed_records)
     t = AssessTable(TestData, "proposed")
     # Load proposed records
     t.load(False, [])
     self.assertEqual(t.records[r.get_key()].value, r.value)
Ejemplo n.º 2
0
 def test_table_save_changed_records_failure(self):
     """Test save_changed_records. """
     # First test modifying an existing record
     t = AssessTable(TestData, "")
     t.load(False, [])
     r = TestData.objects.get(id=1)
     r.value = "bad_decimal_value"
     t.changed_records = {r.get_key(): r}
     try:
         t.save_changed_records(t.changed_records)
     except NotCleanRecord as e1:
         r2 = TestData.objects.get(id=1)
         r2.value = "bad_decimal_value"
         try:
             r2.full_clean()
         except ValidationError as e3:
             self.assertEqual(str(e1), str(NotCleanRecord(r, e3)))