55import logging
66
77from django .test import TestCase
8- from mock import patch
98from django .urls import reverse
9+ from mock import patch
1010
1111from .clients import EcommerceApiClient
1212
13+ # from pprint import pp
14+
15+
1316logger = 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
1676class 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."""
0 commit comments