Skip to content

Commit 972fac7

Browse files
committed
refactor(cl): convert PeopleTestCase to a mixin
1 parent 617b178 commit 972fac7

File tree

7 files changed

+174
-178
lines changed

7 files changed

+174
-178
lines changed

cl/citations/tests.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
from cl.citations.utils import (
6363
make_get_citations_kwargs,
6464
)
65-
from cl.lib.test_helpers import PeopleTestCase, SearchTestCase
65+
from cl.lib.test_helpers import SearchTestCase
6666
from cl.search.documents import ParentheticalGroupDocument
6767
from cl.search.factories import (
6868
CitationWithParentsFactory,
@@ -90,7 +90,7 @@
9090
TestCase,
9191
TransactionTestCase,
9292
)
93-
from cl.tests.mixins import CourtMixin
93+
from cl.tests.mixins import CourtMixin, PeopleMixin
9494
from cl.users.factories import UserProfileWithParentsFactory
9595

9696
HYPERSCAN_TOKENIZER = HyperscanTokenizer(cache_dir=".hyperscan")
@@ -1584,7 +1584,7 @@ def test_citation_count_not_updated(self) -> None:
15841584

15851585

15861586
class CitationFeedTest(
1587-
TestCase, ESIndexTestCase, CourtMixin, PeopleTestCase, SearchTestCase
1587+
TestCase, ESIndexTestCase, CourtMixin, PeopleMixin, SearchTestCase
15881588
):
15891589
@classmethod
15901590
def setUpTestData(cls) -> None:
@@ -2348,16 +2348,14 @@ def test_get_graph_component(self):
23482348
"cl.api.utils.CitationCountRateThrottle.get_cache_key_for_citations",
23492349
return_value="citations_tests",
23502350
)
2351-
class CitationLookUpApiTest(
2352-
TestCase, CourtMixin, PeopleTestCase, SearchTestCase
2353-
):
2351+
class CitationLookUpApiTest(TestCase, CourtMixin, PeopleMixin, SearchTestCase):
23542352
@classmethod
23552353
def setUpTestData(cls) -> None:
2354+
super().setUpTestData()
23562355
UserProfileWithParentsFactory.create(
23572356
user__username="citation-user",
23582357
user__password=make_password("password"),
23592358
)
2360-
super().setUpTestData()
23612359

23622360
@async_to_sync
23632361
async def setUp(self) -> None:

cl/lib/test_helpers.py

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,12 @@
1515
from cl.audio.models import Audio
1616
from cl.lib.utils import deepgetattr
1717
from cl.people_db.factories import (
18-
ABARatingFactory,
1918
AttorneyFactory,
2019
AttorneyOrganizationFactory,
21-
EducationFactory,
2220
PartyFactory,
2321
PartyTypeFactory,
2422
PersonFactory,
25-
PoliticalAffiliationFactory,
26-
PositionFactory,
27-
SchoolFactory,
2823
)
29-
from cl.people_db.models import Race
3024
from cl.search.constants import o_type_index_map
3125
from cl.search.docket_sources import DocketSources
3226
from cl.search.documents import DocketDocument
@@ -791,152 +785,6 @@ def midnight_pt_test(d: datetime.date) -> datetime.datetime:
791785
)
792786

793787

