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

extend display of info after daklapack order submission #84

Merged
merged 2 commits into from
Sep 27, 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
9 changes: 7 additions & 2 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 = order_submissions = headers = None
error_message = success_submissions = failure_submissions = headers = None
expected_headers = ["firstName", "lastName", "address1", "insertion",
"address2", "postalCode", "city", "state",
"country", "countryCode"]
Expand Down Expand Up @@ -806,11 +806,16 @@ def return_error(msg):
error_message = post_output
else:
order_submissions = post_output["order_submissions"]
success_submissions = [x for x in order_submissions if
x["order_success"]]
failure_submissions = [x for x in order_submissions if not
x["order_success"]]

return render_template('submit_daklapack_order.html',
**build_login_variables(),
error_message=error_message,
order_submissions=order_submissions)
success_submissions=success_submissions,
failure_submissions=failure_submissions)


@app.route('/authrocket_callback')
Expand Down
43 changes: 31 additions & 12 deletions microsetta_admin/templates/submit_daklapack_order.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ <h3>Submit Daklapack Order</h3>
{{ error_message }}
{% endautoescape %}

{% elif order_submissions %}
{% elif success_submissions or failure_submissions %}
{% if failure_submissions|length > 0 %}
<p>
{{ order_submissions|length }} total order(s) were input.
</p>
<p>
The following orders were not successfully submitted to Daklapack.
The following orders were NOT successfully submitted to Daklapack.
Please correct any errors and then re-submit.
</p>
<table>
<table border="1">
<thead>
<tr>
<th>Address</th>
Expand All @@ -79,17 +77,38 @@ <h3>Submit Daklapack Order</h3>
</tr>
</thead>
<tbody>
{% for curr_order_submission in order_submissions %}
{% if curr_order_submission['order_success'] == False %}
{% for curr_submission in failure_submissions %}
<tr>
<td>{{ curr_submission['order_address'] }}</td>
<td>{{ curr_submission['daklapack_api_error_code'] }}</td>
<td>{{ curr_submission['daklapack_api_error_msg'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}

{% if success_submissions|length > 0 %}
<p>
The following orders were successfully submitted to Daklapack.
</p>
<table border="1">
<thead>
<tr>
<th>Address</th>
<th>Order Id</th>
</tr>
</thead>
<tbody>
{% for curr_submission in success_submissions %}
<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>
<td>{{ curr_submission['order_address'] }}</td>
<td>{{ curr_submission['order_id'] }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endif %}

{% else %}

Expand Down
6 changes: 4 additions & 2 deletions microsetta_admin/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,10 @@ def test_post_submit_daklapack_order_success(self):
self.mock_post.side_effect = [api_post_1]

response = self._test_post_submit_daklapack_order()
self.assertIn(b'Daklapack Error Code', response.data)
self.assertIn(b'2 total order(s) were input.', response.data)
self.assertIn(b'The following orders were NOT successfully submitted '
b'to Daklapack.', response.data)
self.assertIn(b'The following orders were successfully submitted '
b'to Daklapack', response.data)

def test_post_submit_daklapack_order_fail_api(self):
# server side issues one POST to the API
Expand Down