当前位置: 首页>>代码示例>>Python>>正文


Python MockUtils.get_mock_parameter方法代码示例

本文整理汇总了Python中tests.utils.MockUtils.get_mock_parameter方法的典型用法代码示例。如果您正苦于以下问题:Python MockUtils.get_mock_parameter方法的具体用法?Python MockUtils.get_mock_parameter怎么用?Python MockUtils.get_mock_parameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.utils.MockUtils的用法示例。


在下文中一共展示了MockUtils.get_mock_parameter方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_create(self):
        """ POST /enterprises create enterprise """

        user = self.user
        enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
        mock = MockUtils.create_mock_response(status_code=201, data=enterprise)

        with patch('requests.request', mock):
            (obj, connection) = user.create_child(enterprise)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'POST')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(connection.response.status_code, 201)
        self.assertEqual(obj.id, 1)
        self.assertEqual(obj.name, enterprise.name)
        self.assertIn(obj, user.enterprises)
        self.assertIn(enterprise, user.enterprises)

        user.enterprises.flush()
开发者ID:Dogild,项目名称:bambou,代码行数:29,代码来源:test_create_enterprise.py

示例2: test_assign

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_assign(self):
        """ PUT /groups/id/users assign users """

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        employee1 = Employee(firstname=u"Steven", lastname=u"Gerrard")
        employee2 = Employee(firstname=u"Gerrard", lastname=u"Lampard")

        with patch('requests.request', mock):
            (objects, connection) = self.group.assign([employee1, employee2], Employee)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(connection.response.status_code, 204)
        self.assertEqual(url, 'https://vsd:8443/api/v3_2/groups/' + self.group.id + '/users')
        self.assertEqual(method, 'PUT')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(objects, [employee1, employee2])
        self.assertEqual(self.group.employees, [employee1, employee2])
        self.group.employees.flush()
开发者ID:Dogild,项目名称:bambou,代码行数:27,代码来源:test_assign_users.py

示例3: test_impersonate

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_impersonate(self):
        """ GET /enterprises with impersonation

        """
        session = start_session()

        session.impersonate(username='johndoe', enterprise='enterprise')

        mock = MockUtils.create_mock_response(status_code=200, data=[])

        user = User()

        with patch('requests.request', mock):
            user.enterprises.fetch()

        headers = MockUtils.get_mock_parameter(mock=mock, name='headers')

        self.assertIn('X-Nuage-ProxyUser', headers)
        self.assertEquals(headers['X-Nuage-ProxyUser'], '[email protected]')
        self.assertEquals(session.is_impersonating, True)

        session.stop_impersonate()
        self.assertEquals(session.is_impersonating, False)

        with patch('requests.request', mock):
            user.enterprises.fetch()

        headers = MockUtils.get_mock_parameter(mock=mock, name='headers')
        self.assertNotIn('X-Nuage-ProxyUser', headers)
开发者ID:Dogild,项目名称:bambou,代码行数:31,代码来源:test_impersonate.py

示例4: test_fetch_with_page

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_fetch_with_page(self):
        """ GET /enterprises retrieve enterprises with page """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(page=2)

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Page'], '2')
开发者ID:nuagenetworks,项目名称:bambou,代码行数:12,代码来源:test_fetch_enterprises.py

示例5: test_fetch_with_group_by

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_fetch_with_group_by(self):
        """ GET /enterprises retrieve enterprises with group_by """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(group_by=['field1', 'field2'])

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-GroupBy'], 'true')
        self.assertEqual(headers['X-Nuage-Attributes'], 'field1, field2')
开发者ID:nuagenetworks,项目名称:bambou,代码行数:13,代码来源:test_fetch_enterprises.py

示例6: test_fetch_with_filter

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_fetch_with_filter(self):
        """ GET /enterprises retrieve enterprises with filters """

        mock = MockUtils.create_mock_response(status_code=200, data=[self.enterprises[1]])

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch(filter=u"name == 'Enterprise 2'")

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Filter'],"name == 'Enterprise 2'")
        self.assertEqual(len(enterprises), 1)
        self.assertEqual(enterprises[0].name,"Enterprise 2")
开发者ID:nuagenetworks,项目名称:bambou,代码行数:14,代码来源:test_fetch_enterprises.py

示例7: test_fetch

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_fetch(self):
        """ GET /enterprises/id fetch enterprise """

        enterprise = Enterprise(id=1)
        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprise)

        with patch('requests.request', mock):
            (obj, connection) = enterprise.fetch()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises/%s' % enterprise.id)
        self.assertEqual(method, 'GET')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(connection.response.status_code, 200)
        self.assertEqual(enterprise.name, obj.name)
