def test_save_new_specialization(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Specialization() to_save.capacity = 92 to_save.name = "new specialization" to_save.identifier = 1 result = dbc.save_specialization(to_save) saved = dbc.get_specialization_by_id(1) self.assertEqual(to_save.to_xml(), saved.to_xml()) self.assertEqual('OK', result)
def test_save_specialization_no_id(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Specialization() to_save.name = 'No id' to_save.capacity = 92 result = dbc.save_specialization(to_save) found = dbc.get_specialization_by_id(-1) self.assertEqual('OK', result) self.assertEqual(to_save.to_xml(), found.to_xml()) found.print()
def test_delete_specialization_by_id(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save1 = dbc.Specialization() to_save1.capacity = 11 to_save1.name = "new specialization 1" to_save1.identifier = 1 to_save2 = dbc.Specialization() to_save2.capacity = 22 to_save2.name = "new specialization 2" to_save2.identifier = 2 dbc.save_specialization(to_save1) dbc.save_specialization(to_save2) dbc.delete_specialization_by_id(2) found1 = dbc.get_specialization_by_id(1) found2 = dbc.get_specialization_by_id(2) self.assertEqual(to_save1.to_xml(), found1.to_xml()) self.assertEqual(None, found2)
def test_save_specialization_incorrect_data(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Specialization() to_save.identifier = 1 to_save.name = 4567 to_save.capacity = 'Incorrect capacity' result = dbc.save_specialization(to_save) found = dbc.get_specialization_by_id(1) self.assertEqual('OK', result) self.assertEqual(to_save.to_xml(), found.to_xml()) found.print()
def test_update_specialization_not_found(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() original = dbc.Specialization() original.capacity = 11 original.name = "new specialization 1" original.identifier = 1 dbc.save_specialization(original) updated = dbc.Specialization() updated.capacity = 21 updated.name = "updated specialization 1" updated.identifier = 2 result = dbc.update_specialization(updated) found = dbc.get_specialization_by_id(1) self.assertEqual(original.to_xml(), found.to_xml()) self.assertEqual('Entry not found', result)