Skip to content

Commit

Permalink
Merge f572740 into e9afa84
Browse files Browse the repository at this point in the history
  • Loading branch information
AmandaBirmingham committed Nov 10, 2020
2 parents e9afa84 + f572740 commit 3a02692
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 12 deletions.
9 changes: 9 additions & 0 deletions microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,12 @@ def send_email(body, token_info):
t.commit()

return '', 204


def get_daklapack_articles(token_info):
validate_admin_access(token_info)

with Transaction() as t:
admin_repo = AdminRepo(t)
dak_article_dicts = admin_repo.get_daklapack_articles()
return jsonify(dak_article_dicts), 200
38 changes: 27 additions & 11 deletions microsetta_private_api/admin/tests/test_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@
from microsetta_private_api.api.tests.test_api import client, MOCK_HEADERS, \
ACCT_ID_1, ACCT_MOCK_ISS, ACCT_MOCK_SUB, \
extract_last_id_from_location_header # noqa "client" IS used, by name
from microsetta_private_api.admin.tests.test_admin_repo import \
FIRST_DAKLAPACK_ARTICLE, delete_test_scan

DUMMY_PROJ_NAME = "test project"


def delete_test_scan(new_scan_id):
if new_scan_id is not None:
with Transaction() as t:
with t.cursor() as cur:
cur.execute("DELETE FROM barcode_scans "
"WHERE "
"barcode_scan_id = %s",
(new_scan_id,))
t.commit()


def teardown_test_data():
with Transaction() as t:
acct_repo = AccountRepo(t)
Expand Down Expand Up @@ -699,3 +690,28 @@ def test_scan_barcode_fail_invalid_status(self):
self.assertEqual(400, response.status_code)
finally:
delete_test_scan(new_scan_id)

def test_get_daklapack_articles(self):
with Transaction() as t:
admin_repo = AdminRepo(t)
article_dicts_list = admin_repo.get_daklapack_articles()
t.commit()

# execute articles get
response = self.client.get(
"/api/admin/daklapack_articles",
headers=MOCK_HEADERS
)

# check response code
self.assertEqual(200, response.status_code)

# load the response body
response_obj = json.loads(response.data)

# get the first article returned and pop out its id
first_article = response_obj[0]
first_article.pop("dak_article_id")

self.assertEqual(len(article_dicts_list), len(response_obj))
self.assertEqual(FIRST_DAKLAPACK_ARTICLE, response_obj[0])
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@
from microsetta_private_api.repo.admin_repo import AdminRepo
from microsetta_private_api.repo.transaction import Transaction
from microsetta_private_api.admin.admin_impl import validate_admin_access
from microsetta_private_api.admin.tests.test_admin_api import delete_test_scan

STANDARD_ACCT_ID = "12345678-bbbb-cccc-dddd-eeeeffffffff"
ADMIN_ACCT_ID = "12345678-1234-1234-1234-123412341234"
FIRST_DAKLAPACK_ARTICLE = {'dak_article_code': 350100,
'short_description': 'TMI 1 tube',
'num_2point5ml_etoh_tubes': 1,
'num_7ml_etoh_tube': 0,
'num_neoteryx_kit': 0,
'outer_sleeve': 'Microsetta',
'box': 'Microsetta',
'return_label': 'Microsetta',
'compartment_bag': 'Microsetta',
'num_stool_collector': 0,
'instructions': 'Fv1',
'registration_card': 'Microsetta',
'swabs': '1x bag of two',
'rigid_safety_bag': 'yes'}


def add_dummy_scan(scan_dict):
Expand All @@ -33,6 +46,17 @@ def add_dummy_scan(scan_dict):
t.commit()


def delete_test_scan(new_scan_id):
if new_scan_id is not None:
with Transaction() as t:
with t.cursor() as cur:
cur.execute("DELETE FROM barcode_scans "
"WHERE "
"barcode_scan_id = %s",
(new_scan_id,))
t.commit()


class AdminTests(TestCase):
def setUp(self):
AdminTests.setup_test_data()
Expand Down Expand Up @@ -681,3 +705,12 @@ def test_get_projects_inactive_wo_stats(self):
# output values are what we expect. Project 8 is now inactive,
# and is 2nd in (zero-based) list, after project 2
self.assertEqual(updated_dict, output[1].to_api())

def test_get_daklapack_articles(self):
with Transaction() as t:
admin_repo = AdminRepo(t)
articles = admin_repo.get_daklapack_articles()
self.assertEqual(24, len(articles))
first_article = articles[0]
first_article.pop("dak_article_id")
self.assertEqual(FIRST_DAKLAPACK_ARTICLE, first_article)
13 changes: 13 additions & 0 deletions microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,19 @@ paths:
'204':
description: Email sent

'/admin/daklapack_articles':
get:
operationId: microsetta_private_api.admin.admin_impl.get_daklapack_articles
tags:
- Admin
responses:
'200':
description: Return list of dictionaries of full info on all daklapack articles
content:
application/json:
schema:
type: array

