def test_scan_barcode_success(self): with Transaction() as t: # TODO FIXME HACK: Need to build mock barcodes rather than using # these fixed ones TEST_BARCODE = '000000001' TEST_STATUS = "sample-has-inconsistencies" TEST_NOTES = "THIS IS A UNIT TEST" admin_repo = AdminRepo(t) # check that before doing a scan, no scans are recorded for this diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE) self.assertEqual(len(diag['scans_info']), 0) # do a scan admin_repo.scan_barcode(TEST_BARCODE, { "sample_status": TEST_STATUS, "technician_notes": TEST_NOTES }) # show that now a scan is recorded for this barcode diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE) self.assertEqual(len(diag['scans_info']), 1) first_scan = diag['scans_info'][0] self.assertEqual(first_scan['technician_notes'], TEST_NOTES) self.assertEqual(first_scan['sample_status'], TEST_STATUS)
def test_scan_barcode_error_nonexistent(self): with Transaction() as t: admin_repo = AdminRepo(t) with self.assertRaises(NotFound): admin_repo.scan_barcode("THIZIZNOTAREALBARCODEISWARE", { "sample_status": "Abc", "technician_notes": "123" }) self.fail("Shouldn't get here")
def scan_barcode(token_info, sample_barcode, body): validate_admin_access(token_info) with Transaction() as t: admin_repo = AdminRepo(t) admin_repo.scan_barcode(sample_barcode, body) t.commit() response = flask.Response() response.status_code = 201 response.headers['Location'] = '/api/admin/search/samples/%s' % \ sample_barcode return response
def test_scan_barcode(self): with Transaction() as t: # TODO FIXME HACK: Need to build mock barcodes rather than using # these fixed ones TEST_BARCODE = '000000001' TEST_STATUS = "sample-has-inconsistencies" TEST_NOTES = "THIS IS A UNIT TEST" admin_repo = AdminRepo(t) diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE) prestatus = diag['barcode_info']['status'] admin_repo.scan_barcode( TEST_BARCODE, { "sample_status": TEST_STATUS, "technician_notes": TEST_NOTES } ) diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE) self.assertEqual(diag['barcode_info']['technician_notes'], TEST_NOTES) self.assertEqual(diag['barcode_info']['sample_status'], TEST_STATUS) self.assertEqual(diag['barcode_info']['status'], prestatus) with self.assertRaises(NotFound): admin_repo.scan_barcode( "THIZIZNOTAREALBARCODEISWARE", { "sample_status": "Abc", "technician_notes": "123" } ) self.fail("Shouldn't get here")