Exemplo n.º 1
0
    def test_delete_one_to_n_links(self):
        self.c1.association(self.c2, "l: 0..1 -> *")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c1, "o2")
        o3 = CObject(self.c2, "o3")
        o4 = CObject(self.c2, "o4")
        o5 = CObject(self.c2, "o5")

        add_links({o1: [o3, o4], o2: [o5]})
        o4.delete_links([o1])
        eq_(o1.linked, [o3])
        eq_(o2.linked, [o5])
        eq_(o3.linked, [o1])
        eq_(o4.linked, [])
        eq_(o5.linked, [o2])

        o4.add_links([o2])
        eq_(o2.linked, [o5, o4])
        delete_links({o1: o3, o2: o2.linked})
        eq_(o1.linked, [])
        eq_(o2.linked, [])
        eq_(o3.linked, [])
        eq_(o4.linked, [])
        eq_(o5.linked, [])
Exemplo n.º 2
0
    def test_add_one_to_one_link(self):
        self.m1.association(self.m2, "l: 1 -> [target] 0..1")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m2, "c2")
        c3 = CClass(self.m2, "c3")

        eq_(c1.linked, [])

        add_links({c1: c3})
        eq_(c1.linked, [c3])
        eq_(c3.linked, [c1])

        set_links({c1: []}, role_name="target")
        eq_(c1.linked, [])

        c1.add_links(c2)
        eq_(c1.linked, [c2])
        eq_(c2.linked, [c1])

        try:
            add_links({c1: c3})
            exception_expected_()
        except CException as e:
            eq_(e.value, "links of object 'c1' have wrong multiplicity '2': should be '0..1'")
        eq_(c1.linked, [c2])
        eq_(c2.linked, [c1])
        eq_(c3.linked, [])
Exemplo n.º 3
0
    def test_get_links_self_link(self):
        a1 = self.m1.association(self.m1, role_name="to", source_role_name="from",
                                 source_multiplicity="*", multiplicity="*")
        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m1, "c2")
        c3 = CClass(self.m1, "c3")
        c4 = CClass(self.m1, "c4")

        set_links({c1: [c2, c3, c1]})
        add_links({c4: [c1, c3]})
        link1 = c1.links[0]
        link2 = [o for o in c1.links if o.association == a1][0]
        link3 = [o for o in c1.links if o.role_name == "to"][0]
        link4 = [o for o in c1.links if o.source_role_name == "from"][0]
        eq_(link1, link2)
        eq_(link1, link3)
        eq_(link1, link4)
        eq_(link1.association, a1)
        eq_(link1.source, c1)
        eq_(link1.target, c2)

        eq_(len(c1.links), 4)
        eq_(len(c2.links), 1)
        eq_(len(c3.links), 2)
        eq_(len(c4.links), 2)
Exemplo n.º 4
0
    def test_delete_n_to_n_links(self):
        self.c1.association(self.c2, "l: * -> *")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c1, "o2")
        o3 = CObject(self.c2, "o3")
        o4 = CObject(self.c2, "o4")
        o5 = CObject(self.c2, "o5")
        o6 = CObject(self.c2, "o6")

        add_links({o1: [o3, o4], o2: [o4, o5]})
        o4.delete_links([o1, o2])
        eq_(o1.linked, [o3])
        eq_(o2.linked, [o5])
        eq_(o3.linked, [o1])
        eq_(o4.linked, [])
        eq_(o5.linked, [o2])

        add_links({o4: [o1, o2], o6: [o2, o1]})
        delete_links({o1: o6, o2: [o4, o5]})
        eq_(o1.linked, [o3, o4])
        eq_(o2.linked, [o6])
        eq_(o3.linked, [o1])
        eq_(o4.linked, [o1])
        eq_(o5.linked, [])
        eq_(o6.linked, [o2])
