@@ -549,6 +549,7 @@ def test_validate__call(mocker):
549
549
550
550
del os .environ ["PGHOST" ]
551
551
552
+
552
553
def test_validate__call_throws_validation_error (mocker ):
553
554
os .environ ["PGHOST" ] = "localhost"
554
555
@@ -610,19 +611,24 @@ def test_validate__call_throws_validation_error(mocker):
610
611
prompt = "Hello world!" ,
611
612
)
612
613
613
- assert response == ('Test guard validation error' , 400 )
614
+ assert response == (
615
+ {"status_code" : 400 , "detail" : "Test guard validation error" },
616
+ 400 ,
617
+ )
614
618
615
619
del os .environ ["PGHOST" ]
616
620
621
+
617
622
def test_openai_v1_chat_completions__raises_404 (mocker ):
618
623
from guardrails_api .blueprints .guards import openai_v1_chat_completions
624
+
619
625
os .environ ["PGHOST" ] = "localhost"
620
626
mock_guard = None
621
627
622
628
mock_request = MockRequest (
623
629
"POST" ,
624
630
json = {
625
- "messages" : [{"role" :"user" , "content" :"Hello world!" }],
631
+ "messages" : [{"role" : "user" , "content" : "Hello world!" }],
626
632
},
627
633
headers = {"x-openai-api-key" : "mock-key" },
628
634
)
@@ -637,15 +643,16 @@ def test_openai_v1_chat_completions__raises_404(mocker):
637
643
638
644
response = openai_v1_chat_completions ("My%20Guard's%20Name" )
639
645
assert response [1 ] == 404
640
- assert response [0 ]["message" ] == 'NotFound'
641
-
646
+ assert response [0 ]["message" ] == "NotFound"
642
647
643
648
mock_get_guard .assert_called_once_with ("My Guard's Name" )
644
649
645
650
del os .environ ["PGHOST" ]
646
651
652
+
647
653
def test_openai_v1_chat_completions__call (mocker ):
648
654
from guardrails_api .blueprints .guards import openai_v1_chat_completions
655
+
649
656
os .environ ["PGHOST" ] = "localhost"
650
657
mock_guard = MockGuardStruct ()
651
658
mock_outcome = ValidationOutcome (
@@ -664,7 +671,7 @@ def test_openai_v1_chat_completions__call(mocker):
664
671
mock_request = MockRequest (
665
672
"POST" ,
666
673
json = {
667
- "messages" : [{"role" :"user" , "content" :"Hello world!" }],
674
+ "messages" : [{"role" : "user" , "content" : "Hello world!" }],
668
675
},
669
676
headers = {"x-openai-api-key" : "mock-key" },
670
677
)
@@ -687,7 +694,7 @@ def test_openai_v1_chat_completions__call(mocker):
687
694
)
688
695
mock_status .return_value = "fail"
689
696
mock_call = Call ()
690
- mock_call .iterations = Stack (Iteration (' some-id' , 1 ))
697
+ mock_call .iterations = Stack (Iteration (" some-id" , 1 ))
691
698
mock_guard .history = Stack (mock_call )
692
699
693
700
response = openai_v1_chat_completions ("My%20Guard's%20Name" )
@@ -698,7 +705,7 @@ def test_openai_v1_chat_completions__call(mocker):
698
705
699
706
mock___call__ .assert_called_once_with (
700
707
num_reasks = 0 ,
701
- messages = [{"role" :"user" , "content" :"Hello world!" }],
708
+ messages = [{"role" : "user" , "content" : "Hello world!" }],
702
709
)
703
710
704
711
assert response == {
@@ -716,4 +723,4 @@ def test_openai_v1_chat_completions__call(mocker):
716
723
},
717
724
}
718
725
719
- del os .environ ["PGHOST" ]
726
+ del os .environ ["PGHOST" ]
0 commit comments