Example #1
0
    def test_some_users(self):
        """ Retrieve all users for a role """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getAllUsersInRoleAndGroup'
        code = 200
        user1_xml = build_bonita_user_xml(uuid='1234', password='', username='******')
        user2_xml = build_bonita_user_xml(uuid='6789', password='', username='******')
        xml = build_xml_list([user1_xml, user2_xml])
        BonitaServer.set_response_list([[url, code, xml]])

        role = BonitaRole('myrole', '', '')
        role.uuid = '1234'
        group = BonitaGroup('mygroup', '', '')
        group.uuid = '2345'

        users = BonitaUser.find_by_role_and_group(role, group)

        assert isinstance(users, list)
        assert len(users) == 2

        for user in users:
            assert isinstance(user, BonitaUser)

        sorted_users = sorted(users, key=lambda user: user.uuid)
        assert sorted_users[0].uuid == u'1234'
        assert sorted_users[1].uuid == u'6789'
Example #2
0
    def test_no_user(self):
        """ Retrieve all users for a group but there are none """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getAllUsersInGroup'
        code = 200
        xml = build_xml_list([])
        BonitaServer.set_response_list([[url, code, xml]])

        group = BonitaGroup('mygroup', '', '')
        group.uuid = '2345'

        users = BonitaUser.find_by_group(group)

        assert isinstance(users, list)
        assert len(users) == 0
Example #3
0
    def test_group_with_one_parent(self):
        """ Instanciate a Bonita group with one parent """
        # Build up parent and child XML
        parent_xml = build_bonita_group_xml('parent uuid','parent name','parent description','parent label','12',None, True)
        child_xml = build_bonita_group_xml('group uuid','group name',description='a desc',label='a label')
        
        # Add the parent XML to the Child
        parent_soup = BeautifulSoup(parent_xml,'xml').parentGroup
        child_soup = BeautifulSoup(child_xml,'xml')
        child_soup.Group.append(parent_soup)

        xml = unicode(child_soup.Group)

        group = BonitaGroup._instanciate_from_xml(xml)

        assert isinstance(group,BonitaGroup)
        assert group.uuid == u'group uuid'
        assert group.name == u'group name'
        assert group.description == u'a desc'
        assert group.label == u'a label'

        assert group.parent is not None
        assert isinstance(group.parent, BonitaGroup)
        assert group.parent.uuid == u'parent uuid'
        assert group.parent.parent is None
Example #4
0
    def test_unknown_group(self):
        """ Try to retrieve membership by role and group : no group matching """
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getMembershipForRoleAndGroup'
        code = 500
        xml = build_dumb_bonita_error_body('GroupNotFoundException',message='can\'t find Group: unknown')
        BonitaServer.set_response_list([[url,code,xml]])

        role = BonitaRole('myrole','','')
        role.uuid = '1234'
        group = BonitaGroup('mygroup','','')
        group.uuid = '2345'

        membership = BonitaMembership.get_by_role_and_group(role=role,group=group)

        assert membership == None
Example #5
0
    def test_unknown_group(self):
        """ Try to retrieve group by UUID but no group matching """
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getGroupByUUID'
        code = 500
        xml = build_dumb_bonita_error_body('GroupNotFoundException',message='can\'t find Group: unknown')
        BonitaServer.set_response_list([[url,code,xml]])

        group = BonitaGroup.get_by_uuid('unknown')

        assert group == None
Example #6
0
    def test_get_membership_by_role_and_group(self):
        """ Retrieve a membership using role and group """
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getMembershipForRoleAndGroup'
        code = 200

        role = BonitaRole('myrole','','')
        role.uuid = '1234'
        group = BonitaGroup('mygroup','','')
        group.uuid = '2345'

        xml = build_bonita_membership_xml(uuid='996633',role=role, group=group)
        BonitaServer.set_response_list([[url,code,xml]])


        membership = BonitaMembership.get_by_role_and_group(role,group)

        assert isinstance(membership, BonitaMembership)
        assert isinstance(membership.role,BonitaRole)
        assert isinstance(membership.group,BonitaGroup)
