@@ -549,6 +549,7 @@ def test_validate__call(mocker):
549549
550550 del os .environ ["PGHOST" ]
551551
552+
552553def test_validate__call_throws_validation_error (mocker ):
553554 os .environ ["PGHOST" ] = "localhost"
554555
@@ -610,19 +611,24 @@ def test_validate__call_throws_validation_error(mocker):
610611 prompt = "Hello world!" ,
611612 )
612613
613- assert response == ('Test guard validation error' , 400 )
614+ assert response == (
615+ {"status_code" : 400 , "detail" : "Test guard validation error" },
616+ 400 ,
617+ )
614618
615619 del os .environ ["PGHOST" ]
616620
621+
617622def test_openai_v1_chat_completions__raises_404 (mocker ):
618623 from guardrails_api .blueprints .guards import openai_v1_chat_completions
624+
619625 os .environ ["PGHOST" ] = "localhost"
620626 mock_guard = None
621627
622628 mock_request = MockRequest (
623629 "POST" ,
624630 json = {
625- "messages" : [{"role" :"user" , "content" :"Hello world!" }],
631+ "messages" : [{"role" : "user" , "content" : "Hello world!" }],
626632 },
627633 headers = {"x-openai-api-key" : "mock-key" },
628634 )
@@ -637,15 +643,16 @@ def test_openai_v1_chat_completions__raises_404(mocker):
637643
638644 response = openai_v1_chat_completions ("My%20Guard's%20Name" )
639645 assert response [1 ] == 404
640- assert response [0 ]["message" ] == 'NotFound'
641-
646+ assert response [0 ]["message" ] == "NotFound"
642647
643648 mock_get_guard .assert_called_once_with ("My Guard's Name" )
644649
645650 del os .environ ["PGHOST" ]
646651
652+
647653def test_openai_v1_chat_completions__call (mocker ):
648654 from guardrails_api .blueprints .guards import openai_v1_chat_completions
655+
649656 os .environ ["PGHOST" ] = "localhost"
650657 mock_guard = MockGuardStruct ()
651658 mock_outcome = ValidationOutcome (
@@ -664,7 +671,7 @@ def test_openai_v1_chat_completions__call(mocker):
664671 mock_request = MockRequest (
665672 "POST" ,
666673 json = {
667- "messages" : [{"role" :"user" , "content" :"Hello world!" }],
674+ "messages" : [{"role" : "user" , "content" : "Hello world!" }],
668675 },
669676 headers = {"x-openai-api-key" : "mock-key" },
670677 )
@@ -687,7 +694,7 @@ def test_openai_v1_chat_completions__call(mocker):
687694 )
688695 mock_status .return_value = "fail"
689696 mock_call = Call ()
690- mock_call .iterations = Stack (Iteration (' some-id' , 1 ))
697+ mock_call .iterations = Stack (Iteration (" some-id" , 1 ))
691698 mock_guard .history = Stack (mock_call )
692699
693700 response = openai_v1_chat_completions ("My%20Guard's%20Name" )
@@ -698,7 +705,7 @@ def test_openai_v1_chat_completions__call(mocker):
698705
699706 mock___call__ .assert_called_once_with (
700707 num_reasks = 0 ,
701- messages = [{"role" :"user" , "content" :"Hello world!" }],
708+ messages = [{"role" : "user" , "content" : "Hello world!" }],
702709 )
703710
704711 assert response == {
@@ -716,4 +723,4 @@ def test_openai_v1_chat_completions__call(mocker):
716723 },
717724 }
718725
719- del os .environ ["PGHOST" ]
726+ del os .environ ["PGHOST" ]
0 commit comments