Skip to content

Commit

Permalink
Merge pull request #90 from biocore/dak_shipping_provider
Browse files Browse the repository at this point in the history
Open up shipping provider and shipping type for daklapack orders
  • Loading branch information
cassidysymons authored Aug 23, 2022
2 parents 1ba6787 + de45244 commit ad92b1f
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 77 deletions.
12 changes: 11 additions & 1 deletion microsetta_admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ def return_error(msg):
**build_login_variables(),
error_message=msg)

status, dak_shipping_type_by_provider = APIRequest.get(
'/api/admin/daklapack_shipping')
if status >= 400:
return return_error("Unable to load daklapack shipping information.")

status, dak_articles_output = APIRequest.get(
'/api/admin/daklapack_articles')
if status >= 400:
Expand All @@ -860,6 +865,7 @@ def return_error(msg):
error_message=None,
dummy_status=DUMMY_SELECT_TEXT,
dak_articles=dak_articles_output,
dak_shipping=dak_shipping_type_by_provider,
contact_phone_number=SERVER_CONFIG[
"order_contact_phone"],
projects=projects_output['projects'])
Expand All @@ -884,10 +890,12 @@ def return_error(msg):
article_quantity = int(request.form['quantity'])
file = request.files['addresses_file']

shipping_provider = request.form.get('dak_shipping_provider')
shipping_type = request.form.get('dak_shipping_type')

# get optional fields or defaults
planned_send_str = request.form.get('planned_send_date')
planned_send_date = planned_send_str if planned_send_str else None

description = request.form.get('description')
fedex_ref_1 = request.form.get('fedex_ref_1')
fedex_ref_2 = request.form.get('fedex_ref_2')
Expand Down Expand Up @@ -927,6 +935,8 @@ def return_error(msg):
"article_code": dak_article_code,
"quantity": article_quantity,
"addresses": addresses_list,
"shipping_provider": shipping_provider,
"shipping_type": shipping_type,
"planned_send_date": planned_send_date,
"description": description,
"fedex_ref_1": fedex_ref_1,
Expand Down
62 changes: 53 additions & 9 deletions microsetta_admin/templates/submit_daklapack_order.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

{% block head %}

{% if not dak_shipping %}
{% set dak_shipping = {} %}
{% endif %}