Exemplo n.º 5
0
    def test_add_links_one_to_n_link(self):
        self.m1.association(self.m2, name="l")
        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m2, "c2")
        c3 = CClass(self.m2, "c3")
        c4 = CClass(self.m2, "c4")
        c5 = CClass(self.m2, "c5")
        c6 = CClass(self.m2, "c6")

        add_links({c1: [c2, c3]})
        eq_(c1.linked, [c2, c3])
        eq_(c2.linked, [c1])
        eq_(c3.linked, [c1])
        add_links({c1: c4})
        eq_(c1.linked, [c2, c3, c4])
        eq_(c2.linked, [c1])
        eq_(c3.linked, [c1])
        eq_(c4.linked, [c1])
        c1.add_links([c5, c6])
        eq_(c1.linked, [c2, c3, c4, c5, c6])
        eq_(c2.linked, [c1])
        eq_(c3.linked, [c1])
        eq_(c4.linked, [c1])
        eq_(c5.linked, [c1])
        eq_(c6.linked, [c1])
Exemplo n.º 6
0
    def test_delete_link_no_matching_link(self):
        a = self.m1.association(self.m2, "l: 0..1 -> *")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m1, "c2")
        c3 = CClass(self.m2, "c3")
        c4 = CClass(self.m2, "c4")
        c5 = CClass(self.m2, "c5")

        add_links({c1: [c3, c4], c2: [c5]}, association=a)

        try:
            delete_links({c1: c5})
            exception_expected_()
        except CException as e:
            eq_(e.value, "no link found for 'c1 -> c5' in delete links")

        b = self.m1.association(self.m2, "l: 0..1 -> *")
        try:
            delete_links({c1: c5})
            exception_expected_()
        except CException as e:
            eq_(e.value, "no link found for 'c1 -> c5' in delete links")

        try:
            c4.delete_links([c1], association=b)
            exception_expected_()
        except CException as e:
            eq_(e.value, "no link found for 'c4 -> c1' in delete links for given association")
Exemplo n.º 7
0
    def test_delete_link_no_matching_link(self):
        a = self.c1.association(self.c2, "l: 0..1 -> *")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c1, "o2")
        o3 = CObject(self.c2, "o3")
        o4 = CObject(self.c2, "o4")
        o5 = CObject(self.c2, "o5")

        add_links({o1: [o3, o4], o2: [o5]}, association=a)

        try:
            delete_links({o1: o5})
            exception_expected_()
        except CException as e:
            eq_(e.value, "no link found for 'o1 -> o5' in delete links")

        b = self.c1.association(self.c2, "l: 0..1 -> *")
        try:
            delete_links({o1: o5})
            exception_expected_()
        except CException as e:
            eq_(e.value, "no link found for 'o1 -> o5' in delete links")

        try:
            o4.delete_links([o1], association=b)
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "no link found for 'o4 -> o1' in delete links for given association"
            )
Exemplo n.º 8
0
    def test_delete_n_to_n_links(self):
        self.m1.association(self.m2, "l: * -> *")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m1, "c2")
        c3 = CClass(self.m2, "c3")
        c4 = CClass(self.m2, "c4")
        c5 = CClass(self.m2, "c5")
        c6 = CClass(self.m2, "c6")

        add_links({c1: [c3, c4], c2: [c4, c5]})
        c4.delete_links([c1, c2])
        eq_(c1.linked, [c3])
        eq_(c2.linked, [c5])
        eq_(c3.linked, [c1])
        eq_(c4.linked, [])
        eq_(c5.linked, [c2])

        add_links({c4: [c1, c2], c6: [c2, c1]})
        delete_links({c1: c6, c2: [c4, c5]})
        eq_(c1.linked, [c3, c4])
        eq_(c2.linked, [c6])
        eq_(c3.linked, [c1])
        eq_(c4.linked, [c1])
        eq_(c5.linked, [])
        eq_(c6.linked, [c2])
Exemplo n.º 9
0
    def test_add_one_to_one_link(self):
        self.c1.association(self.c2, "l: 1 -> [target] 0..1")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c2, "o2")
        o3 = CObject(self.c2, "o3")

        eq_(o1.linked, [])

        add_links({o1: o3})
        eq_(o1.linked, [o3])
        eq_(o3.linked, [o1])

        set_links({o1: []}, role_name="target")
        eq_(o1.linked, [])

        o1.add_links(o2)
        eq_(o1.linked, [o2])
        eq_(o2.linked, [o1])

        try:
            add_links({o1: o3})
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "links of object 'o1' have wrong multiplicity '2': should be '0..1'"
            )
        eq_(o1.linked, [o2])
        eq_(o2.linked, [o1])
        eq_(o3.linked, [])
