# ********************************************************************************
# *         WARNING: This file is automatically generated by unasync.py.         *
# *                             DO NOT MANUALLY EDIT                             *
# *     Source File: patent_client/_async/uspto/global_dossier/model_test.py     *
# ********************************************************************************

import pytest

from .model import Document, DocumentList, GlobalDossier, GlobalDossierApplication


class TestGlobalDossier:
    def test_us_lookup(self):
        result = GlobalDossier.objects.get("16123456")
        assert result.id == "16123456"

    def test_us_lookup_docs(self):
        dossier = GlobalDossier.objects.get("16123456")
        result = dossier.applications[0].document_list
        assert len(result.office_action_docs) >= 2

    @pytest.mark.skip("issue in pytest-recording")
    def test_us_download_docs(self, tmpdir):
        dossier = GlobalDossier.objects.get("16123456")
        result = dossier.applications[0].documents[0].download(tmpdir)
        assert result.exists()

    def test_us_app_lookup(self):
        result = GlobalDossierApplication.objects.get("16123456")
        assert result.app_num == "16123456"
        assert isinstance(result, GlobalDossierApplication)

    def test_us_app_lookup_docs(self):
        result = GlobalDossierApplication.objects.get("16123456")
        document_list = result.document_list
        documents = result.documents
        office_actions = result.office_actions
        assert isinstance(document_list, DocumentList)
        assert isinstance(documents, list)
        assert isinstance(documents[0], Document)
        assert isinstance(office_actions, list)
        assert isinstance(office_actions[0], Document)

    def test_links(self):
        app = GlobalDossierApplication.objects.get("16123456")
        us_application = app.us_application
        assert (
            us_application.patent_title
            == "LEARNING ASSISTANCE DEVICE, METHOD OF OPERATING LEARNING ASSISTANCE DEVICE, LEARNING ASSISTANCE PROGRAM, LEARNING ASSISTANCE SYSTEM, AND TERMINAL DEVICE"
        )
        # Broken links to Public Patent Search
        # assert (
        #    GlobalDossierApplication.objects.get("16123456").us_publication.patent_title
        #    == "Learning assistance device, method of operating learning assistance device, learning assistance program, learning assistance system, and terminal device"
        # )
        # assert (
        #    GlobalDossierApplication.objects.get("16123456").us_patent.patent_title
        #    == "Learning assistance device, method of operating learning assistance device, learning assistance program, learning assistance system, and terminal device"
        # )
        assignments = app.us_assignments
        assert (assignments.first()).id == "46816-108"
        with pytest.raises(ValueError):
            (GlobalDossierApplication.objects.get(publication="EP1000000")).us_application
        # Broken links to Public Patent Search
        # with pytest.raises(ValueError):
        #    GlobalDossierApplication.objects.get(publication="EP1000000").us_publication
        # with pytest.raises(ValueError):
        #    GlobalDossierApplication.objects.get(publication="EP1000000").us_patent
        with pytest.raises(ValueError):
            (GlobalDossierApplication.objects.get(publication="EP1000000")).us_assignments

    def test_issue_99(self):
        app = GlobalDossierApplication.objects.get("16740760", type="application", office="US")
        assert app.app_num == "16740760"
        app = GlobalDossierApplication.objects.get("17193105")
        assert app.app_num == "17193105"
