def test_list_class(self): model = UMLModel() model.create_class("class1") model.create_class("class2") model.create_class("class3") # variables used for testing equality message = model.list_class("class5")[1] # test output equality while using the wrong class name self.assertEqual(message, "'class5' is not a valid class") # add fields to class1 model.create_field("class1", "public", "void", "a1") model.create_field("class1", "private", "int", "size") # add methods to class1 along with some parameters model.create_method("class1", "protected", "void", "setSpeed") model.create_method("class1", "public", "void", "walk") model.create_parameter("class1", "setSpeed", "int", "speed") model.create_parameter("class1", "walk", "int", "speed") model.create_parameter("class1", "walk", "double", "direction") # add relationships to class1 model.create_relationship("inheritance", "class1", "class2") model.create_relationship("aggregation", "class3", "class1") # variables used for testing equality message = model.list_class("class1")[1] outString = "".join(("Class: class1\n", "=== Fields ======================\n", "public a1: void\n", "private size: int\n", "=== Methods =====================\n", "protected setSpeed(int speed): void\n", "public walk(int speed, double direction): void\n", "=== Relationships ===============\n", "class1 ---------> class2\n", "class1 <<>>------ class3\n", "=================================")) # 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")