Exemplo n.º 10
0
    def test_delete_one_to_n_links(self):
        self.m1.association(self.m2, "l: 0..1 -> *")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m1, "c2")
        c3 = CClass(self.m2, "c3")
        c4 = CClass(self.m2, "c4")
        c5 = CClass(self.m2, "c5")

        add_links({c1: [c3, c4], c2: [c5]})
        c4.delete_links([c1])
        eq_(c1.linked, [c3])
        eq_(c2.linked, [c5])
        eq_(c3.linked, [c1])
        eq_(c4.linked, [])
        eq_(c5.linked, [c2])

        c4.add_links([c2])
        eq_(c2.linked, [c5, c4])
        delete_links({c1: c3, c2: c2.linked})
        eq_(c1.linked, [])
        eq_(c2.linked, [])
        eq_(c3.linked, [])
        eq_(c4.linked, [])
        eq_(c5.linked, [])
Exemplo n.º 11
0
    def test_add_links_one_to_n_link(self):
        self.c1.association(self.c2, name="l")
        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c2, "o2")
        o3 = CObject(self.c2, "o3")
        o4 = CObject(self.c2, "o4")
        o5 = CObject(self.c2, "o5")
        o6 = CObject(self.c2, "o6")

        add_links({o1: [o2, o3]})
        eq_(o1.linked, [o2, o3])
        eq_(o2.linked, [o1])
        eq_(o3.linked, [o1])
        add_links({o1: o4})
        eq_(o1.linked, [o2, o3, o4])
        eq_(o2.linked, [o1])
        eq_(o3.linked, [o1])
        eq_(o4.linked, [o1])
        o1.add_links([o5, o6])
        eq_(o1.linked, [o2, o3, o4, o5, o6])
        eq_(o2.linked, [o1])
        eq_(o3.linked, [o1])
        eq_(o4.linked, [o1])
        eq_(o5.linked, [o1])
        eq_(o6.linked, [o1])
