8
8
from fastapi .testclient import TestClient
9
9
from argowrapper .constants import *
10
10
from test .constants import EXAMPLE_AUTH_HEADER
11
- from argowrapper .routes .routes import router , check_user_reached_monthly_workflow_cap
12
- from argowrapper .constants import GEN3_NON_VA_WORKFLOW_MONTHLY_CAP
11
+ from argowrapper .routes .routes import (
12
+ router ,
13
+ check_user_monthly_workflow_cap ,
14
+ get_user_monthly_workflow ,
15
+ )
16
+ from argowrapper .constants import (
17
+ GEN3_NON_VA_WORKFLOW_MONTHLY_CAP ,
18
+ GEN3_DEFAULT_WORKFLOW_MONTHLY_CAP ,
19
+ )
13
20
14
21
variables = [
15
22
{"variable_type" : "concept" , "concept_id" : "2000000324" },
@@ -110,13 +117,13 @@ def test_submit_workflow(client):
110
117
) as mock_check_billing_id , patch (
111
118
"requests.get"
112
119
) as mock_requests , patch (
113
- "argowrapper.routes.routes.check_user_reached_monthly_workflow_cap "
120
+ "argowrapper.routes.routes.check_user_monthly_workflow_cap "
114
121
) as mock_check_monthly_cap :
115
122
mock_auth .return_value = True
116
123
mock_engine .return_value = "workflow_123"
117
124
mock_check_billing_id .return_value = None , None
118
125
mock_requests .side_effect = mocked_requests_get
119
- mock_check_monthly_cap .return_value = False
126
+ mock_check_monthly_cap .return_value = 1 , 3
120
127
121
128
response = client .post (
122
129
"/submit" ,
@@ -558,9 +565,9 @@ def test_submit_workflow_with_user_billing_id(client):
558
565
data ["user_tags" ] = {"tags" : {"othertag1" : "tag1" , "billing_id" : "1234" }}
559
566
560
567
with patch (
561
- "argowrapper.routes.routes.check_user_reached_monthly_workflow_cap "
568
+ "argowrapper.routes.routes.check_user_monthly_workflow_cap "
562
569
) as mock_check_monthly_cap :
563
- mock_check_monthly_cap .return_value = False
570
+ mock_check_monthly_cap .return_value = 1 , 3
564
571
response = client .post (
565
572
"/submit" ,
566
573
data = json .dumps (data ),
@@ -584,7 +591,7 @@ def test_submit_workflow_with_user_billing_id(client):
584
591
assert response .status_code == 500
585
592
586
593
587
- def test_check_user_reached_monthly_workflow_cap ():
594
+ def test_check_user_monthly_workflow_cap ():
588
595
headers = {
589
596
"Content-Type" : "application/json" ,
590
597
"Authorization" : EXAMPLE_AUTH_HEADER ,
@@ -600,16 +607,14 @@ def test_check_user_reached_monthly_workflow_cap():
600
607
601
608
# Test Under Default Limit
602
609
assert (
603
- check_user_reached_monthly_workflow_cap (
604
- headers ["Authorization" ], None , None
605
- )
606
- == False
610
+ check_user_monthly_workflow_cap (headers ["Authorization" ], None , None ) == 2 ,
611
+ GEN3_NON_VA_WORKFLOW_MONTHLY_CAP ,
607
612
)
608
613
609
614
# Test Custom Limit
610
615
assert (
611
- check_user_reached_monthly_workflow_cap (headers ["Authorization" ], None , 2 )
612
- == True
616
+ check_user_monthly_workflow_cap (headers ["Authorization" ], None , 2 ) == 2 ,
617
+ 2 ,
613
618
)
614
619
615
620
# Test Billing Id User Exceeding Limit
@@ -619,10 +624,9 @@ def test_check_user_reached_monthly_workflow_cap():
619
624
mock_get_workflow .return_value = workflows
620
625
621
626
assert (
622
- check_user_reached_monthly_workflow_cap (
623
- headers ["Authorization" ], "1234" , None
624
- )
625
- == True
627
+ check_user_monthly_workflow_cap (headers ["Authorization" ], "1234" , None )
628
+ == GEN3_NON_VA_WORKFLOW_MONTHLY_CAP + 1 ,
629
+ GEN3_NON_VA_WORKFLOW_MONTHLY_CAP ,
626
630
)
627
631
628
632
# Test VA User Exceeding Limit
@@ -631,10 +635,9 @@ def test_check_user_reached_monthly_workflow_cap():
631
635
workflows .append ({"wf_name" : "workflow" + str (index )})
632
636
mock_get_workflow .return_value = workflows
633
637
assert (
634
- check_user_reached_monthly_workflow_cap (
635
- headers ["Authorization" ], None , None
636
- )
637
- == True
638
+ check_user_monthly_workflow_cap (headers ["Authorization" ], None , None )
639
+ == GEN3_DEFAULT_WORKFLOW_MONTHLY_CAP + 1 ,
640
+ GEN3_DEFAULT_WORKFLOW_MONTHLY_CAP ,
638
641
)
639
642
640
643
@@ -646,14 +649,14 @@ def test_submit_workflow_with_billing_id_and_over_monthly_cap(client):
646
649
) as mock_log , patch (
647
650
"argowrapper.routes.routes.check_user_info_for_billing_id_and_workflow_limit"
648
651
) as mock_check_billing_id , patch (
649
- "argowrapper.routes.routes.check_user_reached_monthly_workflow_cap "
652
+ "argowrapper.routes.routes.check_user_monthly_workflow_cap "
650
653
) as mock_check_monthly_cap , patch (
651
654
"requests.get"
652
655
) as mock_requests :
653
656
mock_auth .return_value = True
654
657
mock_engine .return_value = "workflow_123"
655
658
mock_check_billing_id .return_value = "1234" , None
656
- mock_check_monthly_cap .return_value = True
659
+ mock_check_monthly_cap .return_value = 1 , 1
657
660
mock_requests .side_effect = mocked_requests_get
658
661
659
662
response = client .post (
@@ -675,14 +678,14 @@ def test_submit_workflow_over_monthly_cap(client):
675
678
) as mock_log , patch (
676
679
"argowrapper.routes.routes.check_user_info_for_billing_id_and_workflow_limit"
677
680
) as mock_check_billing_id , patch (
678
- "argowrapper.routes.routes.check_user_reached_monthly_workflow_cap "
681
+ "argowrapper.routes.routes.check_user_monthly_workflow_cap "
679
682
) as mock_check_monthly_cap , patch (
680
683
"requests.get"
681
684
) as mock_requests :
682
685
mock_auth .return_value = True
683
686
mock_engine .return_value = "workflow_123"
684
687
mock_check_billing_id .return_value = None , None
685
- mock_check_monthly_cap .return_value = True
688
+ mock_check_monthly_cap .return_value = 1 , 1
686
689
mock_requests .side_effect = mocked_requests_get
687
690
688
691
response = client .post (
@@ -722,3 +725,52 @@ def test_submit_workflow_with_non_team_project_cohort(client):
722
725
},
723
726
)
724
727
assert response .status_code == 400
728
+
729
+
730
+ def test_get_user_monthly_workflow (client ):
731
+ with patch (
732
+ "argowrapper.engine.argo_engine.ArgoEngine.get_user_workflows_for_current_month"
733
+ ) as mock_get_workflow , patch (
734
+ "argowrapper.routes.routes.check_user_info_for_billing_id_and_workflow_limit"
735
+ ) as mock_check_billing_id :
736
+ mock_get_workflow .return_value = [
737
+ {"wf_name" : "workflow1" },
738
+ {"wf_name" : "workflow2" },
739
+ ]
740
+ mock_check_billing_id .return_value = None , None
741
+
742
+ response = client .get (
743
+ "/workflows/user-monthly" ,
744
+ headers = {
745
+ "Content-Type" : "application/json" ,
746
+ "Authorization" : EXAMPLE_AUTH_HEADER ,
747
+ },
748
+ )
749
+
750
+ assert response .status_code == 200
751
+ assert response .content .decode (
752
+ "utf-8"
753
+ ) == '{{"workflow_run":2,"workflow_limit":{}}}' .format (
754
+ GEN3_DEFAULT_WORKFLOW_MONTHLY_CAP
755
+ )
756
+
757
+ mock_get_workflow .return_value = [
758
+ {"wf_name" : "workflow1" },
759
+ {"wf_name" : "workflow2" },
760
+ {"wf_name" : "workflow3" },
761
+ ]
762
+ mock_check_billing_id .return_value = "1234" , None
763
+
764
+ response = client .get (
765
+ "/workflows/user-monthly" ,
766
+ headers = {
767
+ "Content-Type" : "application/json" ,
768
+ "Authorization" : EXAMPLE_AUTH_HEADER ,
769
+ },
770
+ )
771
+
772
+ assert response .content .decode (
773
+ "utf-8"
774
+ ) == '{{"workflow_run":3,"workflow_limit":{}}}' .format (
775
+ GEN3_NON_VA_WORKFLOW_MONTHLY_CAP
776
+ )
0 commit comments