def test_count_proposed(self): """Test count proposed functionality.""" # In our setup, we have 12 records self.assertEqual(TestData.objects.count(), 12) # Then add one proposed record - we now have 13 t = AssessTable(TestData, "") t.load(False, []) POST = { "('a1', 'b1', 'c1', 'value')": '99', } t.save_POST(POST) self.assertEqual(t.count_db_records('proposed', changes=True), 1)
def test_revert_proposed(self): """Test revert table functionality.""" # In our setup, we have 12 records self.assertEqual(TestData.objects.count(), 12) # Then add one proposed record - we now have 13 t = AssessTable(TestData, "") t.load(False, []) POST = { "('a1', 'b1', 'c1', 'value')": '99', } t.save_POST(POST) self.assertEqual(TestData.objects.count(), 13) # Then revert the new proposed record, now we're back to 12 again t.revert_proposed() self.assertEqual(TestData.objects.count(), 12)
def test_table_save_POST_success(self): """Test saving data using POST edit method.""" t = AssessTable(TestData, "") t.load(False, []) POST = { "('a1', 'b1', 'c1', 'value')": '10', "('a1', 'b1', 'c2', 'value')": '11', } t.save_POST(POST) # Test no errors and that other records were unchanged self.assertEqual(t.errors, []) self.assertEqual(t.records[('a1', 'b2', 'c1', 'value')].get_value(), '3,000') # Load proposed and test that the changes took effect t = AssessTable(TestData, "proposed") t.load(False, []) self.assertEqual(t.records[('a1', 'b1', 'c1', 'value')].get_value(), '10,000') self.assertEqual(t.records[('a1', 'b1', 'c2', 'value')].get_value(), '11,000')
def test_table_commit_success(self): """Test saving data using POST edit method.""" t = AssessTable(TestData, "") t.load(False, []) POST = { "('a1', 'b1', 'c1', 'value')": '10', "('a1', 'b1', 'c2', 'value')": '11', } t.save_POST(POST) # Test no errors and that other records were unchanged self.assertEqual(t.errors, []) self.assertEqual(t.records[('a1', 'b2', 'c1', 'value')].value, Decimal('3')) # Load proposed and test that the changes took effect version_info = {'label': 'new', 'user': '******', 'note': 'haha'} t.commit_rows(version_info) t.load(False, []) self.assertEqual(t.records[('a1', 'b1', 'c1', 'value')].value, Decimal('10')) self.assertEqual(t.records[('a1', 'b1', 'c2', 'value')].value, Decimal('11'))
def test_table_save_POST_failure(self): """Test failure when saving data using POST edit method.""" t = AssessTable(TestData, "") t.load(False, []) # Test bad decimal POST = {"('a1', 'b1', 'c1', 'value')": 'bad_decimal'} t.save_POST(POST) self.assertEqual(str(t.errors.pop()), str(NotDecimalError('bad_decimal', TestData))) self.assertEqual(t.records[('a1', 'b1', 'c1', 'value')].get_value(), '1,000') # Test bad POST key - item label POST = {"('bad_item', 'b1', 'c1', 'value')": '1'} t.save_POST(POST) self.assertEqual( str(t.errors.pop()), str( KeyNotFound("bad_item in ('bad_item', 'b1', 'c1', 'value')", TestData))) self.assertEqual(t.records[('a1', 'b1', 'c1', 'value')].get_value(), '1,000') # Test bad value field POST = {"('a1', 'b1', 'c1', 'bad_value_field')": '1'} t.save_POST(POST) self.assertEqual(str(t.errors.pop()), str(NoFieldError('bad_value_field', TestData))) self.assertEqual(t.records[('a1', 'b1', 'c1', 'value')].get_value(), '1,000')