Beispiel #1
0
    def test_delete_class(self):
        model = UMLModel()
        model.create_class("class1")
        model.create_class("class2")

        # create relationship between classes
        model.create_relationship("composition", "class1", "class2")
        # Ensure relationship is created
        self.assertTrue(model.classes["class1"].has_relationship("class2"))
        self.assertTrue(model.classes["class2"].has_relationship("class1"))

        # Ensure deleted
        model.delete_class("class1")
        # assert dictionary key was removed
        self.assertTrue("class1" not in model.classes)

        # Ensure relationship was removed after deletion of class1
        status, msg = model.list_relationships("class2")
        self.assertTrue(status)
        self.assertEqual(msg, "Class 'class2' has no relationships")
        
        # Ensure no errors when class DNE
        status, msg = model.delete_class("class1")
        # ensure it failed
        self.assertFalse(status)
        self.assertEqual(msg, "class1 does not exist.")
Beispiel #2
0
    def test_list_relationships(self):
        model = UMLModel()
        model.create_class("class1")
        model.create_class("class2")

        # variables used for testing equality
        message = model.list_relationships("class5")[1]
        # test output equality with using a non-existent class name
        self.assertEqual(message, "class5 does not exist")
        
        # test with a parameter
        # variables used for testing equality
        message = model.list_relationships('class1')[1]
        # test output equality without creating a relationship
        self.assertEqual(message, "Class 'class1' has no relationships")

        # test without a parameter
        # variables used for testing equality
        message = model.list_relationships()[1]
        # test output equality without creating a relationship
        self.assertEqual(message, "No relationships exist for the current model")

        # create a relationship between the classes
        model.create_relationship("inheritance", "class1", "class2")

        # test with a parameter
        message = model.list_relationships("class1")[1]
        # test output equality
        outString = "".join(("Relationships for class1\n",
                             "class1 ---------> class2"))
        self.assertEqual(message, outString)

        # test without a parameter
        # variables used for testing equality
        message = model.list_relationships()[1]
        outString = "".join(("Listing all relationships\n",
                             "class1 ---------> class2\n",
                             "class2 <--------- class1"))
        # test output equality            
        self.assertEqual(message,outString)