本文整理汇总了Python中tests.utils.MockUtils类的典型用法代码示例。如果您正苦于以下问题:Python MockUtils类的具体用法?Python MockUtils怎么用?Python MockUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create
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()
示例2: test_assign
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()
示例3: test_impersonate
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)
示例4: test_fetch_with_page
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')
示例5: test_fetch_with_group_by
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')
示例6: test_fetch_with_filter
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")
示例7: test_count_with_page
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')
示例8: test_count_with_filter
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)
示例9: test_count_with_group_by
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')
示例10: test_refetch_all_with_delete_object
def test_refetch_all_with_delete_object(self):
""" GET /enterprises refetch all enterprises should remove local info when object is deleted """
mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises)
with patch('requests.request', mock):
(fetcher, user, enterprises) = self.user.enterprises.fetch()
mock = MockUtils.create_mock_response(status_code=200, data=self.enterprises[1:])
with patch('requests.request', mock):
(fetcher, user, enterprises) = self.user.enterprises.fetch()
connection = fetcher.current_connection
self.assertEqual(connection.response.status_code, 200)
self.assertEqual(len(enterprises), 3)
示例11: test_delete_raise_error
def test_delete_raise_error(self):
""" DELETE /enterprises delete enterprise raise error """
mock = MockUtils.create_mock_response(status_code=400, data=self.enterprise, error=u"Internal error")
with patch('requests.request', mock):
with self.assertRaises(BambouHTTPError):
(obj, connection) = self.enterprise.delete(response_choice=1)
示例12: test_fetch_all_should_not_raise_exception
def test_fetch_all_should_not_raise_exception(self):
""" GET /enterprises retrieve all enterprises should not raise exception """
mock = MockUtils.create_mock_response(status_code=500, data=[], error=u"Internal error")
with patch('requests.request', mock):
with self.assertRaises(BambouHTTPError):
(fetcher, user, enterprises) = self.user.enterprises.fetch()
connection = fetcher.current_connection
示例13: test_count_all_should_raise_exception
def test_count_all_should_raise_exception(self):
""" HEAD /enterprises count all enterprises should raise exception """
user = self.user
mock = MockUtils.create_mock_response(status_code=500, data=[], error=u"Internal error")
with patch('requests.request', mock):
with self.assertRaises(BambouHTTPError):
(fetcher, user, count) = self.user.enterprises.count()
示例14: test_create_raise_error
def test_create_raise_error(self):
""" POST /enterprises create enterprise raises an error """
user = self.user
enterprise = get_valid_enterprise(id=1, name=u"Enterprise")
mock = MockUtils.create_mock_response(status_code=409, data=enterprise, error=u"Name already exists")
with patch('requests.request', mock):
with self.assertRaises(BambouHTTPError):
(obj, connection) = user.create_child(enterprise)
示例15: test_update_raise_error
def test_update_raise_error(self):
""" PUT /enterprises update enterprise raise error """
enterprise = self.enterprise
enterprise.name ="Another name"
mock = MockUtils.create_mock_response(status_code=404, data=enterprise, error=u"Enterprise not found")
with patch('requests.request', mock):
with self.assertRaises(BambouHTTPError):
(obj, connection) = enterprise.save()