Exemplo n.º 12
0
    def test_delete_link_select_by_association(self):
        a = self.c1.association(self.c2, "a: * -> *")
        b = self.c1.association(self.c2, "b: * -> *")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c1, "o2")
        o3 = CObject(self.c2, "o3")
        o4 = CObject(self.c2, "o4")

        add_links({o1: [o3], o2: [o3, o4]}, association=b)
        delete_links({o2: o3})
        eq_(o1.linked, [o3])
        eq_(o2.linked, [o4])
        eq_(o3.linked, [o1])
        eq_(o4.linked, [o2])
        add_links({o1: [o3], o2: [o3, o4]}, association=a)

        try:
            delete_links({o1: o3})
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "link definition in delete links ambiguous for link 'o1->o3': found multiple matches"
            )

        delete_links({o1: o3, o2: o4}, association=b)
        eq_(o1.linked, [o3])
        eq_(o2.linked, [o3, o4])
        eq_(o3.linked, [o1, o2])
        eq_(o4.linked, [o2])
        for o in [o1, o2, o3, o4]:
            for lo in o.links:
                eq_(lo.association, a)

        o1.add_links(o3, association=b)
        try:
            o1.delete_links(o3)
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "link definition in delete links ambiguous for link 'o1->o3': found multiple matches"
            )

        eq_(o1.linked, [o3, o3])
        eq_(o2.linked, [o3, o4])
        eq_(o3.linked, [o1, o2, o1])
        eq_(o4.linked, [o2])

        o1.delete_links(o3, association=a)
        eq_(o1.linked, [o3])
        eq_(o2.linked, [o3, o4])
        eq_(o3.linked, [o2, o1])
        eq_(o4.linked, [o2])
    def test_link_to_link(self):
        collection1 = CMetaclass("Collection1")
        collection2 = CMetaclass("Collection2")
        collections_association = collection1.association(collection2,
                                                          "element references: [references] * -> [referenced] *")
        type_a = CMetaclass("Type A", superclasses=collection1)
        type_b = CMetaclass("Type B", superclasses=collection1)
        a_b_association = type_a.association(type_b, "a_b: [type_a] * -> [type_b] *", superclasses=collection1)
        type_c = CMetaclass("Type C", superclasses=collection2)
        type_d = CMetaclass("Type D", superclasses=[collection1, collection2])
        c_d_association = type_c.association(type_d, "c_d: [type_c] * -> [type_d] *", superclasses=collection2)
        a_d_association = type_a.association(type_d, "a_d: [type_a] * -> [type_d] *",
                                             superclasses=[collection1, collection2])

        a1 = CClass(type_a, "a1")
        b1 = CClass(type_b, "b1")
        b2 = CClass(type_b, "b2")
        c1 = CClass(type_c, "c1")
        c2 = CClass(type_c, "c2")
        d1 = CClass(type_d, "d1")

        a_b_links = add_links({a1: [b1, b2]}, association=a_b_association)
        c_d_links = add_links({d1: [c1, c2]}, association=c_d_association)
        a_d_links = add_links({a1: [d1]}, association=a_d_association)

        references_links = add_links({a_b_links[0]: c_d_links[0],
                                      a_b_links[1]: [c1, c2, d1, c_d_links[1], c_d_links[0]],
                                      a_d_links[0]: [a_d_links[0], c_d_links[1], c1, d1]}, role_name="referenced")

        eq_(set(a_b_links[0].get_linked(role_name="referenced")),
            {c_d_links[0]})
        eq_(set(a_b_links[0].linked), {c_d_links[0]})
        eq_(set(a_b_links[0].links), {references_links[0]})
        eq_(set(a_b_links[0].get_links_for_association(collections_association)), {references_links[0]})
        eq_(set(get_links([a_b_links[0]])), {references_links[0]})

        eq_(set(a_b_links[1].get_linked(role_name="referenced")),
            {c1, c2, d1, c_d_links[1], c_d_links[0]})
        eq_(set(a_b_links[1].linked), {c1, c2, d1, c_d_links[1], c_d_links[0]})
        correct_links_set = {references_links[1], references_links[2], references_links[3], references_links[4],
                             references_links[5]}
        eq_(set(a_b_links[1].links), correct_links_set)
        eq_(set(a_b_links[1].get_links_for_association(collections_association)), correct_links_set)
        eq_(set(get_links([a_b_links[1]])), correct_links_set)

        eq_(set(a_d_links[0].get_linked(role_name="referenced")),
            {a_d_links[0], c_d_links[1], c1, d1})
        eq_(set(a_d_links[0].linked), {a_d_links[0], c_d_links[1], c1, d1})
        correct_links_set = {references_links[6], references_links[7], references_links[8], references_links[9]}
        eq_(set(a_d_links[0].links), correct_links_set)
        eq_(set(a_d_links[0].get_links_for_association(collections_association)), correct_links_set)
        eq_(set(get_links([a_d_links[0]])), correct_links_set)
Exemplo n.º 14
0
    def test_delete_one_to_one_link_wrong_multiplicity(self):
        self.m1.association(self.m2, "l: 1 -> [c2] 1")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m2, "c2")
        add_links({c1: c2})
        try:
            c1.delete_links(c2)
            exception_expected_()
        except CException as e:
            eq_(e.value, "links of object 'c1' have wrong multiplicity '0': should be '1'")
        eq_(c1.linked, [c2])
        eq_(c2.linked, [c1])
Exemplo n.º 15
0
 def test_wrong_types_add_links(self):
     self.c1.association(self.c2, name="l", multiplicity="1")
     o1 = CObject(self.c1, "o1")
     o2 = CObject(self.c2, "o2")
     try:
         add_links({o1: self.mcl})
         exception_expected_()
     except CException as e:
         eq_(e.value, "link target 'MCL' is not an object, class, or link")
     try:
         o1.add_links([o2, self.mcl])
         exception_expected_()
     except CException as e:
         eq_(e.value, "link target 'MCL' is not an object, class, or link")