Example #7
0
    def test_group_without_parent(self):
        """ Instanciate a Bonita group without any parent """
        xml = build_bonita_group_xml('group uuid','group name',description='a desc',label='a label')

        group = BonitaGroup._instanciate_from_xml(xml)

        assert isinstance(group,BonitaGroup)
        assert group.uuid == u'group uuid'
        assert group.name == u'group name'
        assert group.description == u'a desc'
        assert group.label == u'a label'
        assert group.parent is None
Example #8
0
    def test_not_found_group_by_uuid(self):
        """ Try to retrieve group but nothing found with given key """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getGroupByUUID'
        code = 500
        xml = build_dumb_bonita_error_body('GroupNotFoundException',message='can\'t find Group: unknown')
        BonitaServer.set_response_list([[url,code,xml]])

        group = BonitaGroup.get(uuid='unknown')

        assert group == None
Example #9
0
    def test_known_group(self):
        """ Retrieve a group using the UUID """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getGroupByUUID'
        code = 200
        xml = build_bonita_group_xml(uuid='996633',name='mygroup')
        BonitaServer.set_response_list([[url,code,xml]])

        group = BonitaGroup.get_by_uuid('996633')

        assert isinstance(group,BonitaGroup)
        assert group.uuid == '996633'
Example #10
0
    def test_get_group_by_path(self):
        """ Retrieve a group with path """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getGroupUsingPath'
        code = 200
        xml = build_bonita_group_xml(uuid='996633',name='mygroup')
        BonitaServer.set_response_list([[url,code,xml]])

        group = BonitaGroup.get(path='/mygroup')

        assert isinstance(group,BonitaGroup)
        assert group.name == 'mygroup'
Example #11
0
    def test_known_group_at_root(self):
        """ Retrieve a group using the path (at root) """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getGroupUsingPath'
        code = 200
        xml = build_bonita_group_xml(uuid='996633',name='something')
        BonitaServer.set_response_list([[url,code,xml]])

        group = BonitaGroup.get_by_path('/something')

        assert isinstance(group,BonitaGroup)
        assert group.uuid == '996633'
        assert group.parent is None
Example #12
0
    def test_root_group(self):
        """ Retrieve root group : /platform """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getGroupUsingPath'
        code = 200
        xml = build_bonita_group_xml(uuid='996633',name='platform')
        BonitaServer.set_response_list([[url,code,xml]])

        group = BonitaGroup.get_default_root()

        assert isinstance(group,BonitaGroup)
        assert group.name == u'platform'
        assert group.parent is None
Example #13
0
    def test_user_with_memberships(self):
        """ Instanciate a BonitaUser with memberships """
        role = BonitaRole('myrole', '', '')
        role.uuid = '1234'

        group1 = BonitaGroup('mygroup1', '', '')
        group1.uuid = '2345'
        group2 = BonitaGroup('mygroup2', '', '')
        group2.uuid = '2346'

        membership1 = BonitaMembership(role, group1)
        membership1.uuid = 'uuid-12'
        membership2 = BonitaMembership(role, group2)
        membership2.uuid = 'uuid-13'

        user_properties = {'firstName': u'firstname', 'lastName': u'lastname',
                           'title': u'title', 'jobTitle': u'jobtitle',
                           'memberships': [membership1, membership2]}
        xml = build_bonita_user_xml('user uuid', 'user pass', 'user name', user_properties)

        user = BonitaUser._instanciate_from_xml(xml)

        assert isinstance(user, BonitaUser)

        assert isinstance(user.memberships, list)
        assert len(user.memberships) == 2

        assert isinstance(user.roles, list)
        #assert len(user.roles) == 1
        assert user.roles[0].name == u'myrole'

        assert isinstance(user.groups, list)
        #assert len(user.groups) == 2
        group_names = [group.name for group in user.groups]
        assert u'mygroup1' in group_names
        assert u'mygroup2' in group_names