794-
class PeopleTestCase(TestCase):
795-
"""People test case factories"""
796-
797-
@classmethod
798-
def setUpTestData(cls):
799-
cls.w_race, _ = Race.objects.get_or_create(race="w")
800-
cls.b_race, _ = Race.objects.get_or_create(race="b")
801-
cls.person_1 = PersonFactory.create(
802-
gender="m",
803-
name_first="Bill",
804-
name_last="Clinton",
805-
)
806-
cls.person_1.race.add(cls.w_race)
807-
808-
cls.person_2 = PersonFactory.create(
809-
gender="f",
810-
name_first="Judith",
811-
name_last="Sheindlin",
812-
name_suffix="2",
813-
date_dob=datetime.date(1942, 10, 21),
814-
date_dod=datetime.date(2020, 11, 25),
815-
date_granularity_dob="%Y-%m-%d",
816-
date_granularity_dod="%Y-%m-%d",
817-
name_middle="Susan",
818-
dob_city="Brookyln",
819-
dob_state="NY",
820-
fjc_id=19832,
821-
)
822-
cls.person_2.race.add(cls.w_race)
823-
cls.person_2.race.add(cls.b_race)
824-
825-
cls.person_3 = PersonFactory.create(
826-
gender="f",
827-
name_first="Sheindlin",
828-
name_last="Judith",
829-
date_dob=datetime.date(1945, 11, 20),
830-
date_granularity_dob="%Y-%m-%d",
831-
name_middle="Olivia",
832-
dob_city="Queens",
833-
dob_state="NY",
834-
)
835-
cls.person_3.race.add(cls.w_race)
836-
837-
cls.position_1 = PositionFactory.create(
838-
date_granularity_start="%Y-%m-%d",
839-
date_start=datetime.date(1993, 1, 20),
840-
date_retirement=datetime.date(2001, 1, 20),
841-
termination_reason="retire_mand",
842-
position_type="pres",
843-
person=cls.person_1,
844-
how_selected="e_part",
845-
)
846-
cls.position_2 = PositionFactory.create(
847-
date_granularity_start="%Y-%m-%d",
848-
court=cls.court_1,
849-
date_start=datetime.date(2015, 12, 14),
850-
predecessor=cls.person_2,
851-
appointer=cls.position_1,
852-
judicial_committee_action="no_rep",
853-
termination_reason="retire_mand",
854-
position_type="c-jud",
855-
person=cls.person_2,
856-
how_selected="e_part",
857-
nomination_process="fed_senate",
858-
date_elected=datetime.date(2015, 11, 12),
859-
date_confirmation=datetime.date(2015, 11, 14),
860-
date_termination=datetime.date(2018, 10, 14),
861-
date_granularity_termination="%Y-%m-%d",
862-
date_hearing=datetime.date(2021, 10, 14),
863-
date_judicial_committee_action=datetime.date(2022, 10, 14),
864-
date_recess_appointment=datetime.date(2013, 10, 14),
865-
date_referred_to_judicial_committee=datetime.date(2010, 10, 14),
866-
date_retirement=datetime.date(2023, 10, 14),
867-
)
868-
cls.position_3 = PositionFactory.create(
869-
date_granularity_start="%Y-%m-%d",
870-
date_start=datetime.date(2015, 12, 14),
871-
organization_name="Pants, Inc.",
872-
job_title="Corporate Lawyer",
873-
position_type=None,
874-
person=cls.person_2,
875-
)
876-
cls.position_4 = PositionFactory.create(
877-
date_granularity_start="%Y-%m-%d",
878-
court=cls.court_2,
879-
date_start=datetime.date(2020, 12, 14),
880-
predecessor=cls.person_3,
881-
appointer=cls.position_1,
882-
judicial_committee_action="no_rep",
883-
termination_reason="retire_mand",
884-
position_type="c-jud",
885-
person=cls.person_3,
886-
how_selected="a_legis",
887-
nomination_process="fed_senate",
888-
)
889-
890-
cls.school_1 = SchoolFactory(name="New York Law School")
891-
cls.school_2 = SchoolFactory(name="American University")
892-
893-
cls.education_1 = EducationFactory(
894-
degree_level="jd",
895-
person=cls.person_2,
896-
degree_year=1965,
897-
school=cls.school_1,
898-
)
899-
cls.education_2 = EducationFactory(
900-
degree_level="ba",
901-
person=cls.person_2,
902-
school=cls.school_2,
903-
)
904-
cls.education_3 = EducationFactory(
905-
degree_level="ba",
906-
person=cls.person_3,
907-
school=cls.school_1,
908-
)
909-
910-
cls.political_affiliation_1 = PoliticalAffiliationFactory.create(
911-
political_party="d",
912-
source="b",
913-
date_start=datetime.date(1993, 1, 1),
914-
person=cls.person_1,
915-
date_granularity_start="%Y",
916-
)
917-
cls.political_affiliation_2 = PoliticalAffiliationFactory.create(
918-
political_party="d",
919-
source="b",
920-
date_start=datetime.date(2015, 12, 14),
921-
person=cls.person_2,
922-
date_granularity_start="%Y-%m-%d",
923-
)
924-
cls.political_affiliation_3 = PoliticalAffiliationFactory.create(
925-
political_party="i",
926-
source="b",
927-
date_start=datetime.date(2015, 12, 14),
928-
person=cls.person_3,
929-
date_granularity_start="%Y-%m-%d",
930-
)
931-
932-
cls.aba_rating_1 = ABARatingFactory(
933-
rating="nq",
934-
person=cls.person_2,
935-
year_rated="2015",
936-
)
937-
super().setUpTestData()
938-
939-
940788
class SearchTestCase(TestCase):
941789
"""Search test case factories"""
942790

