From 3ce0993b56c57afe64e179542523f9e27711eff4 Mon Sep 17 00:00:00 2001 From: AmandaBirmingham Date: Tue, 7 Sep 2021 13:59:01 -0700 Subject: [PATCH 1/3] change code, template to anticipate a list of order submission statuses, rather than just one. --- microsetta_admin/server.py | 15 +++------ .../templates/submit_daklapack_order.html | 31 +++++++++++++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/microsetta_admin/server.py b/microsetta_admin/server.py index a689bba..315fad4 100644 --- a/microsetta_admin/server.py +++ b/microsetta_admin/server.py @@ -744,7 +744,7 @@ def return_error(msg): **build_login_variables(), error_message=msg) - error_message = success_message = headers = None + error_message = order_submissions = headers = None expected_headers = ["firstName", "lastName", "address1", "insertion", "address2", "postalCode", "city", "state", "country", "countryCode"] @@ -805,22 +805,15 @@ def return_error(msg): ) # if the post failed, keep track of the error so it can be displayed - if status != 201: + if status != 200: error_message = post_output else: - order_id = post_output.get("order_id") - success_message = f"Order {order_id } submitted." - - if not post_output.get("email_success"): - success_message = f"{success_message}

" \ - f"

HOWEVER, fulfillment hold" \ - f" email could NOT be sent. Contact Daklapack" \ - f" manually to initiate order hold!" + order_submissions = post_output["order_submissions"] return render_template('submit_daklapack_order.html', **build_login_variables(), error_message=error_message, - success_message=success_message) + order_submissions=order_submissions) @app.route('/authrocket_callback') diff --git a/microsetta_admin/templates/submit_daklapack_order.html b/microsetta_admin/templates/submit_daklapack_order.html index 100a1ee..078a7fb 100644 --- a/microsetta_admin/templates/submit_daklapack_order.html +++ b/microsetta_admin/templates/submit_daklapack_order.html @@ -62,12 +62,31 @@

Submit Daklapack Order

{{ error_message }} {% endautoescape %} -{% elif success_message %} -{% autoescape false %} -
-

{{ success_message }}

-
-{% endautoescape %} +{% elif order_submissions %} +

+The following orders were not successfully submitted to Daklapack. +Please correct any errors and then re-submit. +

+ + + + + + + + + + {% for curr_order_submission in order_submissions %} + {% if curr_order_submission['order_success'] == False %} + + + + + + {% endif %} + {% endfor %} + +
AddressDaklapack Error CodeDaklapack Error Message
{{ curr_order_submission['order_address'] }}{{ curr_order_submission['daklapack_api_error_code'] }}{{ curr_order_submission['daklapack_api_error_msg'] }}
{% else %} From b4cee94f1945a8ae1cd343fe338ee1e00fd9091a Mon Sep 17 00:00:00 2001 From: AmandaBirmingham Date: Tue, 7 Sep 2021 14:47:49 -0700 Subject: [PATCH 2/3] update tests for multiple orders --- microsetta_admin/server.py | 3 -- .../templates/submit_daklapack_order.html | 3 ++ microsetta_admin/tests/test_routes.py | 49 ++++++++++++++----- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/microsetta_admin/server.py b/microsetta_admin/server.py index 315fad4..7a8a20c 100644 --- a/microsetta_admin/server.py +++ b/microsetta_admin/server.py @@ -780,9 +780,6 @@ def return_error(msg): f"not match expected column names" f" {expected_headers}") - # TODO: discuss: where/how should validation that addresses - # meet FedEx rules happen? - # add (same) contact phone number to every address addresses_df['phone'] = phone_number diff --git a/microsetta_admin/templates/submit_daklapack_order.html b/microsetta_admin/templates/submit_daklapack_order.html index 078a7fb..384092f 100644 --- a/microsetta_admin/templates/submit_daklapack_order.html +++ b/microsetta_admin/templates/submit_daklapack_order.html @@ -64,6 +64,9 @@

Submit Daklapack Order

{% elif order_submissions %}

+{{ order_submissions|length }} total order(s) were input. +

+

The following orders were not successfully submitted to Daklapack. Please correct any errors and then re-submit.