<style type="text/css">
.extended-width {
width: 600px;
Expand All @@ -18,15 +22,34 @@
<script src="/static/vendor/js/jquery.validate.min.js"></script>
<script src="/static/vendor/js/additional-methods.min.js"></script>
<script>
function verifyQuantity(){
let quantity = $("#quantity").val();
let verified = true;
if (quantity > 1) {
let confirmMsg = 'Do you really want to send ' + quantity + ' articles to every address in your list?';
verified = window.confirm(confirmMsg);
}
return verified;
var DAK_SHIPPING = {{ dak_shipping|tojson }};

function makeNewOption(val, txt) {
return $("<option></option>").attr("value", val).text(txt);
}

function replaceShippingTypeOptions(shippingProvider){
let selected_provider = shippingProvider.value;
let new_options = DAK_SHIPPING[selected_provider];
let dropdown_elm = $("#dak_shipping_type");
dropdown_elm.empty();

dropdown_elm.append(makeNewOption("", '{{ dummy_status }}'));

$.each(new_options, function(index, value) {
dropdown_elm.append(makeNewOption(value, value));
});
}

function verifyQuantity(){
let quantity = $("#quantity").val();
let verified = true;
if (quantity > 1) {
let confirmMsg = 'Do you really want to send ' + quantity + ' articles to every address in your list?';
verified = window.confirm(confirmMsg);
}
return verified;
}

$(document).ready(function(){
// Adapted from https://stackoverflow.com/a/5812341
Expand Down Expand Up @@ -80,7 +103,7 @@
// of an input field. Validation rules are defined
// on the right side
projects: "required",
dak_article: "required",
dak_article_code: "required",
quantity: {
required: true,
digits: true,
Expand All @@ -90,6 +113,8 @@
//NB: validation is NOT applied to "hidden" inputs.
// However, if this is ever changed to user-facing,
// this should validate it ;)
dak_shipping_provider: "required",
dak_shipping_type: "required",
contact_phone_number: {
phoneUS: true,
required: true
Expand Down Expand Up @@ -205,6 +230,25 @@ <h3>Submit Daklapack Order</h3>
<input type="file" name="addresses_file" id="addresses_file" />
</div>
</div>
<div class="form-group row">
<label for="dak_shipping_provider" class="control-label col-sm-4">Shipping Provider</label>
<div class="col-sm-8">
<select name="dak_shipping_provider" id="dak_shipping_provider" onchange="replaceShippingTypeOptions(this);">
<option value="">{{ dummy_status }}</option>
{% for dak_shipping_provider in dak_shipping %}
<option value="{{ dak_shipping_provider }}">{{ dak_shipping_provider }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group row">
<label for="dak_shipping_type" class="control-label col-sm-4">Shipping Type</label>
<div class="col-sm-8">
<select name="dak_shipping_type" id="dak_shipping_type">
<option value="">{{ dummy_status }}</option>
</select>
</div>
</div>
<hr />
<p>
<strong>Optionals:</strong>
Expand Down
129 changes: 62 additions & 67 deletions microsetta_admin/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,38 @@
'fedex_ref_3': '',
'addresses_file': None}

DAK_SHIPPING = {'FedEx': ['Default', 'FEDEX_2_DAY', 'FEDEX_GROUND',
'PRIORITY_OVERNIGHT', 'STANDARD_OVERNIGHT'],
'Freight': ['Default'],
'TransSmart': ['Default'],
'USPS': ['PRIORITY_EXPRESS', 'PRIORITY', 'FIRST_CLASS']}
DAK_ARTICLE = {'dak_article_code': '3510000E',
'short_description': 'TMI 1 tube',
'detailed_description': 'TMI 1 tube, American English'}
A_PROJECT = {'project_name': 'test_proj', 'is_microsetta': True,
'bank_samples': False, 'plating_start_date': None,
'contact_name': 'Jane Doe',
'contact_email': '[email protected]',
'additional_contact_name': 'John Doe',
'deadlines': 'Spring 2021', 'num_subjects': 'Variable',
'num_timepoints': '4', 'start_date': 'Fall 2020',
'disposition_comments': 'Store', 'collection': 'AGP',
'is_fecal': 'X', 'is_saliva': '', 'is_skin': '?',
'is_blood': 'X', 'is_other': 'Nares, mouth',
'do_16s': '', 'do_shallow_shotgun': 'Subset',
'do_shotgun': 'X', 'do_rt_qpcr': '', 'do_serology': '',
'do_metatranscriptomics': 'X', 'do_mass_spec': 'X',
'mass_spec_comments': 'Dorrestein',
'mass_spec_contact_name': 'Ted Doe',
'mass_spec_contact_email': '[email protected]',
'do_other': '',
'branding_associated_instructions': 'branding_doc.pdf',
'branding_status': 'In Review',
'subproject_name': 'IBL SIBL',
'alias': 'Healthy Sitting', 'sponsor': 'Crowdfunded',
'coordination': 'TMI', 'is_active': True,
'project_id': 8}


class DummyResponse(object):
def __init__(self, status_code, output_dict):
Expand Down Expand Up @@ -368,75 +400,40 @@ def test_manage_projects_fail(self):
self.assertIn(b'Unable to load project list', response.data)

def test_get_submit_daklapack_order_success(self):
# server side issues two GETs to the API
dak_article = {'dak_article_code': '3510000E',
'short_description': 'TMI 1 tube',
'detailed_description': 'TMI 1 tube, American English'}

a_project = {'project_name': 'test_proj', 'is_microsetta': True,
'bank_samples': False, 'plating_start_date': None,
'contact_name': 'Jane Doe',
'contact_email': '[email protected]',
'additional_contact_name': 'John Doe',
'deadlines': 'Spring 2021', 'num_subjects': 'Variable',
'num_timepoints': '4', 'start_date': 'Fall 2020',
'disposition_comments': 'Store', 'collection': 'AGP',
'is_fecal': 'X', 'is_saliva': '', 'is_skin': '?',
'is_blood': 'X', 'is_other': 'Nares, mouth',
'do_16s': '', 'do_shallow_shotgun': 'Subset',
'do_shotgun': 'X', 'do_rt_qpcr': '', 'do_serology': '',
'do_metatranscriptomics': 'X', 'do_mass_spec': 'X',
'mass_spec_comments': 'Dorrestein',
'mass_spec_contact_name': 'Ted Doe',
'mass_spec_contact_email': '[email protected]',
'do_other': '',
'branding_associated_instructions': 'branding_doc.pdf',
'branding_status': 'In Review',
'subproject_name': 'IBL SIBL',
'alias': 'Healthy Sitting', 'sponsor': 'Crowdfunded',
'coordination': 'TMI', 'is_active': True,
'project_id': 8}

api_get_1 = DummyResponse(200, [dak_article])
api_get_2 = DummyResponse(200, [a_project])
self.mock_get.side_effect = [api_get_1, api_get_2]
# server side issues three GETs to the API
api_get_1 = DummyResponse(200, DAK_SHIPPING)
api_get_2 = DummyResponse(200, [DAK_ARTICLE])
api_get_3 = DummyResponse(200, [A_PROJECT])
self.mock_get.side_effect = [api_get_1, api_get_2, api_get_3]

response = self.app.get('/submit_daklapack_order',
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertIn(b'<strong>Optionals:</strong>', response.data)

def test_get_submit_daklapack_order_fail_shipping(self):
dak_shipping = {'error_msg': 'hit a problem'}

# server side issues three GETs to the API
api_get_1 = DummyResponse(400, dak_shipping)
api_get_2 = DummyResponse(200, [DAK_ARTICLE])
api_get_3 = DummyResponse(200, [A_PROJECT])
self.mock_get.side_effect = [api_get_1, api_get_2, api_get_3]

response = self.app.get('/submit_daklapack_order',
follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertIn(b'Unable to load daklapack shipping information.',
response.data)

def test_get_submit_daklapack_order_fail_articles(self):
# server side issues two GETs to the API
dak_article = {'error_msg': 'hit a problem'}

a_project = {'project_name': 'test_proj', 'is_microsetta': True,
'bank_samples': False, 'plating_start_date': None,
'contact_name': 'Jane Doe',
'contact_email': '[email protected]',
'additional_contact_name': 'John Doe',
'deadlines': 'Spring 2021', 'num_subjects': 'Variable',
'num_timepoints': '4', 'start_date': 'Fall 2020',
'disposition_comments': 'Store', 'collection': 'AGP',
'is_fecal': 'X', 'is_saliva': '', 'is_skin': '?',
'is_blood': 'X', 'is_other': 'Nares, mouth',
'do_16s': '', 'do_shallow_shotgun': 'Subset',
'do_shotgun': 'X', 'do_rt_qpcr': '', 'do_serology': '',
'do_metatranscriptomics': 'X', 'do_mass_spec': 'X',
'mass_spec_comments': 'Dorrestein',
'mass_spec_contact_name': 'Ted Doe',
'mass_spec_contact_email': '[email protected]',
'do_other': '',
'branding_associated_instructions': 'branding_doc.pdf',
'branding_status': 'In Review',
'subproject_name': 'IBL SIBL',
'alias': 'Healthy Sitting', 'sponsor': 'Crowdfunded',
'coordination': 'TMI', 'is_active': True,
'project_id': 8}

api_get_1 = DummyResponse(400, [dak_article])
api_get_2 = DummyResponse(200, [a_project])
self.mock_get.side_effect = [api_get_1, api_get_2]
# server side issues three GETs to the API
api_get_1 = DummyResponse(200, DAK_SHIPPING)
api_get_2 = DummyResponse(400, [dak_article])
api_get_3 = DummyResponse(200, [A_PROJECT])
self.mock_get.side_effect = [api_get_1, api_get_2, api_get_3]

response = self.app.get('/submit_daklapack_order',
follow_redirects=True)
Expand All @@ -445,15 +442,13 @@ def test_get_submit_daklapack_order_fail_articles(self):
response.data)

def test_get_submit_daklapack_order_fail_projects(self):
# server side issues two GETs to the API
dak_article = {'dak_article_code': '3510000E',
'short_description': 'TMI 1 tube',
'detailed_description': 'TMI 1 tube, American English'}
a_project = {'error_message': 'no projects for you'}

api_get_1 = DummyResponse(200, [dak_article])
api_get_2 = DummyResponse(400, [a_project])
self.mock_get.side_effect = [api_get_1, api_get_2]
# server side issues three GETs to the API
api_get_1 = DummyResponse(200, DAK_SHIPPING)
api_get_2 = DummyResponse(200, [DAK_ARTICLE])
api_get_3 = DummyResponse(400, [a_project])
self.mock_get.side_effect = [api_get_1, api_get_2, api_get_3]

response = self.app.get('/submit_daklapack_order',
follow_redirects=True)
Expand Down

0 comments on commit ad92b1f

Please sign in to comment.