def test_is_member(self, mock_session_get, mock_get_dn, mock_isfile):
        """
        :param mock_session:       The mock_session object.
        :return:
        """

        mock_response = mock.Mock()
        mock_response.text = _XML0
        mock_response.status_code = 200

        mock_response2 = mock.Mock()
        mock_response2.text = _XML0
        mock_response2.status_code = 200

        mock_get_dn.return_value = test_x500_dn

        c = GroupsClient(test_certificate_name, host=test_host)

        these_params = deepcopy(test_params)

        # Not a member of group
        these_params['GROUPID'] = 'foo'
        mock_session_get.return_value = mock_response
        self.assertFalse(c.is_member('foo'))
        mock_session_get.assert_called_once_with(
            test_base_url + "/search?", verify=False, params=these_params)
        mock_session_get.reset_mock()

        # Member of single supplied group
        mock_response.text = _XML1
        these_params['GROUPID'] = 'groupA'
        self.assertTrue(c.is_member('groupA'))
        mock_session_get.assert_called_once_with(
            test_base_url + "/search?", verify=False, params=these_params)
        mock_session_get.reset_mock()

        # Member of one of a list of groups: success after checking first
        self.assertTrue(c.is_member(['groupA', 'bork']))
        mock_session_get.assert_called_once_with(
            test_base_url + "/search?", verify=False, params=these_params)
        mock_session_get.reset_mock()

        # Member of one of a list of groups: 2 calls, success on second
        these_params2 = deepcopy(test_params)
        these_params2['GROUPID'] = 'bork'
        mock_session_get.side_effect = [mock_response2, mock_response]
        self.assertTrue(c.is_member(['bork','groupA']))
        mock_session_get.assert_has_calls(
            [ mock.call(test_base_url + "/search?", verify=False,
                        params=these_params2),
              mock.call(test_base_url + "/search?", verify=False,
                        params=these_params) ] )
        mock_session_get.reset_mock()
    def test_users_client(self):
        self.init()

        # Since the UsersClient can't currently create a user, as a work around
        # we create a new group, get the group, and use the group owner as
        # the user to try and get using the user client.
        groups_client = GroupsClient(self.cert_file)
        group = Group(GroupsClientIntTest.get_group_id("py1"))

        try:
            groups_client.create_group(group)
        except Exception, e:
            self.fail("Error creating group because {0}".format(repr(e)))
    def test_users_client(self):
        self.init()

        # Since the UsersClient can't currently create a user, as a work around
        # we create a new group, get the group, and use the group owner as
        # the user to try and get using the user client.
        groups_client = GroupsClient(self.cert_file)
        group = Group(GroupsClientIntTest.get_group_id('py1'))

        try:
            groups_client.create_group(group)
        except Exception, e:
            self.fail('Error creating group because {0}'.format(repr(e)))
    def test_groups_client(self):
        self.init()

        # Use the first version for lots of debugging information
        # client = GroupsClient(self.cert_file, log_level=logging.DEBUG)
        client = GroupsClient(self.cert_file)

        # create a group
        expected = Group(self.get_group_id("py1"))
        expected.description = "group description"
        print "expected group {0}".format(expected)

        try:
            client.create_group(expected)
        except Exception, e:
            self.fail("Error creating group because {0}".format(repr(e)))
    def test_groups_client(self):
        self.init()

        # Use the first version for lots of debugging information
        #client = GroupsClient(self.cert_file, log_level=logging.DEBUG)
        client = GroupsClient(self.cert_file)

        # create a group
        expected = Group(self.get_group_id('py1'))
        expected.description = 'group description'
        print 'expected group {0}'.format(expected)

        try:
            client.create_group(expected)
        except Exception, e:
            self.fail('Error creating group because {0}'.format(repr(e)))
    def test_groups_client(self):
        self.init()

        # Use the first version for lots of debugging information
        #client = GroupsClient(self.cert_file, log_level=logging.DEBUG)
        client = GroupsClient(self.cert_file)

        # create the owner
        owner = User(Identity(client.current_user_dn, 'X500'))

        # create a group
        expected = Group(self.get_group_id('py1'), owner)
        expected.description = 'group description'
        print 'expected group ' + expected

        try:
            client.create_group(expected)
        except Exception, e:
            self.fail('Error creating group because ' + repr(e))