cl/opinion_page/tests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from cl.lib.redis_utils import get_redis_interface
3232
from cl.lib.storage import clobbering_get_name
3333
from cl.lib.test_helpers import (
34-
PeopleTestCase,
3534
SearchTestCase,
3635
SimpleUserDataMixin,
3736
SitemapTest,
@@ -89,7 +88,7 @@
8988
)
9089
from cl.sitemaps_infinite.sitemap_generator import generate_urls_chunk
9190
from cl.tests.cases import ESIndexTestCase, TestCase
92-
from cl.tests.mixins import CourtMixin
91+
from cl.tests.mixins import CourtMixin, PeopleMixin
9392
from cl.tests.providers import fake
9493
from cl.users.factories import UserFactory, UserProfileWithParentsFactory
9594

@@ -122,7 +121,7 @@ class OpinionPageLoadTest(
122121
TestCase,
123122
ESIndexTestCase,
124123
CourtMixin,
125-
PeopleTestCase,
124+
PeopleMixin,
126125
SearchTestCase,
127126
):
128127
@classmethod

cl/search/tests/tests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from cl.lib.indexing_utils import log_last_document_indexed
3535
from cl.lib.redis_utils import get_redis_interface
3636
from cl.lib.storage import clobbering_get_name
37-
from cl.lib.test_helpers import PeopleTestCase
3837
from cl.lib.utils import (
3938
cleanup_main_query,
4039
get_child_court_ids_for_parents,
@@ -91,7 +90,7 @@
9190
from cl.search.types import EventTable
9291
from cl.tests.base import SELENIUM_TIMEOUT, BaseSeleniumTest
9392
from cl.tests.cases import ESIndexTestCase, TestCase
94-
from cl.tests.mixins import CourtMixin
93+
from cl.tests.mixins import CourtMixin, PeopleMixin
9594
from cl.tests.utils import get_with_wait
9695
from cl.users.factories import UserProfileWithParentsFactory
9796

@@ -2770,7 +2769,7 @@ def test_get_unique_oldest_date_range_rows(self) -> None:
27702769
return_value="es_sweep_indexer:log_test",
27712770
)
27722771
class SweepIndexerCommandTest(
2773-
TestCase, CourtMixin, PeopleTestCase, ESIndexTestCase
2772+
TestCase, CourtMixin, PeopleMixin, ESIndexTestCase
27742773
):
27752774
"""sweep_indexer command tests for Elasticsearch"""
27762775

cl/search/tests/tests_es_opinion.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from cl.lib.elasticsearch_utils import do_es_api_query
2727
from cl.lib.redis_utils import get_redis_interface
2828
from cl.lib.test_helpers import (
29-
PeopleTestCase,
3029
SearchTestCase,
3130
opinion_document_v4_api_keys,
3231
opinion_v3_search_api_keys,
@@ -78,12 +77,12 @@
7877
TransactionTestCase,
7978
V4SearchAPIAssertions,
8079
)
81-
from cl.tests.mixins import CourtMixin
80+
from cl.tests.mixins import CourtMixin, PeopleMixin
8281
from cl.users.factories import UserProfileWithParentsFactory
8382

8483

8584
class OpinionSearchAPICommonTests(
86-
TestCase, CourtMixin, PeopleTestCase, SearchTestCase
85+
TestCase, CourtMixin, PeopleMixin, SearchTestCase
8786
):
8887
version_api = "v3"
8988
skip_common_tests = True
@@ -1216,7 +1215,7 @@ def test_verify_empty_lists_type_fields_after_partial_update(self):
12161215

