-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into huniafatima/python-and-django-update
- Loading branch information
Showing
14 changed files
with
163 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ def test_pipeline(self, is_redirect_mock): | |
request, | ||
{ | ||
"edx_lms_user_id": 127, | ||
"customer_id": None, | ||
"email": "[email protected]", | ||
"username": "test", | ||
"page_size": ORDER_HISTORY_PER_SYSTEM_REQ_LIMIT, | ||
"page": 0, | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ class OrdersViewTests(TestCase): | |
test_user_username = 'test' # Different from ORDER_HISTORY_GET_PARAMETERS username. | ||
test_user_email = '[email protected]' | ||
test_user_password = 'secret' | ||
url = reverse('frontend_app_ecommerce:order_history') | ||
|
||
def setUp(self): | ||
"""Create test user before test starts.""" | ||
|
@@ -69,7 +70,7 @@ def test_view_rejects_post(self, _mock_ctorders, _mock_ecommerce_client): | |
self.client.login(username=self.test_user_username, password=self.test_user_password) | ||
|
||
# Perform POST | ||
response = self.client.post(reverse('frontend_app_ecommerce:order_history'), ORDER_HISTORY_GET_PARAMETERS) | ||
response = self.client.post(self.url, ORDER_HISTORY_GET_PARAMETERS) | ||
|
||
# Check 405 Method Not Allowed | ||
self.assertEqual(response.status_code, 405) | ||
|
@@ -78,7 +79,7 @@ def test_view_rejects_unauthorized(self, _mock_ctorders, _mock_ecommerce_client) | |
"""Check unauthorized users querying orders are redirected to login page.""" | ||
|
||
# Perform GET without logging in. | ||
response = self.client.get(reverse('frontend_app_ecommerce:order_history'), ORDER_HISTORY_GET_PARAMETERS) | ||
response = self.client.get(self.url, ORDER_HISTORY_GET_PARAMETERS) | ||
|
||
# Check 302 Found with redirect to login page. | ||
self.assertEqual(response.status_code, 302) | ||
|
@@ -91,7 +92,7 @@ def test_view_returns_ok(self, _mock_ctorders, _mock_ecommerce_client): | |
self.client.login(username=self.test_user_username, password=self.test_user_password) | ||
|
||
# Perform GET | ||
response = self.client.get(reverse('frontend_app_ecommerce:order_history'), ORDER_HISTORY_GET_PARAMETERS) | ||
response = self.client.get(self.url, ORDER_HISTORY_GET_PARAMETERS) | ||
# Check 200 OK | ||
self.assertEqual(response.status_code, 200) | ||
|
||
|
@@ -104,7 +105,7 @@ def test_view_returns_expected_ecommerce_response(self, is_redirect_mock, _mock_ | |
self.client.login(username=self.test_user_username, password=self.test_user_password) | ||
|
||
# Perform GET | ||
response = self.client.get(reverse('frontend_app_ecommerce:order_history'), ORDER_HISTORY_GET_PARAMETERS) | ||
response = self.client.get(self.url, ORDER_HISTORY_GET_PARAMETERS) | ||
|
||
# Check expected response | ||
self.assertEqual(response.json()['results'][1], ECOMMERCE_REQUEST_EXPECTED_RESPONSE['results'][0]) | ||
|
@@ -116,14 +117,33 @@ def test_view_passes_username(self, _mock_ctorders, mock_ecommerce_client): | |
self.client.login(username=self.test_user_username, password=self.test_user_password) | ||
|
||
# Perform GET | ||
self.client.get(reverse('frontend_app_ecommerce:order_history'), ORDER_HISTORY_GET_PARAMETERS) | ||
self.client.get(self.url, ORDER_HISTORY_GET_PARAMETERS) | ||
|
||
# Get username sent to ecommerce client | ||
request_username = mock_ecommerce_client.call_args.args[0]['username'] | ||
|
||
# Check username is passed to ecommerce client | ||
self.assertEqual(request_username, self.test_user_username) | ||
|
||
@patch( | ||
'commerce_coordinator.apps.commercetools.pipeline.GetCommercetoolsOrders.run_filter', | ||
side_effect=Exception('Something went wrong') | ||
) | ||
def test_view_crashes_with_some_error(self, _mock_pipeline, _mock_ctorders, _mock_ecommerce_client): | ||
"""Check exception is handled gracefully if pipeline crashes.""" | ||
|
||
# Login | ||
self.client.login(username=self.test_user_username, password=self.test_user_password) | ||
|
||
# Perform GET request | ||
response = self.client.get(self.url, ORDER_HISTORY_GET_PARAMETERS) | ||
|
||
# Assert the response status is 400 | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
# Assert the response content matches the error message | ||
self.assertEqual(response.data, 'Something went wrong!') | ||
|
||
|
||
@ddt.ddt | ||
class ReceiptRedirectViewTests(APITestCase): | ||
|
Oops, something went wrong.