Example #14
0
    def test_known_group_deep_path(self):
        """ Retrieve a group using the path (deep path) """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getGroupUsingPath'
        code = 200
        gran_father_xml = build_bonita_group_xml(uuid='996631',name='gran-father',as_parent=True)
        father_xml = build_bonita_group_xml(uuid='996632',name='father',parent=gran_father_xml, as_parent=True)
        xml = build_bonita_group_xml(uuid='996633',name='child-group',parent=father_xml)
        BonitaServer.set_response_list([[url,code,xml]])

        group = BonitaGroup.get_by_path('/gran-father/father/child-group')

        assert isinstance(group,BonitaGroup)
        assert group.uuid == '996633'
        assert isinstance(group.parent,BonitaGroup)
        assert group.parent.uuid == '996632'
        assert isinstance(group.parent.parent,BonitaGroup)
        assert group.parent.parent.uuid == '996631'
Example #15
0
    def test_group_with_several_parents(self):
        """ Instanciate a Boinita group with a hierarchy of parents """
        # Build up parents and child XML
        parentA_xml = build_bonita_group_xml('parentA uuid','parentA name','parentA description','parentA label','vieux-1',None, True)
        parentB_xml = build_bonita_group_xml('parentB uuid','parentB name','parentB description','parentB label','vieux-2',None, True)
        parentC_xml = build_bonita_group_xml('parentC uuid','parentC name','parentC description','parentC label','vieux-3',None, True)
        child_xml = build_bonita_group_xml('group uuid','group name',description='a desc',label='a label')
        
        # Add the hierachy of parents to the Child
        parentA_soup = BeautifulSoup(parentA_xml,'xml').parentGroup
        parentB_soup = BeautifulSoup(parentB_xml,'xml').parentGroup
        parentC_soup = BeautifulSoup(parentC_xml,'xml').parentGroup

        parentB_soup.append(parentC_soup)
        parentA_soup.append(parentB_soup)

        child_soup = BeautifulSoup(child_xml,'xml')
        child_soup.Group.append(parentA_soup)

        xml = unicode(child_soup.Group)

        group = BonitaGroup._instanciate_from_xml(xml)

        assert isinstance(group,BonitaGroup)
        assert group.uuid == u'group uuid'
        assert group.name == u'group name'
        assert group.description == u'a desc'
        assert group.label == u'a label'

        assert group.parent is not None
        assert isinstance(group.parent, BonitaGroup)
        assert group.parent.uuid == u'parentA uuid'

        assert group.parent.parent is not None
        assert isinstance(group.parent.parent, BonitaGroup)
        assert group.parent.parent.uuid == u'parentB uuid'

        assert group.parent.parent.parent is not None
        assert isinstance(group.parent.parent.parent, BonitaGroup)
        assert group.parent.parent.parent.uuid == u'parentC uuid'
Example #16
0
    def test_not_role(self):
        """ Try to retrieve Users for a role and group but not given a Role """
        group = BonitaGroup('mygroup', '', '')
        group.uuid = '2345'

        BonitaUser.find_by_role_and_group('coucou', group)
Example #17
0
    def test_role_not_bonitarole(self):
        """ Try to retrieve membership by role and group but role is not a BonitaRole """
        group = BonitaGroup('mygroup','','')
        group.uuid = '2345'

        membership = BonitaMembership.get_by_role_and_group(role='unknown',group=group)
Example #18
0
    def test_group_with_several_parents(self):
        """ Instanciate a Boinita group with a hierarchy of parents """
        xml = ''

        group = BonitaGroup._instanciate_from_xml(xml)
Example #19
0
 def test_unknown_param(self):
     """ Try to retrieve group but gives an unknown param """
     BonitaGroup.get(unknown_param='32')
Example #20
0
    def test_invalid_xml(self):
        """ Try to instanciate a BonitaGroup from invalid XML """
        xml = '<coucou>une valeur</coucou>'

        group = BonitaGroup._instanciate_from_xml(xml)