diff --git a/src/caselawclient/factories.py b/src/caselawclient/factories.py index 650e9ab9..0bf7acb6 100644 --- a/src/caselawclient/factories.py +++ b/src/caselawclient/factories.py @@ -1,6 +1,6 @@ import datetime from typing import Any, Optional, cast -from unittest.mock import Mock, patch +from unittest.mock import Mock from typing_extensions import TypeAlias @@ -63,10 +63,8 @@ def build( api_client = Mock(spec=MarklogicApiClient) api_client.get_judgment_xml_bytestring.return_value = DEFAULT_DOCUMENT_BODY_XML.encode(encoding="utf-8") - with patch.object(cls.target_class, "content_as_html") as mock_content_as_html: - mock_content_as_html.return_value = html - document = cls.target_class(uri, api_client=api_client) - + document = cls.target_class(uri, api_client=api_client) + document.content_as_html = Mock(return_value=html) # type: ignore[method-assign] document.body = kwargs.pop("body") if "body" in kwargs else DocumentBodyFactory.build() for param_name, default_value in cls.PARAMS_MAP.items(): diff --git a/tests/test_factories.py b/tests/test_factories.py new file mode 100644 index 00000000..35b95115 --- /dev/null +++ b/tests/test_factories.py @@ -0,0 +1,6 @@ +from caselawclient.factories import DocumentFactory + + +def test_content_as_html(): + doc = DocumentFactory.build() + assert doc.content_as_html() == "

This is a judgment.

"