Skip to content

Commit a94398c

Browse files
author
Diane Kaplan
committed
fix: review feedback- move sample response out into readable block, and refer to it from clients.py
1 parent aa94dad commit a94398c

File tree

4 files changed

+65
-31
lines changed

4 files changed

+65
-31
lines changed

commerce_coordinator/apps/orders/clients.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,8 @@ def get_orders(self, query_params):
5050
Returns:
5151
dict: Dictionary represention of JSON returned from API
5252
53-
example response:
54-
{
55-
{"count": 1, "next": null, "previous": null, "results": [{"billing_address": {"first_name":
56-
"Diane", "last_name": "Test", "line1": "50 turner st", "line2": "", "postcode": "02135",
57-
"state": "MA", "country": "US", "city": "Brighton"}, "currency": "USD", "date_placed":
58-
"2021-12-20T15:09:44Z", "discount": "0", "lines": [{"title": "Seat in edX Demonstration
59-
Course with verified certificate (and ID verification)", "quantity": 1, "description":
60-
"Seat in edX Demonstration Course with verified certificate (and ID verification)", "status":
61-
"Complete", "line_price_excl_tax": "149.00", "unit_price_excl_tax": "149.00", "product":
62-
{"id": 3, "url": "http://localhost:18130/api/v2/products/3/", "structure": "child",
63-
"product_class": "Seat", "title": "Seat in edX Demonstration Course with verified certificate
64-
(and ID verification)", "price": "149.00", "expires": "2022-11-08T22:54:30.777313Z",
65-
"attribute_values": [{"name": "certificate_type", "code": "certificate_type", "value":
66-
"verified"}, {"name": "course_key", "code": "course_key", "value":
67-
"course-v1:edX+DemoX+Demo_Course"}, {"name": "id_verification_required", "code":
68-
"id_verification_required", "value": true}], "is_available_to_buy": true, "stockrecords":
69-
[{"id": 3, "product": 3, "partner": 1, "partner_sku": "8CF08E5", "price_currency": "USD",
70-
"price_excl_tax": "149.00"}]}}], "number": "EDX-100004", "payment_processor":
71-
"cybersource-rest", "status": "Complete", "total_excl_tax": "149.00", "user":
72-
{"email": "[email protected]", "username": "edx"}, "vouchers": []} ]}
73-
}
53+
See sample response in tests.py
54+
7455
"""
7556
try:
7657
endpoint = self.api_base_url + 'orders/'

commerce_coordinator/apps/orders/tests.py

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,72 @@
55
import logging
66

77
from django.test import TestCase
8-
from mock import patch
98
from django.urls import reverse
9+
from mock import patch
1010

1111
from .clients import EcommerceApiClient
1212

13+
# from pprint import pp
14+
15+
1316
logger = logging.getLogger(__name__)
17+
sample_response = {'count': 1,
18+
'results': [{'billing_address': {'city': 'Brighton',
19+
'country': 'US',
20+
'first_name': 'Diane',
21+
'last_name': 'Test',
22+
'line1': '50 turner st',
23+
'line2': '',
24+
'postcode': '02135',
25+
'state': 'MA'},
26+
'currency': 'USD',
27+
'date_placed': '2021-12-20T15:09:44Z',
28+
'discount': '0',
29+
'lines': [{'description': 'Seat in edX '
30+
'Demonstration Course with verified '
31+
'certificate (and ID verification)',
32+
'line_price_excl_tax': '149.00',
33+
'product': {'attribute_values': [{'code': 'certificate_type',
34+
'name': 'certificate_type',
35+
'value': 'verified'},
36+
{'code': 'course_key',
37+
'name': 'course_key',
38+
'value': 'course-v1:\
39+
edX+DemoX+Demo_Course'},
40+
{'code': 'id_verification_required',
41+
'name': 'id_verification_required',
42+
'value': True}],
43+
'expires': '2022-11-08T22:54:30.777313Z',
44+
'id': 3,
45+
'is_available_to_buy': True,
46+
'price': '149.00',
47+
'product_class': 'Seat',
48+
'stockrecords': [{'id': 3,
49+
'partner': 1,
50+
'partner_sku': '8CF08E5',
51+
'price_currency': 'USD',
52+
'price_excl_tax': '149.00',
53+
'product': 3}],
54+
'structure': 'child',
55+
'title': 'Seat in edX Demonstration '
56+
'Course '
57+
'with verified certificate (and '
58+
'ID '
59+
'verification)',
60+
'url': 'http://localhost:18130/api/v2/'
61+
'products/3/'},
62+
'quantity': 1,
63+
'status': 'Complete',
64+
'title': 'Seat in edX Demonstration '
65+
'Course with verified certificate (and ID '
66+
'verification)',
67+
'unit_price_excl_tax': '149.00'}],
68+
'number': 'EDX-100004',
69+
'payment_processor': 'cybersource-rest',
70+
'status': 'Complete',
71+
'total_excl_tax': '149.00',
72+
'user': {'email': '[email protected]', 'username': 'edx'},
73+
'vouchers': []}]}
1474

1575

1676
class OrderRetrievalTests(TestCase):
@@ -28,24 +88,20 @@ def __init__(self, **kwargs):
2888
self.__dict__ = kwargs
2989

3090
# mock response from ecommerce orders API
31-
self.test_response = TestResponse(**{
32-
'count': 1,
33-
'results': [{"billing_address": {"first_name": "Diane", "last_name": "Test", "line1": "50 turner st", "line2": "", "postcode": "02135", "state": "MA", "country": "US", "city": "Brighton"}, "currency": "USD", "date_placed": "2021-12-20T15:09:44Z", "discount": "0", "lines": [{"title": "Seat in edX Demonstration Course with verified certificate (and ID verification)", "quantity": 1, "description": "Seat in edX Demonstration Course with verified certificate (and ID verification)", "status": "Complete", "line_price_excl_tax": "149.00", "unit_price_excl_tax": "149.00", "product": {"id": 3, "url": "http://localhost:18130/api/v2/products/3/", "structure": "child", "product_class": "Seat", "title": "Seat in edX Demonstration Course with verified certificate (and ID verification)", "price": "149.00", "expires": "2022-11-08T22:54:30.777313Z", "attribute_values": [{"name": "certificate_type", "code": "certificate_type", "value": "verified"}, {"name": "course_key", "code": "course_key", "value": "course-v1:edX+DemoX+Demo_Course"}, {"name": "id_verification_required", "code": "id_verification_required", "value": True}], "is_available_to_buy": True, "stockrecords": [{"id": 3, "product": 3, "partner": 1, "partner_sku": "8CF08E5", "price_currency": "USD", "price_excl_tax": "149.00"}]}}], "number": "EDX-100004", "payment_processor": "cybersource-rest", "status": "Complete", "total_excl_tax": "149.00", "user": {"email": "[email protected]", "username": "edx"}, "vouchers": []}] # pylint: disable=line-too-long # nopep8
34-
})
91+
self.test_response = TestResponse(**sample_response)
3592

3693
@patch('commerce_coordinator.apps.orders.clients.EcommerceApiClient.get_orders')
3794
def test_EcommerceApiClient(self, mock_response):
3895
"""We can call the EcommerceApiClient successfully."""
3996

4097
mock_response.return_value = self.test_response
4198
params = {'username': 'TestUser', "page": 1, "page_size": 20}
42-
expected_result = {'count': 1, 'results': [{"billing_address": {"first_name": "Diane", "last_name": "Test", "line1": "50 turner st", "line2": "", "postcode": "02135", "state": "MA", "country": "US", "city": "Brighton"}, "currency": "USD", "date_placed": "2021-12-20T15:09:44Z", "discount": "0", "lines": [{"title": "Seat in edX Demonstration Course with verified certificate (and ID verification)", "quantity": 1, "description": "Seat in edX Demonstration Course with verified certificate (and ID verification)", "status": "Complete", "line_price_excl_tax": "149.00", "unit_price_excl_tax": "149.00", "product": {"id": 3, "url": "http://localhost:18130/api/v2/products/3/", "structure": "child", "product_class": "Seat", "title": "Seat in edX Demonstration Course with verified certificate (and ID verification)", "price": "149.00", "expires": "2022-11-08T22:54:30.777313Z", "attribute_values": [{"name": "certificate_type", "code": "certificate_type", "value": "verified"}, {"name": "course_key", "code": "course_key", "value": "course-v1:edX+DemoX+Demo_Course"}, {"name": "id_verification_required", "code": "id_verification_required", "value": True}], "is_available_to_buy": True, "stockrecords": [{"id": 3, "product": 3, "partner": 1, "partner_sku": "8CF08E5", "price_currency": "USD", "price_excl_tax": "149.00"}]}}], "number": "EDX-100004", "payment_processor": "cybersource-rest", "status": "Complete", "total_excl_tax": "149.00", "user": {"email": "[email protected]", "username": "edx"}, "vouchers": []}]} # pylint: disable=line-too-long # nopep8
4399

44100
# Call the new function (EcommerceApiClient().get_orders(params)), mocking the response
45101
ecommerce_api_client = EcommerceApiClient()
46102
ecommerce_response = ecommerce_api_client.get_orders(params)
47103

48-
self.assertEqual(expected_result, ecommerce_response.__dict__)
104+
self.assertEqual(sample_response, ecommerce_response.__dict__)
49105

50106
# def test_ecommerce_view(self):
51107
# """We can call get_user_orders__ecommerce successfully."""

commerce_coordinator/apps/orders/views.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ def get_user_orders__ecommerce(request):
1919
page_size = request.GET['page_size']
2020
params = {'username': username, "page": page, "page_size": page_size}
2121

22-
logger.info(f'DKTEST: get_user_orders__ecommerce called with params: {params}.')
23-
2422
ecommerce_api_client = EcommerceApiClient()
2523
ecommerce_response = ecommerce_api_client.get_orders(params)
2624

commerce_coordinator/settings/local.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
INSTALLED_APPS += (
66
'commerce_coordinator.apps.demo_lms.apps.LmsConfig',
7-
# 'commerce_coordinator.apps.orders.apps.OrdersConfig',
87
)
98

109
# CACHE CONFIGURATION

0 commit comments

Comments
 (0)