def test_add_member_already_have_parent(self): obj0 = lib.ResourceRelationNode(self.entity_fixture("0")) obj1 = lib.ResourceRelationNode(self.entity_fixture("1")) obj2 = lib.ResourceRelationNode(self.entity_fixture("2")) obj0.add_member(obj1) with self.assertRaises(AssertionError): obj2.add_member(obj1)
def test_with_members(self): ent0 = self.entity_fixture("0") ent1 = self.entity_fixture("1") ent2 = self.entity_fixture("2") ent3 = self.entity_fixture("3") obj = lib.ResourceRelationNode(ent0) obj.add_member(lib.ResourceRelationNode(ent1)) member = lib.ResourceRelationNode(ent2) member.add_member(lib.ResourceRelationNode(ent3)) obj.add_member(member) self.assert_dto_equal( ResourceRelationDto( ent0, [ ResourceRelationDto(ent1, [], False), ResourceRelationDto( ent2, [ ResourceRelationDto(ent3, [], False), ], False, ), ], False, ), obj.to_dto(), )
def test_add_member(self): ent0 = self.entity_fixture("0") ent1 = self.entity_fixture("1") obj = lib.ResourceRelationNode(ent0) obj.add_member(lib.ResourceRelationNode(ent1)) self.assertEqual( ResourceRelationDto( ent0, [ResourceRelationDto(ent1, [], False)], False, ).to_dict(), obj.to_dto().to_dict(), )
def test_add_member_already_in_branch(self): ent0 = self.entity_fixture("0") ent1 = self.entity_fixture("1") obj0 = lib.ResourceRelationNode(ent0) obj1 = lib.ResourceRelationNode(ent1) obj0.add_member(obj1) obj1.add_member(obj0) self.assert_dto_equal( ResourceRelationDto(ent0, [ResourceRelationDto(ent1, [], False)], False), obj0.to_dto(), )
def test_no_members(self): ent = self.entity_fixture("0") obj = lib.ResourceRelationNode(ent) self.assertEqual( ResourceRelationDto(ent, [], False).to_dict(), obj.to_dto().to_dict(), )
def test_add_member_already_in_different_branch(self): ent0 = self.entity_fixture("0") ent1 = self.entity_fixture("1") obj0 = lib.ResourceRelationNode(ent0) obj0.add_member(lib.ResourceRelationNode(ent1)) obj0.add_member(lib.ResourceRelationNode(ent1)) self.assertEqual( ResourceRelationDto( ent0, [ ResourceRelationDto(ent1, [], False), ResourceRelationDto(ent1, [], False), ], False, ).to_dict(), obj0.to_dto().to_dict(), )
def test_stop(self): ent = self.entity_fixture("0") obj = lib.ResourceRelationNode(ent) obj.stop() self.assert_dto_equal( ResourceRelationDto(ent, [], True), obj.to_dto(), )
def test_add_member_itself(self): ent = self.entity_fixture("0") obj = lib.ResourceRelationNode(ent) obj.add_member(obj) self.assert_dto_equal( ResourceRelationDto(ent, [], False), obj.to_dto(), )