Esempio n. 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'
Esempio n. 2
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
Esempio n. 3
0
    def test_no_user(self):
        """ Retrieve all users for a role but there are none """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getAllUsersInRole'
        code = 200
        xml = build_xml_list([])
        BonitaServer.set_response_list([[url, code, xml]])

        role = BonitaRole('myrole', '', '')
        role.uuid = '1234'

        users = BonitaUser.find_by_role(role)

        assert isinstance(users, list)
        assert len(users) == 0
Esempio n. 4
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)
Esempio n. 5
0
    def test_unknown_role(self):
        """ Try to retrieve role by UUID but no role matching """
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getRoleByUUID'
        code = 500
        xml = build_dumb_bonita_error_body('RoleNotFoundException',message='can\'t find Role: unknown')
        BonitaServer.set_response_list([[url,code,xml]])

        role = BonitaRole.get_by_uuid('unknown')

        assert role == None
Esempio n. 6
0
    def test_not_found_role_by_uuid(self):
        """ Try to retrieve role but nothing found with given key """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getRoleByUUID'
        code = 500
        xml = build_dumb_bonita_error_body('RoleNotFoundException',message='can\'t find Role: unknown')
        BonitaServer.set_response_list([[url,code,xml]])

        role = BonitaRole.get(uuid='unknown')

        assert role == None
Esempio n. 7
0
    def test_role(self):
        """ Instanciate a Bonita role """
        xml = build_bonita_role_xml('role uuid','role name',description='a role desc',label='a role label',dbid='dbid-1234')

        role = BonitaRole._instanciate_from_xml(xml)

        assert isinstance(role,BonitaRole)
        assert role.uuid == u'role uuid'
        assert role.name == u'role name'
        assert role.description == u'a role desc'
        assert role.label == u'a role label'
        assert role.dbid == u'dbid-1234'
Esempio n. 8
0
    def test_get_role_by_name(self):
        """ Retrieve a role with name """
        # Setup the response for MockServer
        BonitaServer.use('localhost', 9090, 'restuser', 'restbpm')
        url = '/identityAPI/getRole'
        code = 200
        xml = build_bonita_role_xml(uuid='996633',name='myrole')
        BonitaServer.set_response_list([[url,code,xml]])

        role = BonitaRole.get(name='myrole')

        assert isinstance(role,BonitaRole)
        assert role.name == 'myrole'
Esempio n. 9
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
Esempio n. 10
0
    def test_group_not_bonitagroup(self):
        """ Try to retrieve membership by role and group but group is not a BonitaGroup """
        role = BonitaRole('myrole','','')
        role.uuid = '1234'

        membership = BonitaMembership.get_by_role_and_group(role=role,group='unknown')
Esempio n. 11
0
    def test_not_group(self):
        """ Try to retrieve Users for a role and group but not given a Group """
        role = BonitaRole('myrole', '', '')
        role.uuid = '1234'

        BonitaUser.find_by_role_and_group(role, 123.45)
Esempio n. 12
0
 def test_unknown_param(self):
     """ Try to retrieve role but gives an unknown param """
     BonitaRole.get(unknown_param='32')
Esempio n. 13
0
    def test_invalid_xml(self):
        """ Try to instanciate a BonitaRole from invalid XML """
        xml = '<coucou>une valeur</coucou>'

        role = BonitaRole._instanciate_from_xml(xml)