components:
parameters:
# path parameters
Expand Down
48 changes: 48 additions & 0 deletions microsetta_private_api/db/patches/0071.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- add and fill daklapack_article table

-- create table barcodes.daklapack_article
CREATE TABLE barcodes.daklapack_article
(
dak_article_id uuid DEFAULT uuid_generate_v4() NOT NULL,
dak_article_code INTEGER NOT NULL,
short_description VARCHAR NOT NULL,
num_2point5ml_etoh_tubes INTEGER NOT NULL,
num_7ml_etoh_tube INTEGER NOT NULL,
num_neoteryx_kit INTEGER NOT NULL,
outer_sleeve VARCHAR NOT NULL,
box VARCHAR NOT NULL,
return_label VARCHAR NOT NULL,
compartment_bag VARCHAR NOT NULL,
num_stool_collector INTEGER NOT NULL,
instructions VARCHAR,
registration_card VARCHAR,
swabs VARCHAR,
rigid_safety_bag VARCHAR,
CONSTRAINT dak_article_pkey PRIMARY KEY (dak_article_id),
CONSTRAINT idx_dak_article_code UNIQUE (dak_article_code)
);

INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350100,'TMI 1 tube', '1', '0', '0', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '0', 'Fv1', 'Microsetta', '1x bag of two', 'yes');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350101,'TMI 1 tube + blood', '1', '0', '1', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '0', 'FV1 + BV1', '', '', '');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350102,'TMI 1 tube + 2 Blood', '1', '0', '1', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '0', 'FV1 + BV1', '', '', '');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350103,'TMI 2 tubes', '2', '0', '0', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '0', '3v1', 'Microsetta', '2x bag of two', 'yes');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350104,'TMI 2 tubes + Blood', '2', '0', '1', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '0', '3v1 + Bv1', 'Microsetta', '2x bag of two', 'yes');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350105,'TMI 2 tubes + 2 Blood', '2', '0', '2', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', '3v1 + Bv1', '', '2x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350106,'TMI 3 tubes', '3', '0', '0', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', '3v1', 'Microsetta', '3x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350107,'TMI 3 tubes + Blood', '3', '0', '1', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', '3v1 + Bv1', 'Microsetta', '3x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350108,'TMI 3 tubes + 2 Blood', '3', '0', '2', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', '3v1 + Bv1', '', '3x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350109,'TMI 4 tubes', '4', '0', '0', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', '4v1', 'Microsetta', '4x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350110,'TMI 4 tubes + Blood', '4', '0', '1', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', '4v1 + Bv1', 'Microsetta', '4x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350111,'TMI 4 tubes + 2 Blood', '4', '0', '2', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', '4v1 + Bv1', '', '4x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350112,'TMI 6 tubes + Blood', '6', '0', '1', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', 'TBD', 'Microsetta', '6x bag of two', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350200,'AGMP Tube', '0', '1', '0', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350201,'AGMP Tube + blood', '0', '1', '1', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350202,'AGMP Tube + 2 Blood', '0', '1', '1', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350203,'AGMP Tube + TMI Tube + blood', '1', '1', '1', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350204,'AGMP Tube + TMI Tube + 2 blood', '1', '1', '2', 'Microsetta', 'Microsetta', 'Microsetta', 'Microsetta', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350205,'2 AGMP Tube', '0', '2', '0', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350206,'2 AGMP Tube + blood', '0', '2', '1', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350207,'2 AGMP Tube + 2 blood', '0', '2', '2', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350208,'2 AGMP Tube + TMI Tube + blood', '1', '2', '1', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350209,'2 AGMP Tube + TMI tube + 2 blood', '1', '2', '2', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '1', 'TBD', '', '', 'no');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, num_2point5ml_etoh_tubes, num_7ml_etoh_tube, num_neoteryx_kit, outer_sleeve, box, return_label, compartment_bag, num_stool_collector, instructions, registration_card, swabs, rigid_safety_bag) VALUES (350210,'TMI 7 tubes', '7', '0', '0', 'Microsetta', 'Microsetta', 'Microsetta', '4 tubes', '0', 'FV1', 'Microsetta', '7x bag of two', 'no');
14 changes: 14 additions & 0 deletions microsetta_private_api/repo/admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,17 @@ def get_survey_metadata(self, sample_barcode, survey_template_id=None):
}

return pulldown

def get_daklapack_articles(self):
with self._transaction.dict_cursor() as cur:
cur.execute(
"SELECT dak_article_id, dak_article_code, short_description, "
"num_2point5ml_etoh_tubes, num_7ml_etoh_tube, "
"num_neoteryx_kit, outer_sleeve, box, return_label, "
"compartment_bag, num_stool_collector, instructions, "
"registration_card, swabs, rigid_safety_bag "
"FROM "
"barcodes.daklapack_article "
"ORDER BY daklapack_article.dak_article_code;")
rows = cur.fetchall()
return [dict(x) for x in rows]

0 comments on commit 3a02692

Please sign in to comment.