replaced unittest assertions pytest assertions (#26572)

This commit is contained in:
Aarif
2021-02-22 20:04:00 +05:00
committed by GitHub
parent 4ef7d63211
commit cbf78fbdf3
5 changed files with 47 additions and 71 deletions

View File

@@ -42,7 +42,7 @@ class TestUtils(ApiTestCase): # lint-amnesty, pylint: disable=missing-class-doc
body=self.request_data['body'],
)
self.assertEqual(status_code, 503)
assert status_code == 503
@ddt.data(201, 400, 401, 403, 404, 500)
def test_zendesk_status_codes(self, mock_code):
@@ -54,7 +54,7 @@ class TestUtils(ApiTestCase): # lint-amnesty, pylint: disable=missing-class-doc
body=self.request_data['body'],
)
self.assertEqual(status_code, mock_code)
assert status_code == mock_code
def test_unexpected_error_pinging_zendesk(self):
with patch('requests.post', side_effect=Exception("WHAMMY")):
@@ -64,7 +64,7 @@ class TestUtils(ApiTestCase): # lint-amnesty, pylint: disable=missing-class-doc
subject=self.request_data['subject'],
body=self.request_data['body'],
)
self.assertEqual(status_code, 500)
assert status_code == 500
def test_financial_assistant_ticket(self):
""" Test Financial Assistent request ticket. """
@@ -93,4 +93,4 @@ class TestUtils(ApiTestCase): # lint-amnesty, pylint: disable=missing-class-doc
)
),
)
self.assertEqual(status_code, 200)
assert status_code == 200

View File

@@ -46,33 +46,23 @@ class ZendeskProxyTestCase(ApiTestCase):
)
self.assertHttpCreated(response)
(mock_args, mock_kwargs) = mock_post.call_args
self.assertEqual(mock_args, ('https://www.superrealurlsthataredefinitelynotfake.com/api/v2/tickets.json',))
assert mock_args == ('https://www.superrealurlsthataredefinitelynotfake.com/api/v2/tickets.json',)
six.assertCountEqual(self, mock_kwargs.keys(), ['headers', 'data'])
self.assertEqual(
mock_kwargs['headers'],
{
'content-type': 'application/json',
'Authorization': 'Bearer abcdefghijklmnopqrstuvwxyz1234567890'
}
)
self.assertEqual(
json.loads(mock_kwargs['data']),
{
'ticket': {
'comment': {
'body': "Help! I'm trapped in a unit test factory and I can't get out!",
'uploads': None,
},
'custom_fields': None,
'requester': {
'email': 'JohnQStudent@example.com',
'name': 'John Q. Student',
},
assert mock_kwargs['headers'] == {
'content-type': 'application/json', 'Authorization': 'Bearer abcdefghijklmnopqrstuvwxyz1234567890'
}
assert json.loads(mock_kwargs['data']) == {
'ticket':
{
'comment':
{
'body': "Help! I'm trapped in a unit test factory and I can't get out!", 'uploads': None
}, 'custom_fields': None,
'requester': {'email': 'JohnQStudent@example.com', 'name': 'John Q. Student'},
'subject': 'Python Unit Test Help Request',
'tags': ['python_unit_test'],
},
}
)
'tags': ['python_unit_test']
}
}
@ddt.data('name', 'tags', 'email')
def test_bad_request(self, key_to_delete):
@@ -103,4 +93,4 @@ class ZendeskProxyTestCase(ApiTestCase):
for _ in range(ZENDESK_REQUESTS_PER_HOUR):
self.request_without_auth('post', self.url)
response = self.request_without_auth('post', self.url)
self.assertEqual(response.status_code, 429)
assert response.status_code == 429

View File

@@ -57,33 +57,21 @@ class ZendeskProxyTestCase(ApiTestCase):
)
self.assertHttpCreated(response)
(mock_args, mock_kwargs) = mock_post.call_args
self.assertEqual(mock_args, ('https://www.superrealurlsthataredefinitelynotfake.com/api/v2/tickets.json',))
assert mock_args == ('https://www.superrealurlsthataredefinitelynotfake.com/api/v2/tickets.json',)
six.assertCountEqual(self, mock_kwargs.keys(), ['headers', 'data'])
self.assertEqual(
mock_kwargs['headers'],
{
'content-type': 'application/json',
'Authorization': 'Bearer abcdefghijklmnopqrstuvwxyz1234567890'
}
)
self.assertEqual(
json.loads(mock_kwargs['data']),
{
'ticket': {
'comment': {
'body': "Help! I'm trapped in a unit test factory and I can't get out!",
'uploads': None,
},
'custom_fields': [{'id': '001', 'value': 'demo-course'}],
'requester': {
'email': self.user.email,
'name': self.user.username
},
'subject': 'Python Unit Test Help Request',
'tags': ['python_unit_test'],
assert mock_kwargs['headers'] == {
'content-type': 'application/json', 'Authorization': 'Bearer abcdefghijklmnopqrstuvwxyz1234567890'
}
assert json.loads(mock_kwargs['data']) == {
'ticket': {
'comment': {
'body': "Help! I'm trapped in a unit test factory and I can't get out!", 'uploads': None
},
'custom_fields': [{'id': '001', 'value': 'demo-course'}],
'requester': {'email': self.user.email, 'name': self.user.username},
'subject': 'Python Unit Test Help Request', 'tags': ['python_unit_test']
}
)
}
@ddt.data('subject', 'tags')
def test_bad_request(self, key_to_delete):
@@ -115,4 +103,4 @@ class ZendeskProxyTestCase(ApiTestCase):
for _ in range(ZendeskProxyThrottle().num_requests):
self.request_without_auth('post', self.url)
response = self.request_without_auth('post', self.url)
self.assertEqual(response.status_code, 429)
assert response.status_code == 429