diff --git a/microsetta_admin/tests/test_routes.py b/microsetta_admin/tests/test_routes.py index 299a76f..ce429a9 100644 --- a/microsetta_admin/tests/test_routes.py +++ b/microsetta_admin/tests/test_routes.py @@ -496,22 +496,45 @@ def _test_post_submit_daklapack_order(self, addresses_filename=None): def test_post_submit_daklapack_order_success(self): # server side issues one POST to the API - api_post_1 = DummyResponse(201, {'order_id': '11211', - 'email_success': None}) - self.mock_post.side_effect = [api_post_1] - - response = self._test_post_submit_daklapack_order() - self.assertIn(b'Order 11211 submitted.', response.data) - - def test_post_submit_daklapack_order_success_but_email_fail(self): - # server side issues one POST to the API - api_post_1 = DummyResponse(201, {'order_id': '11211', - 'email_success': False}) + api_post_1 = DummyResponse( + 200, + {'order_submissions': + [{'order_id': '11211', + 'order_address': {'address1': '123 Main St', + 'address2': '', + 'city': 'San Diego', + 'companyName': 'Dan H', + 'country': 'USA', + 'countryCode': 'us', + 'firstName': 'Jane', + 'insertion': 'Apt 2', + 'lastName': 'Doe', + 'phone': '(858) 555-1212', + 'postalCode': '92210', + 'state': 'CA'}, + 'order_success': True}, + {'order_id': '11212', + 'daklapack_api_error_code': 409, + 'daklapack_api_error_msg': 'Got 409', + 'order_address': {'address1': '29 Side St', + 'address2': 'Kew Gardens', + 'city': 'Gananoque', + 'companyName': 'Dan H', + 'country': 'Canada', + 'countryCode': 'ca', + 'firstName': 'Tom', + 'insertion': '', + 'lastName': 'Thumb', + 'phone': '(858) 555-1212', + 'postalCode': 'KG7-448', + 'state': 'Ontario'}, + 'order_success': False}]} + ) self.mock_post.side_effect = [api_post_1] response = self._test_post_submit_daklapack_order() - self.assertIn(b'Order 11211 submitted.', response.data) - self.assertIn(b'HOWEVER, fulfillment hold', response.data) + self.assertIn(b'Daklapack Error Code', response.data) + self.assertIn(b'2 total order(s) were input.', response.data) def test_post_submit_daklapack_order_fail_api(self): # server side issues one POST to the API From da9665c1eb3371415337c3b2b4f9a6718f5235c8 Mon Sep 17 00:00:00 2001 From: AmandaBirmingham Date: Tue, 7 Sep 2021 14:56:02 -0700 Subject: [PATCH 3/3] lint fixes --- microsetta_admin/tests/test_routes.py | 63 ++++++++++++++------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/microsetta_admin/tests/test_routes.py b/microsetta_admin/tests/test_routes.py index ce429a9..ce61e31 100644 --- a/microsetta_admin/tests/test_routes.py +++ b/microsetta_admin/tests/test_routes.py @@ -499,37 +499,38 @@ def test_post_submit_daklapack_order_success(self): api_post_1 = DummyResponse( 200, {'order_submissions': - [{'order_id': '11211', - 'order_address': {'address1': '123 Main St', - 'address2': '', - 'city': 'San Diego', - 'companyName': 'Dan H', - 'country': 'USA', - 'countryCode': 'us', - 'firstName': 'Jane', - 'insertion': 'Apt 2', - 'lastName': 'Doe', - 'phone': '(858) 555-1212', - 'postalCode': '92210', - 'state': 'CA'}, - 'order_success': True}, - {'order_id': '11212', - 'daklapack_api_error_code': 409, - 'daklapack_api_error_msg': 'Got 409', - 'order_address': {'address1': '29 Side St', - 'address2': 'Kew Gardens', - 'city': 'Gananoque', - 'companyName': 'Dan H', - 'country': 'Canada', - 'countryCode': 'ca', - 'firstName': 'Tom', - 'insertion': '', - 'lastName': 'Thumb', - 'phone': '(858) 555-1212', - 'postalCode': 'KG7-448', - 'state': 'Ontario'}, - 'order_success': False}]} - ) + [ + {'order_id': '11211', + 'order_address': {'address1': '123 Main St', + 'address2': '', + 'city': 'San Diego', + 'companyName': 'Dan H', + 'country': 'USA', + 'countryCode': 'us', + 'firstName': 'Jane', + 'insertion': 'Apt 2', + 'lastName': 'Doe', + 'phone': '(858) 555-1212', + 'postalCode': '92210', + 'state': 'CA'}, + 'order_success': True}, + {'order_id': '11212', + 'daklapack_api_error_code': 409, + 'daklapack_api_error_msg': 'Got 409', + 'order_address': {'address1': '29 Side St', + 'address2': 'Kew Gardens', + 'city': 'Gananoque', + 'companyName': 'Dan H', + 'country': 'Canada', + 'countryCode': 'ca', + 'firstName': 'Tom', + 'insertion': '', + 'lastName': 'Thumb', + 'phone': '(858) 555-1212', + 'postalCode': 'KG7-448', + 'state': 'Ontario'}, + 'order_success': False}]} + ) self.mock_post.side_effect = [api_post_1] response = self._test_post_submit_daklapack_order()