Beispiel #7
0
    def test_is_member(self, mock_session_get, mock_get_dn, mock_isfile):
        """
        :param mock_session:       The mock_session object.
        :return:
        """

        mock_response = mock.Mock()
        mock_response.text = _XML0
        mock_response.status_code = 200

        mock_response2 = mock.Mock()
        mock_response2.text = _XML0
        mock_response2.status_code = 200

        mock_get_dn.return_value = test_x500_dn

        c = GroupsClient(test_certificate_name, host=test_host)

        these_params = deepcopy(test_params)

        # Not a member of group
        these_params['GROUPID'] = 'foo'
        mock_session_get.return_value = mock_response
        self.assertFalse(c.is_member('foo'))
        mock_session_get.assert_called_once_with(test_base_url + "/search?",
                                                 verify=False,
                                                 params=these_params)
        mock_session_get.reset_mock()

        # Member of single supplied group
        mock_response.text = _XML1
        these_params['GROUPID'] = 'groupA'
        self.assertTrue(c.is_member('groupA'))
        mock_session_get.assert_called_once_with(test_base_url + "/search?",
                                                 verify=False,
                                                 params=these_params)
        mock_session_get.reset_mock()

        # Member of one of a list of groups: success after checking first
        self.assertTrue(c.is_member(['groupA', 'bork']))
        mock_session_get.assert_called_once_with(test_base_url + "/search?",
                                                 verify=False,
                                                 params=these_params)
        mock_session_get.reset_mock()

        # Member of one of a list of groups: 2 calls, success on second
        these_params2 = deepcopy(test_params)
        these_params2['GROUPID'] = 'bork'
        mock_session_get.side_effect = [mock_response2, mock_response]
        self.assertTrue(c.is_member(['bork', 'groupA']))
        mock_session_get.assert_has_calls([
            mock.call(test_base_url + "/search?",
                      verify=False,
                      params=these_params2),
            mock.call(test_base_url + "/search?",
                      verify=False,
                      params=these_params)
        ])
        mock_session_get.reset_mock()
Beispiel #8
0
    def test_get_membership(self, mock_session_get, mock_get_dn, mock_isfile):
        """
        :param mock_session:       The mock_session object.
        :return:
        """
        mock_response = mock.Mock()
        mock_response.text = _XML2
        mock_response.status_code = 200

        mock_get_dn.return_value = test_x500_dn

        c = GroupsClient(test_certificate_name, host=test_host)

        # no arguments: return full list of memberships
        mock_session_get.return_value = mock_response
        self.assertEqual(c.get_membership(), groups2)
        mock_session_get.assert_called_once_with(test_base_url + "/search?",
                                                 verify=False,
                                                 params=test_params)
        mock_session_get.reset_mock()

        # provide a group name
        mock_response.text = _XML1
        these_params = deepcopy(test_params)
        these_params['GROUPID'] = 'groupA'
        self.assertEqual(c.get_membership(group_id='groupA'), groups1)
        mock_session_get.assert_called_once_with(test_base_url + "/search?",
                                                 verify=False,
                                                 params=these_params)
        mock_session_get.reset_mock()

        # group for which we are not a member
        mock_response.text = _XML0
        these_params['GROUPID'] = 'foo'
        self.assertEqual(c.get_membership(group_id='foo'), groups0)
        mock_session_get.assert_called_once_with(test_base_url + "/search?",
                                                 verify=False,
                                                 params=these_params)
        mock_session_get.reset_mock()
    def test_get_membership(self, mock_session_get, mock_get_dn, mock_isfile):
        """
        :param mock_session:       The mock_session object.
        :return:
        """
        mock_response = mock.Mock()
        mock_response.text = _XML2
        mock_response.status_code = 200

        mock_get_dn.return_value = test_x500_dn

        c = GroupsClient(test_certificate_name, host=test_host)

        # no arguments: return full list of memberships
        mock_session_get.return_value = mock_response
        self.assertEqual(c.get_membership(), groups2)
        mock_session_get.assert_called_once_with(
            test_base_url + "/search?", verify=False, params=test_params)
        mock_session_get.reset_mock()

        # provide a group name
        mock_response.text = _XML1
        these_params = deepcopy(test_params)
        these_params['GROUPID'] = 'groupA'
        self.assertEqual(c.get_membership(group_id='groupA'), groups1)
        mock_session_get.assert_called_once_with(
            test_base_url + "/search?", verify=False, params=these_params)
        mock_session_get.reset_mock()

        # group for which we are not a member
        mock_response.text = _XML0
        these_params['GROUPID'] = 'foo'
        self.assertEqual(c.get_membership(group_id='foo'), groups0)
        mock_session_get.assert_called_once_with(
            test_base_url + "/search?", verify=False, params=these_params)
        mock_session_get.reset_mock()