Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daklapack one order per address #81

Merged
merged 4 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions microsetta_admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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

Expand All @@ -805,22 +802,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}</p>" \
f"<p>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')
Expand Down
34 changes: 28 additions & 6 deletions microsetta_admin/templates/submit_daklapack_order.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,34 @@ <h3>Submit Daklapack Order</h3>
{{ error_message }}
{% endautoescape %}

{% elif success_message %}
{% autoescape false %}
<div class="success">
<p>{{ success_message }}</p>
</div>
{% endautoescape %}
{% elif order_submissions %}
<p>
{{ order_submissions|length }} total order(s) were input.
</p>
<p>
The following orders were not successfully submitted to Daklapack.
Please correct any errors and then re-submit.
</p>
<table>
<thead>
<tr>
<th>Address</th>
<th>Daklapack Error Code</th>
<th>Daklapack Error Message</th>
</tr>
</thead>
<tbody>
{% for curr_order_submission in order_submissions %}
{% if curr_order_submission['order_success'] == False %}
<tr>
<td>{{ curr_order_submission['order_address'] }}</td>
<td>{{ curr_order_submission['daklapack_api_error_code'] }}</td>
<td>{{ curr_order_submission['daklapack_api_error_msg'] }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>

{% else %}

Expand Down
50 changes: 37 additions & 13 deletions microsetta_admin/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,22 +496,46 @@ 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
Expand Down