Exemplo n.º 16
0
 def test_wrong_types_add_links(self):
     self.m1.association(self.m2, name="l", multiplicity="1")
     c1 = CClass(self.m1, "c1")
     c2 = CClass(self.m2, "c2")
     try:
         add_links({c1: self.mcl})
         exception_expected_()
     except CException as e:
         eq_(e.value, "link target 'MCL' is not an object, class, or link")
     try:
         c1.add_links([c2, self.mcl])
         exception_expected_()
     except CException as e:
         eq_(e.value, "link target 'MCL' is not an object, class, or link")
Exemplo n.º 17
0
 def test_link_delete_object(self):
     self.c1.association(self.c2,
                         name="l",
                         source_multiplicity="*",
                         multiplicity="*")
     o1 = CObject(self.c1, "o2")
     o2 = CObject(self.c2, "o2")
     o3 = CObject(self.c2, "o3")
     o4 = CObject(self.c1, "o4")
     add_links({o1: [o2, o3]})
     add_links({o4: [o3, o2]})
     o2.delete()
     eq_(o1.linked, [o3])
     eq_(o3.linked, [o1, o4])
     eq_(o4.linked, [o3])
     try:
         add_links({o1: [o2]})
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot link to deleted target")
     try:
         add_links({o2: [o1]})
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot link to deleted source")
Exemplo n.º 18
0
    def test_delete_link_select_by_association(self):
        a = self.m1.association(self.m2, "a: * -> *")
        b = self.m1.association(self.m2, "b: * -> *")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m1, "c2")
        c3 = CClass(self.m2, "c3")
        c4 = CClass(self.m2, "c4")

        add_links({c1: [c3], c2: [c3, c4]}, association=b)
        delete_links({c2: c3})
        eq_(c1.linked, [c3])
        eq_(c2.linked, [c4])
        eq_(c3.linked, [c1])
        eq_(c4.linked, [c2])
        add_links({c1: [c3], c2: [c3, c4]}, association=a)

        try:
            delete_links({c1: c3})
            exception_expected_()
        except CException as e:
            eq_(e.value, "link definition in delete links ambiguous for link 'c1->c3': found multiple matches")

        delete_links({c1: c3, c2: c4}, association=b)
        eq_(c1.linked, [c3])
        eq_(c2.linked, [c3, c4])
        eq_(c3.linked, [c1, c2])
        eq_(c4.linked, [c2])
        for o in [c1, c2, c3, c4]:
            for lo in o.links:
                eq_(lo.association, a)

        c1.add_links(c3, association=b)
        try:
            c1.delete_links(c3)
            exception_expected_()
        except CException as e:
            eq_(e.value, "link definition in delete links ambiguous for link 'c1->c3': found multiple matches")

        eq_(c1.linked, [c3, c3])
        eq_(c2.linked, [c3, c4])
        eq_(c3.linked, [c1, c2, c1])
        eq_(c4.linked, [c2])

        c1.delete_links(c3, association=a)
        eq_(c1.linked, [c3])
        eq_(c2.linked, [c3, c4])
        eq_(c3.linked, [c2, c1])
        eq_(c4.linked, [c2])
    def create_simple_link_object_test_setup(self):
        self.a = CMetaclass("A")
        self.a1 = CMetaclass("A1", superclasses=self.a)
        self.a2 = CMetaclass("A2", superclasses=self.a)
        self.a_association = self.a1.association(self.a2, "[a1] * -> [a2] *", superclasses=self.a)
        self.b = CMetaclass("B")
        self.b_a_association = self.b.association(self.a, "[b] * -> [a] *")

        self.a1_1 = CClass(self.a1, "a1_1")
        self.a1_2 = CClass(self.a1, "a1_2")
        self.a2_1 = CClass(self.a2, "a2_1")
        self.b_1 = CClass(self.b, "b_1")
        self.a_links = add_links({self.a2_1: [self.a1_1, self.a1_2]}, association=self.a_association)

        self.b_a_links = add_links({self.b_1: [self.a_links[0], self.a_links[1]]}, association=self.b_a_association)
