def test_list_fields(self): model = UMLModel() model.create_class("class1") # variables used for testing equality message = model.list_fields("class3")[1] # test output equality with a non-existent class self.assertEqual(message, "class3 is not a class") # variables used for testing equality message = model.list_fields("class1")[1] # test output equality without inserting fields self.assertEqual(message, "Class 'class1' has no fields") # add some fields to class1 model.create_field("class1", "public", "int", "year") model.create_field("class1", "private", "int", "salary") model.create_field("class1", "protected", "string", "SSN") # variables used for testing equality message = model.list_fields("class1")[1] outString = "".join(("Fields of class1\n", "PUBLIC int year\n", "PRIVATE int salary\n", "PROTECTED string SSN")) # test output equality self.assertEqual(message,outString)
def test_set_data(self): model = UMLModel() # Test 1: set model data newData = { "class1" : { "name" : "class1", "fields" : [{ "visibility" : 'private', 'type' : 'string', 'name' : 'name' }], "methods" : [], "relationships" : [], "x" : 200, "y" : 0, "zindex" : 0 }, "class2" : { "name" : "class2", "fields" : [], "methods" : [], "relationships" : [], "x" : 200, "y" : 0, "zindex" : 0 } } status, msg = model.set_data(newData) self.assertTrue(status) # ensure each piece was copied in correctly # ensure classes were created self.assertTrue("class1" in model.classes) self.assertTrue("class2" in model.classes) status, msg = model.list_fields("class1") self.assertEqual(msg, "Fields of class1\nPRIVATE string name") # Test 2: invalid data badData = { "class1" : "somethings not right here..." } status, msg = model.set_data(badData) # ensure it failed self.assertFalse(status) self.assertEqual(msg, "Data cannot be parsed") # ensure previous model is still there self.assertTrue("class1" in model.classes) self.assertTrue("class2" in model.classes) status, msg = model.list_fields("class1") self.assertEqual(msg, "Fields of class1\nPRIVATE string name") # Test 3: invalid data - type error badData = { "class1" : { "name" : "class1", "fields": [7] } } status, msg = model.set_data(badData) print(model.list_class("class1")) # ensure it failed self.assertFalse(status) self.assertEqual(msg, "Data cannot be parsed") # ensure previous model is still there self.assertTrue("class1" in model.classes) self.assertTrue("class2" in model.classes) status, msg = model.list_fields("class1") self.assertEqual(msg, "Fields of class1\nPRIVATE string name")