New paste Repaste Download
open_ai_meta_mock = <MagicMock name='invoke' id='140204985401744'>
anthropic_ai_mock = <MagicMock name='invoke' id='140204982062960'>
open_ai_classification_mock = <AsyncMock name='ainvoke' id='140204983627648'>
project_type = "['Document Drafting']"
contract_type_id = 'c723a3775c27405d8c54a939687b6d52'
file_input = 'consulting_agreement.docx', expected = 200
work_flow_cache = {'contract_type': 'a92b97a72f874344adb3846cb161478c', 'functions': {'redline': {'platform': {'function_id': '0ee40bf69..., ...]}}}, 'new_user_id': '0a55ac84b44e4887b209ae741401f2ad', 'permission_id': '74f69564af3c48238439b44573665033', ...}
client = <FlaskClient <Flask 'app'>>
tokens = {'access_token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTcxODEwNDQ3NCwianRpIjoiNGNhNTZiNjE...HB4bFhIaHZPY292a00yRzVNUENJbk9GdncxbklZRlplSlpGdXF6ajZLajBMdEV4V3JVcz0ifQ.HjUWLv9s7OMXJVFRT-OpsLmSDkTz6oKuU2MqpwGCjno'}
    @pytest.mark.parametrize(
        "project_type,contract_type_id,file_input,expected",
        [
            (
                "['Document Drafting']",
                "c723a3775c27405d8c54a939687b6d52",
                "consulting_agreement.docx",
                200,
            ),
            (
                "['Document Redraft', 'Document Extraction', 'Document Drafting']",
                "8a8f6e1f4b9344dfa348bb323916c93e",
                "template_sample_nda.docx",
                200,
            ),
            pytest.param(
                "['Document Drafting']",
                "8a8f6e1f4b9344dfa348bb323916c93e",
                "test.txt",
                422,
            ),
            pytest.param(
                "Document Drafting",
                "8a8f6e1f4b9344dfa348bb323916c93e",
                "test.txt",
                422,
            ),
            pytest.param(
                "Document Drafting",
                "8a8f6e1f4b9344dfa348bb323916c93e",
                "template_sample_nda.docx",
                422,
            ),
        ],
    )
    # @mock.patch("utils.LLM.model.ChatOpenAI.with_fallbacks")
    @mock.patch("utils.LLM.model.ChatOpenAI.ainvoke")
    @mock.patch("utils.LLM.model.ChatAnthropic.invoke")
    @mock.patch("utils.LLM.model.ChatOpenAI.invoke")
    def test_template_upload(
        open_ai_meta_mock,
        anthropic_ai_mock,
        open_ai_classification_mock,
        project_type,
        contract_type_id,
        file_input,
        expected,
        work_flow_cache,
        client: FlaskClient,
        tokens: Dict[str, str],
    
    ):
        with open(
            Path(__file__).parent / "test_data/test_langchain_data.json", encoding="utf-8"
        ) as lang_fp:
            openai_sample = json.load(lang_fp)
            ai_data = openai_sample["upload"]
            openai_metadata = ai_data["template"]["open_ai"]["metadata"]
            anthropic_metadata = ai_data["template"]["anthropic"]["key_term_specification"]
            clause = ai_data["template"]["open_ai"]["clause"]
            mock_open_ai = mock.MagicMock(name="openai__call__").return_value
    
            if "Document Redraft" in project_type:
                openai_metadata["party_metadata"][0].update(
                    {
                        "mapped_model": "NDA Unilateral - Disclosing Party Model",
                        "mapped_model_id": work_flow_cache["functions"]["redline"][
                            "platform"
                        ]["model_id"],
                        "reasoning": "Test description",
                    }
                )
                openai_metadata["party_metadata"][1].update(
                    {
                        "mapped_model": "NDA Unilateral - Disclosing Party Model",
                        "mapped_model_id": work_flow_cache["functions"]["redline"][
                            "platform"
                        ]["model_id"],
                        "reasoning": "Test description",
                    }
                )
            mock_open_ai.content = json.dumps(openai_metadata)
            open_ai_meta_mock.return_value = mock_open_ai
            open_ai_classification_mock.return_value = mock.MagicMock(name="ainvoke", content= json.dumps(clause))
            mock_anthropic_ai = mock.MagicMock(name="anthropic__call__").return_value
            mock_anthropic_ai.content = anthropic_metadata
            anthropic_ai_mock.return_value = mock_anthropic_ai
    
        token = tokens["access_token"]
        with open(Path(__file__).parent / f"documents/{file_input}", "rb") as document:
            result = client.post(
                path="/v1/upload_template",
                data={
                    "file": (document, file_input),
                    "contract_type_id": contract_type_id,
                    "project_type": project_type,
                },
                headers={"Authorization": f"Bearer {token}"},
            )
>       assert result.status_code == expected
E       assert 422 == 200
E        +  where 422 = <WrapperTestResponse streamed [422 UNPROCESSABLE ENTITY]>.status_code
tests/test_12_template_upload.py:109: AssertionError
Filename: None. Size: 5kb. View raw, , hex, or download this file.

This paste expires on 2024-06-18 11:14:50.384691. Pasted through deprecated-web.