Exemplo n.º 20
0
    def test_add_links_with_inherited_common_classifiers(self):
        super_a = CMetaclass("SuperA")
        super_b = CMetaclass("SuperB")
        super_a.association(super_b, "[a] 1 -> [b] *")

        sub_b1 = CMetaclass("SubB1", superclasses=[super_b])
        sub_b2 = CMetaclass("SubB2", superclasses=[super_b])
        sub_a = CMetaclass("SubA", superclasses=[super_a])

        cl_a = CClass(sub_a, "a")
        cl_b1 = CClass(sub_b1, "b1")
        cl_b2 = CClass(sub_b2, "b2")

        add_links({cl_a: [cl_b1, cl_b2]}, role_name="b")
        eq_(set(cl_a.get_linked(role_name="b")), {cl_b1, cl_b2})
Exemplo n.º 21
0
    def test_add_links_multiple_links_in_definition(self):
        self.m1.association(self.m2, "[sourceRole1] * -> [role1] *")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m1, "c2")
        c3 = CClass(self.m1, "c3")
        c4 = CClass(self.m2, "c4")
        c5 = CClass(self.m2, "c5")

        add_links({c1: c4, c2: [c4], c5: [c1, c2, c3]})
        eq_(c1.get_linked(), [c4, c5])
        eq_(c2.get_linked(), [c4, c5])
        eq_(c3.get_linked(), [c5])
        eq_(c4.get_linked(), [c1, c2])
        eq_(c5.get_linked(), [c1, c2, c3])
Exemplo n.º 22
0
    def test_add_links_multiple_links_in_definition(self):
        self.c1.association(self.c2, "[sourceRole1] * -> [role1] *")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c1, "o2")
        o3 = CObject(self.c1, "o3")
        o4 = CObject(self.c2, "o4")
        o5 = CObject(self.c2, "o5")

        add_links({o1: o4, o2: [o4], o5: [o1, o2, o3]})
        eq_(o1.get_linked(), [o4, o5])
        eq_(o2.get_linked(), [o4, o5])
        eq_(o3.get_linked(), [o5])
        eq_(o4.get_linked(), [o1, o2])
        eq_(o5.get_linked(), [o1, o2, o3])
Exemplo n.º 23
0
    def test_add_links_with_inherited_common_classifiers(self):
        mcl = CMetaclass("MCL")
        super_a = CClass(mcl, "SuperA")
        super_b = CClass(mcl, "SuperB")
        super_a.association(super_b, "[a] 1 -> [b] *")

        sub_b1 = CClass(mcl, "SubB1", superclasses=[super_b])
        sub_b2 = CClass(mcl, "SubB2", superclasses=[super_b])
        sub_a = CClass(mcl, "SubA", superclasses=[super_a])

        obj_a = CObject(sub_a, "a")
        obj_b1 = CObject(sub_b1, "b1")
        obj_b2 = CObject(sub_b2, "b2")

        add_links({obj_a: [obj_b1, obj_b2]}, role_name="b")
        eq_(set(obj_a.get_linked(role_name="b")), {obj_b1, obj_b2})
Exemplo n.º 24
0
    def test_delete_one_to_one_link_wrong_multiplicity(self):
        self.c1.association(self.c2, "l: 1 -> [c2] 1")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c2, "o2")
        add_links({o1: o2})
        try:
            o1.delete_links(o2)
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "links of object 'o1' have wrong multiplicity '0': should be '1'"
            )
        eq_(o1.linked, [o2])
        eq_(o2.linked, [o1])
Exemplo n.º 25
0
    def test_delete_one_to_one_link(self):
        self.c1.association(self.c2, "l: 1 -> [c2] 0..1")

        o1 = CObject(self.c1, "o1")
        o2 = CObject(self.c2, "o2")
        o3 = CObject(self.c1, "o3")
        o4 = CObject(self.c2, "o4")

        links = add_links({o1: o2, o3: o4})
        o1.delete_links(o2)
        eq_(o1.linked, [])
        eq_(o2.linked, [])
        eq_(o3.linked, [o4])
        eq_(o4.linked, [o3])
        eq_(o1.links, [])
        eq_(o2.links, [])
        eq_(o3.links, [links[1]])
        eq_(o4.links, [links[1]])
        delete_links({o3: o4})
        eq_(o1.linked, [])
        eq_(o2.linked, [])
        eq_(o3.linked, [])
        eq_(o4.linked, [])
        eq_(o1.links, [])
        eq_(o2.links, [])
        eq_(o3.links, [])
        eq_(o4.links, [])
