Skip to content

refactor(cl): refactored factories #5953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cl/alerts/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from factory.fuzzy import FuzzyChoice

from cl.alerts.models import Alert, DocketAlert
from cl.search.factories import DocketParentMixin
from cl.search.factories import DocketFactory
from cl.users.factories import UserFactory


Expand All @@ -20,10 +20,10 @@ class Meta:
)


class DocketAlertWithParentsFactory(DocketAlertFactory, DocketParentMixin):
class DocketAlertWithParentsFactory(DocketAlertFactory):
"""Make an alert on a particular docket"""

pass
docket = SubFactory(DocketFactory)


class AlertFactory(DjangoModelFactory):
Expand Down
2 changes: 1 addition & 1 deletion cl/alerts/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def setUp(self) -> None:
RECAPDocument.objects.create(
docket_entry=de,
document_type=RECAPDocument.PACER_DOCUMENT,
document_number=1,
document_number="1",
pacer_doc_id="232322332",
is_available=False,
)
Expand Down
42 changes: 21 additions & 21 deletions cl/alerts/tests/tests_recap_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from cl.search.factories import (
BankruptcyInformationFactory,
CitationWithParentsFactory,
DocketEntryWithParentsFactory,
DocketEntryFactory,
DocketFactory,
OpinionClusterFactory,
OpinionFactory,
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_index_daily_recap_documents(self, mock_prefix) -> None:
time_machine.travel(mock_two_days_before, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_index_daily_recap_documents(self, mock_prefix) -> None:
time_machine.travel(self.mock_date_indexing, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de_2 = DocketEntryWithParentsFactory(
alert_de_2 = DocketEntryFactory(
docket=docket_2,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_index_daily_recap_documents(self, mock_prefix) -> None:
docket_number="1:21-bk-1254",
source=Docket.RECAP,
)
alert_de_old = DocketEntryWithParentsFactory(
alert_de_old = DocketEntryFactory(
docket=docket_old,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -390,7 +390,7 @@ def test_index_daily_recap_documents(self, mock_prefix) -> None:
time_machine.travel(self.mock_date_indexing, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
rd_old_2.document_number = 3
rd_old_2.document_number = "3"
rd_old_2.save()

# Run the indexer. No new documents re_indexed.
Expand Down Expand Up @@ -524,7 +524,7 @@ def test_filter_out_alerts_to_send_by_query_and_hits(
time_machine.travel(self.mock_date_indexing, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -914,7 +914,7 @@ def test_special_cross_object_alerts_text_query(self, mock_prefix) -> None:
time_machine.travel(self.mock_date_indexing, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -1272,7 +1272,7 @@ def test_limit_alert_case_child_hits(self, mock_prefix) -> None:
time_machine.travel(self.mock_date, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=self.de.docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -1366,7 +1366,7 @@ def test_cross_object_parties_alert_query(self, mock_prefix) -> None:
time_machine.travel(self.mock_date_indexing, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=self.de.docket,
entry_number=2,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -1533,7 +1533,7 @@ def test_multiple_alerts_email_hits_limit_per_alert(
)
dockets_created.append(docket_created)

alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -1942,7 +1942,7 @@ def test_alert_frequency_estimation(self, mock_prefix) -> None:
# RECAPDocument filed today that belongs to a docket filed outside
# the estimation range.
date_outside_range = now() - datetime.timedelta(days=102)
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=DocketFactory(
court=self.court,
case_name="Frequency Test RECAP",
Expand Down Expand Up @@ -1984,7 +1984,7 @@ def test_alert_frequency_estimation(self, mock_prefix) -> None:
# RECAPDocument filed today that belongs to a docket filed outside
# the estimation range.
date_outside_range = now() - datetime.timedelta(days=102)
alert_de_2 = DocketEntryWithParentsFactory(
alert_de_2 = DocketEntryFactory(
docket=DocketFactory(
court=self.court,
case_name="Frequency Test RECAP 2",
Expand Down Expand Up @@ -2109,7 +2109,7 @@ def test_percolator_plus_sweep_alerts_integration(
source=Docket.RECAP,
cause="410 Civil",
)
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -2413,7 +2413,7 @@ def test_case_only_alerts(self, mock_prefix) -> None:
time_machine.travel(self.mock_date_indexing, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -3282,7 +3282,7 @@ def test_percolate_document_on_ingestion(self, mock_prefix) -> None:
time_machine.travel(self.mock_date, tick=False),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=DocketFactory(
court=self.court,
case_name="SUBPOENAS SERVED OFF",
Expand Down Expand Up @@ -3351,7 +3351,7 @@ def test_percolate_document_on_ingestion(self, mock_prefix) -> None:
),
self.captureOnCommitCallbacks(execute=True),
):
alert_de_2 = DocketEntryWithParentsFactory(
alert_de_2 = DocketEntryFactory(
docket=DocketFactory(
court=self.court,
case_name="SUBPOENAS SERVED ON",
Expand Down Expand Up @@ -3437,7 +3437,7 @@ def test_percolate_document_on_ingestion(self, mock_prefix) -> None:
),
self.captureOnCommitCallbacks(execute=True),
):
rd_2.document_number = 1
rd_2.document_number = "2"
rd_2.save()

call_command("cl_send_rt_percolator_alerts", testing_mode=True)
Expand Down Expand Up @@ -3631,7 +3631,7 @@ def test_recap_alerts_highlighting(self, mock_prefix) -> None:
),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=DocketFactory(
court=self.court,
case_name="SUBPOENAS SERVED OFF",
Expand Down Expand Up @@ -3699,7 +3699,7 @@ def test_group_percolator_alerts(self, mock_prefix) -> None:
if i < 2:
docket_case_names.append(docket_created.case_name)

alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -4067,7 +4067,7 @@ def test_filter_out_alerts_to_send_by_query_and_hits(
),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down Expand Up @@ -4540,7 +4540,7 @@ def test_case_only_alerts(self, mock_prefix) -> None:
),
self.captureOnCommitCallbacks(execute=True),
):
alert_de = DocketEntryWithParentsFactory(
alert_de = DocketEntryFactory(
docket=docket,
entry_number=1,
date_filed=datetime.date(2024, 8, 19),
Expand Down
10 changes: 2 additions & 8 deletions cl/api/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ class Meta:
)


class WebhookParentMixin(DjangoModelFactory):
webhook = SubFactory(
"cl.api.factories.WebhookFactory",
)


class WebhookEventWithParentsFactory(WebhookEventFactory, WebhookParentMixin):
class WebhookEventWithParentsFactory(WebhookEventFactory):
"""Make a WebhookEvent with a parent Webhook"""

pass
webhook = SubFactory(WebhookFactory)
8 changes: 4 additions & 4 deletions cl/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
from cl.search.factories import (
CourtFactory,
DocketFactory,
OpinionClusterFactoryWithChildrenAndParents,
OpinionClusterWithChildrenAndParentsFactory,
)
from cl.search.models import (
PRECEDENTIAL_STATUS,
Expand Down Expand Up @@ -211,23 +211,23 @@ def setUpTestData(cls):
cls.court_scotus = CourtFactory(id="scotus", jurisdiction="F")
cls.court_cand = CourtFactory(id="cand", jurisdiction="FD")

cls.c_scotus_1 = OpinionClusterFactoryWithChildrenAndParents(
cls.c_scotus_1 = OpinionClusterWithChildrenAndParentsFactory(
case_name="Strickland v. Lorem.",
docket=DocketFactory(
court=cls.court_scotus, docket_number="123456"
),
precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
date_filed=date(2000, 8, 15),
)
cls.c_scotus_2 = OpinionClusterFactoryWithChildrenAndParents(
cls.c_scotus_2 = OpinionClusterWithChildrenAndParentsFactory(
case_name="America vs Bank",
docket=DocketFactory(
court=cls.court_scotus, docket_number="34-2535"
),
precedential_status=PRECEDENTIAL_STATUS.ERRATA,
date_filed=date(2024, 6, 15),
)
cls.c_cand_1 = OpinionClusterFactoryWithChildrenAndParents(
cls.c_cand_1 = OpinionClusterWithChildrenAndParentsFactory(
case_name="Johnson v. National",
docket=DocketFactory(
court=cls.court_cand, docket_number="36-2000"
Expand Down
8 changes: 4 additions & 4 deletions cl/audio/factories.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from factory import Faker, post_generation
from factory import Faker, SelfAttribute, SubFactory, post_generation
from factory.django import DjangoModelFactory, FileField
from factory.fuzzy import FuzzyChoice

from cl.audio.models import Audio
from cl.search.factories import DocketParentMixin
from cl.search.factories import DocketFactory
from cl.search.models import SOURCES


Expand Down Expand Up @@ -55,7 +55,7 @@ def _after_postgeneration(cls, instance, create, results=None):
)


class AudioWithParentsFactory(AudioFactory, DocketParentMixin):
class AudioWithParentsFactory(AudioFactory):
"""Make an Audio with Docket parents"""

pass
docket = SubFactory(DocketFactory, case_name=SelfAttribute("..case_name"))
Loading