@@ -1487,3 +1487,137 @@ def test_update_perk_fulfillment_state(self):
1487
1487
)
1488
1488
obs = cur .fetchone ()
1489
1489
self .assertFalse (obs [0 ])
1490
+
1491
+ def test_get_barcodes_filter_kit_ids_success (self ):
1492
+ with Transaction () as t :
1493
+ setup_sql = """
1494
+ INSERT INTO barcodes.kit (kit_id, box_id)
1495
+ VALUES ('test1', '0001e15f-4170-4b28-b111-191cd567c347');
1496
+
1497
+ INSERT INTO barcodes.barcode (barcode, kit_id)
1498
+ VALUES ('00001234', 'test1');
1499
+ """
1500
+ with t .cursor () as cur :
1501
+ cur .execute (setup_sql )
1502
+
1503
+ admin_repo = AdminRepo (t )
1504
+
1505
+ barcodes = admin_repo .get_barcodes_filter (kit_ids = ['test1' ])
1506
+ self .assertEqual (barcodes , ['00001234' ])
1507
+
1508
+ def test_get_barcodes_filter_kit_ids_failure (self ):
1509
+ with Transaction () as t :
1510
+ admin_repo = AdminRepo (t )
1511
+ barcodes = admin_repo .get_barcodes_filter (kit_ids = ['notarealkit' ])
1512
+ self .assertEqual (barcodes , [])
1513
+
1514
+ def test_get_barcodes_filter_emails_success (self ):
1515
+ with Transaction () as t :
1516
+ setup_sql = """
1517
+ INSERT INTO ag.source (id, account_id,
1518
+ source_type, source_name)
1519
+ VALUES ('0003ddfd-4949-4105-90a9-1b1530af5352', %s,
1520
+ 'Human', 'Test Source');
1521
+ INSERT INTO barcodes.kit (kit_id, box_id)
1522
+ VALUES ('test1', '0001e15f-4170-4b28-b111-191cd567c347');
1523
+ INSERT INTO barcodes.barcode (barcode, kit_id)
1524
+ VALUES ('00001234', 'test1');
1525
+ INSERT INTO ag.ag_kit_barcodes (barcode, source_id)
1526
+ VALUES ('00001234', '0003ddfd-4949-4105-90a9-1b1530af5352');
1527
+ """
1528
+ with t .cursor () as cur :
1529
+ cur .execute (setup_sql , (STANDARD_ACCT_ID ,))
1530
+
1531
+ admin_repo = AdminRepo (t )
1532
+
1533
+ barcodes = admin_repo .
get_barcodes_filter (
emails = [
'[email protected] ' ])
1534
+ self .assertEqual (barcodes , ['00001234' ])
1535
+
1536
+ def test_get_barcodes_filter_emails_failure (self ):
1537
+ with Transaction () as t :
1538
+ admin_repo = AdminRepo (t )
1539
+ barcodes = admin_repo .get_barcodes_filter (
1540
+
1541
+ self .assertEqual (barcodes , [])
1542
+
1543
+ def test_get_barcodes_filter_outbound_tracking_success (self ):
1544
+ with Transaction () as t :
1545
+ setup_sql = """
1546
+ INSERT INTO barcodes.kit (kit_id, box_id,
1547
+ outbound_fedex_tracking)
1548
+ VALUES ('test1', '0001e15f-4170-4b28-b111-191cd567c347',
1549
+ '12345');
1550
+ INSERT INTO barcodes.barcode (barcode, kit_id)
1551
+ VALUES ('00001234', 'test1');
1552
+ """
1553
+ with t .cursor () as cur :
1554
+ cur .execute (setup_sql )
1555
+
1556
+ admin_repo = AdminRepo (t )
1557
+
1558
+ barcodes = \
1559
+ admin_repo .get_barcodes_filter (
1560
+ outbound_tracking_numbers = ['12345' ])
1561
+ self .assertEqual (barcodes , ['00001234' ])
1562
+
1563
+ def test_get_barcodes_filter_outbound_tracking_failure (self ):
1564
+ with Transaction () as t :
1565
+ admin_repo = AdminRepo (t )
1566
+ barcodes = admin_repo .get_barcodes_filter (
1567
+ outbound_tracking_numbers = ['99999' ])
1568
+ self .assertEqual (barcodes , [])
1569
+
1570
+ def test_get_barcodes_filter_inbound_tracking_success (self ):
1571
+ with Transaction () as t :
1572
+ setup_sql = """
1573
+ INSERT INTO barcodes.kit (kit_id, box_id,
1574
+ inbound_fedex_tracking)
1575
+ VALUES ('test1', '0001e15f-4170-4b28-b111-191cd567c347',
1576
+ '67890');
1577
+ INSERT INTO barcodes.barcode (barcode, kit_id)
1578
+ VALUES ('00001234', 'test1');
1579
+ """
1580
+ with t .cursor () as cur :
1581
+ cur .execute (setup_sql )
1582
+
1583
+ admin_repo = AdminRepo (t )
1584
+
1585
+ barcodes = admin_repo .get_barcodes_filter (
1586
+ inbound_tracking_numbers = ['67890' ])
1587
+ self .assertEqual (barcodes , ['00001234' ])
1588
+
1589
+ def test_get_barcodes_filter_inbound_tracking_failure (self ):
1590
+ with Transaction () as t :
1591
+ admin_repo = AdminRepo (t )
1592
+ barcodes = admin_repo .get_barcodes_filter (
1593
+ inbound_tracking_numbers = ['99999' ])
1594
+ self .assertEqual (barcodes , [])
1595
+
1596
+ def test_get_kit_by_barcode_success (self ):
1597
+ with Transaction () as t :
1598
+ setup_sql = """
1599
+ INSERT INTO barcodes.kit (kit_id, box_id)
1600
+ VALUES ('test1', '0001e15f-4170-4b28-b111-191cd567c348');
1601
+
1602
+ INSERT INTO barcodes.barcode (barcode, kit_id)
1603
+ VALUES ('00001234', 'test1');
1604
+ """
1605
+ with t .cursor () as cur :
1606
+ cur .execute (setup_sql )
1607
+
1608
+ admin_repo = AdminRepo (t )
1609
+
1610
+ kit_info = admin_repo .get_kit_by_barcode (['00001234' ])
1611
+ expected = [{
1612
+ 'barcode' : '00001234' ,
1613
+ 'outbound_tracking' : None ,
1614
+ 'inbound_tracking' : None ,
1615
+ 'kit_id' : 'test1'
1616
+ }]
1617
+ self .assertEqual (kit_info , expected )
1618
+
1619
+ def test_get_kit_by_barcode_failure (self ):
1620
+ with Transaction () as t :
1621
+ admin_repo = AdminRepo (t )
1622
+ kit_info = admin_repo .get_kit_by_barcode (['nonexistent_barcode' ])
1623
+ self .assertIsNone (kit_info )
0 commit comments