Exemplo n.º 26
0
    def test_delete_one_to_n_links_wrong_multiplicity(self):
        self.m1.association(self.m2, "l: 1 -> *")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m1, "c2")
        c3 = CClass(self.m2, "c3")
        c4 = CClass(self.m2, "c4")
        c5 = CClass(self.m2, "c5")

        add_links({c1: [c3, c4], c2: [c5]})

        try:
            c4.delete_links([c1])
            exception_expected_()
        except CException as e:
            eq_(e.value, "links of object 'c4' have wrong multiplicity '0': should be '1'")
Exemplo n.º 27
0
    def test_delete_one_to_one_link(self):
        self.m1.association(self.m2, "l: 1 -> [c2] 0..1")

        c1 = CClass(self.m1, "c1")
        c2 = CClass(self.m2, "c2")
        c3 = CClass(self.m1, "c3")
        c4 = CClass(self.m2, "c4")

        links = add_links({c1: c2, c3: c4})
        c1.delete_links(c2)
        eq_(c1.linked, [])
        eq_(c2.linked, [])
        eq_(c3.linked, [c4])
        eq_(c4.linked, [c3])
        eq_(c1.links, [])
        eq_(c2.links, [])
        eq_(c3.links, [links[1]])
        eq_(c4.links, [links[1]])
        delete_links({c3: c4})
        eq_(c1.linked, [])
        eq_(c2.linked, [])
        eq_(c3.linked, [])
        eq_(c4.linked, [])
        eq_(c1.links, [])
        eq_(c2.links, [])
        eq_(c3.links, [])
        eq_(c4.links, [])
Exemplo n.º 28
0
def place_order(a_cart):
    a_customer = a_cart.get_linked(role_name="customer")[0]

    # this assumes "today" is set to the current date and thus we
    # can just use the default value for those values.
    new_order = CObject(order,
                        values={
                            "id": get_order_id(),
                            "ship to": get_shipping_address(a_customer),
                            "total": calc_cart_total(a_cart)
                        })

    items = a_cart.get_linked(role_name="item in cart")
    add_links({new_order: items}, role_name="item in order")
    add_links({a_customer: new_order}, role_name="order")

    return new_order
    def test_link_association_has_a_compatible_superclass(self):
        code = CMetaclass("Code")

        source = CMetaclass("Source")
        code.association(source, "[contained_code] * -> [source] *")

        code_a = CMetaclass("Code A", superclasses=code)
        code_b = CMetaclass("Code B", superclasses=code)
        a_b_association = code_a.association(code_b, "a_b: [code_a] * -> [code_b] *")

        source_1 = CClass(source, "source_1")

        code_a1 = CClass(code_a, "code_a1")
        code_b1 = CClass(code_b, "code_b1")
        code_b2 = CClass(code_b, "code_b2")
        links = add_links({code_a1: [code_b1, code_b2]}, association=a_b_association)

        try:
            add_links({source_1: [code_a1, code_b2, code_b1, links[0], links[1]]},
                      role_name="contained_code")
            exception_expected_()
        except CException as e:
            eq_("the metaclass link's association is missing a compatible classifier", e.value)

        a_b_association.superclasses = self.mcl
        try:
            add_links({source_1: [code_a1, code_b2, code_b1, links[0], links[1]]},
                      role_name="contained_code")
            exception_expected_()
        except CException as e:
            eq_("no common metaclass for classes or links found", e.value)

        a_b_association.superclasses = code_b
        add_links({source_1: [code_a1, code_b2, code_b1, links[0], links[1]]},
                  role_name="contained_code")
 def test_add_stereotype_of_inherited_metaclass(self):
     sub1 = CMetaclass("Sub1", superclasses=self.m1)
     sub2 = CMetaclass("Sub2", superclasses=self.m2)
     s = CStereotype("S1", extended=self.a)
     c1 = CClass(sub1, "C1")
     c2 = CClass(sub2, "C2")
     links = add_links({c1: c2}, stereotype_instances=s)[0]
     eq_(s.extended_instances, [links])
     eq_(links.stereotype_instances, [s])