开发者ID:Dogild,项目名称:bambou,代码行数:23,代码来源:test_fetch_enterprise.py

示例8: test_delete

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_delete(self):
        """ DELETE /enterprises delete enterprise """

        mock = MockUtils.create_mock_response(status_code=204, data=self.enterprise)

        with patch('requests.request', mock):
            (obj, connection) = self.enterprise.delete(response_choice=1)

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises/%s?responseChoice=1' % self.enterprise.id)
        self.assertEqual(method, 'DELETE')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(obj.name, self.enterprise.name)
        self.assertEqual(obj.id, self.enterprise.id)
        self.assertEqual(connection.response.status_code, 204)
开发者ID:Dogild,项目名称:bambou,代码行数:23,代码来源:test_delete_enterprise.py

示例9: test_count_with_page

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_count_with_page(self):
        """ HEAD /enterprises count enterprises with page """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(page=3)

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Page'], '3')
开发者ID:nuagenetworks,项目名称:bambou,代码行数:15,代码来源:test_count_enterprises.py

示例10: test_update

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_update(self):
        """ PUT /me update current user """

        self.user.prepare_change_password('test')

        mock = MockUtils.create_mock_response(status_code=204, data=None)

        with patch('requests.request', mock):
            (obj, connection) = self.user.save()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(connection.response.status_code, 204)
        self.assertEqual(url, 'https://vsd:8443/api/v3_2/me')
        self.assertEqual(method, 'PUT')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjp0ZXN0')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(self.user.password,"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")  # Encrypted password
开发者ID:Dogild,项目名称:bambou,代码行数:24,代码来源:test_update_user.py

示例11: test_count_with_group_by

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_count_with_group_by(self):
        """ HEAD /enterprises count enterprises with group_by """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(group_by=['field1', 'field2'])

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-GroupBy'], 'true')
        self.assertEqual(headers['X-Nuage-Attributes'], 'field1, field2')
开发者ID:nuagenetworks,项目名称:bambou,代码行数:16,代码来源:test_count_enterprises.py

示例12: test_count_with_filter

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_count_with_filter(self):
        """ HEAD /enterprises count enterprises with filters """

        user = self.user
        headers = {'X-Nuage-Count': 2}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count(filter=u"name == 'Enterprise 2'")

        headers = MockUtils.get_mock_parameter(mock, 'headers')
        self.assertEqual(headers['X-Nuage-Filter'],"name == 'Enterprise 2'")
        self.assertEqual(count, 2)
开发者ID:nuagenetworks,项目名称:bambou,代码行数:16,代码来源:test_count_enterprises.py

示例13: test_fetch_all

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_fetch_all(self):
        """ GET /enterprises fetch all enterprises """

        mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)

        with patch('requests.request', mock):
            (fetcher, user, enterprises) = self.user.enterprises.fetch()
            connection = fetcher.current_connection

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'GET')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(len(enterprises), 4)
        self.assertEqual(connection.response.status_code, 200)
开发者ID:nuagenetworks,项目名称:bambou,代码行数:25,代码来源:test_fetch_enterprises.py

示例14: test_count_all

# 需要导入模块: from tests.utils import MockUtils [as 别名]
# 或者: from tests.utils.MockUtils import get_mock_parameter [as 别名]
    def test_count_all(self):
        """ HEAD /enterprises count all enterprises """

        user = self.user
        headers = {'X-Nuage-Count': 4}

        mock = MockUtils.create_mock_response(status_code=200, data=None, headers=headers)

        with patch('requests.request', mock):
            (fetcher, user, count) = self.user.enterprises.count()

        method = MockUtils.get_mock_parameter(mock, 'method')
        url = MockUtils.get_mock_parameter(mock, 'url')
        headers = MockUtils.get_mock_parameter(mock, 'headers')

        self.assertEqual(url, 'https://vsd:8443/api/v3_2/enterprises')
        self.assertEqual(method, 'HEAD')
        self.assertEqual(headers['Authorization'], 'XREST dXNlcjo1MWYzMTA0Mi1iMDQ3LTQ4Y2EtYTg4Yi02ODM2ODYwOGUzZGE=')
        self.assertEqual(headers['X-Nuage-Organization'], 'enterprise')
        self.assertEqual(headers['Content-Type'], 'application/json')

        self.assertEqual(fetcher, self.user.enterprises)
        self.assertEqual(user, self.user)
        self.assertEqual(count, 4)
开发者ID:nuagenetworks,项目名称:bambou,代码行数:26,代码来源:test_count_enterprises.py


注:本文中的tests.utils.MockUtils.get_mock_parameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。