12171216

12181217
class OpinionsESSearchTest(
1219-
TestCase, ESIndexTestCase, CourtMixin, PeopleTestCase, SearchTestCase
1218+
TestCase, ESIndexTestCase, CourtMixin, PeopleMixin, SearchTestCase
12201219
):
12211220
@classmethod
12221221
def setUpTestData(cls):
@@ -2573,7 +2572,7 @@ def test_relevancy_decay_scoring_v3_api(self) -> None:
25732572

25742573
@override_settings(RELATED_MLT_MINTF=1)
25752574
class RelatedSearchTest(
2576-
TestCase, ESIndexTestCase, CourtMixin, PeopleTestCase, SearchTestCase
2575+
TestCase, ESIndexTestCase, CourtMixin, PeopleMixin, SearchTestCase
25772576
):
25782577
@classmethod
25792578
def setUpTestData(cls) -> None:
@@ -3030,15 +3029,14 @@ async def test_es_get_citing_and_related_clusters_cache_timeout(
30303029

30313030

30323031
class IndexOpinionDocumentsCommandTest(
3033-
TestCase, ESIndexTestCase, CourtMixin, PeopleTestCase, SearchTestCase
3032+
TestCase, ESIndexTestCase, CourtMixin, PeopleMixin, SearchTestCase
30343033
):
30353034
"""cl_index_parent_and_child_docs command tests for Elasticsearch"""
30363035

30373036
@classmethod
30383037
def setUpTestData(cls):
30393038
super().setUpTestData()
30403039
cls.rebuild_index("search.OpinionCluster")
3041-
super().setUpTestData()
30423040
cls.delete_index("search.OpinionCluster")
30433041
cls.create_index("search.OpinionCluster")
30443042

@@ -4055,7 +4053,7 @@ def test_remove_control_chars_on_text_indexing(self) -> None:
40554053

40564054

40574055
class OpinionFeedTest(
4058-
TestCase, ESIndexTestCase, CourtMixin, PeopleTestCase, SearchTestCase
4056+
TestCase, ESIndexTestCase, CourtMixin, PeopleMixin, SearchTestCase
40594057
):
40604058
"""Tests for Opinion Search Feed"""
40614059

cl/search/tests/tests_es_person.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from cl.lib.elasticsearch_utils import build_es_base_query, build_es_main_query
1515
from cl.lib.search_index_utils import extract_field_values
1616
from cl.lib.test_helpers import (
17-
PeopleTestCase,
1817
people_v4_fields,
1918
position_v4_fields,
2019
skip_if_common_tests_skipped,
@@ -41,10 +40,10 @@
4140
TransactionTestCase,
4241
V4SearchAPIAssertions,
4342
)
44-
from cl.tests.mixins import CourtMixin
43+
from cl.tests.mixins import CourtMixin, PeopleMixin
4544

4645

47-
class PeopleSearchAPICommonTests(TestCase, CourtMixin, PeopleTestCase):
46+
class PeopleSearchAPICommonTests(TestCase, CourtMixin, PeopleMixin):
4847
version_api = "v3"
4948
skip_common_tests = True
5049

@@ -1259,7 +1258,7 @@ def test_people_cursor_api_pagination_count(self) -> None:
12591258

12601259

12611260
class PeopleSearchTestElasticSearch(
1262-
TestCase, CourtMixin, PeopleTestCase, ESIndexTestCase
1261+
TestCase, CourtMixin, PeopleMixin, ESIndexTestCase
12631262
):
12641263
"""People search tests for Elasticsearch"""
12651264

@@ -1999,7 +1998,7 @@ def test_frontend_judges_count(self) -> None:
19991998

20001999

20012000
class IndexJudgesPositionsCommandTest(
2002-
TestCase, CourtMixin, PeopleTestCase, ESIndexTestCase
2001+
TestCase, CourtMixin, PeopleMixin, ESIndexTestCase
20032002
):
20042003
"""test_cl_index_parent_and_child_docs_command tests for Elasticsearch"""
20052004

0 commit comments

Comments
 (0)