Skip to content

Commit

Permalink
Merge pull request #3290 from freelawproject/3283-fix-matching-query-…
Browse files Browse the repository at this point in the history
…does-not-exist

3283 fix matching query does not exist
  • Loading branch information
mlissner authored Oct 20, 2023
2 parents fa731aa + c837675 commit 9591f6f
Show file tree
Hide file tree
Showing 8 changed files with 1,931 additions and 1,646 deletions.
105 changes: 59 additions & 46 deletions cl/alerts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ def setUpTestData(cls):
query="type=o&stat_Precedential=on",
)
cls.mock_date = now().replace(day=15, hour=0)
with time_machine.travel(cls.mock_date, tick=False):
with time_machine.travel(
cls.mock_date, tick=False
), cls.captureOnCommitCallbacks(execute=True):
cls.dly_opinion = OpinionWithParentsFactory.create(
cluster__precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
cluster__date_filed=now() - timedelta(hours=5),
Expand Down Expand Up @@ -708,7 +710,9 @@ def test_send_search_alert_webhooks(self):

def test_send_search_alert_webhooks_rates(self):
"""Can we send search alert webhooks for different alert rates?"""
with time_machine.travel(self.mock_date, tick=False):
with time_machine.travel(
self.mock_date, tick=False
), self.captureOnCommitCallbacks(execute=True):
# Get ready the RT opinion for the test.
rt_opinion = OpinionWithParentsFactory.create(
cluster__precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
Expand Down Expand Up @@ -1623,7 +1627,9 @@ def test_alert_frequency_estimation(self, mock_abort_audio):
self.assertEqual(r.json()["count"], 0)

mock_date = now().replace(day=1, hour=5)
with time_machine.travel(mock_date, tick=False):
with time_machine.travel(
mock_date, tick=False
), self.captureOnCommitCallbacks(execute=True):
# When the Audio object is created it should trigger an alert.
rt_oral_argument = AudioWithParentsFactory.create(
case_name="Frequency Test OA",
Expand Down Expand Up @@ -1651,7 +1657,9 @@ def test_send_oa_search_alert_webhooks(self, mock_abort_audio):
),
):
mock_date = now().replace(day=1, hour=5)
with time_machine.travel(mock_date, tick=False):
with time_machine.travel(
mock_date, tick=False
), self.captureOnCommitCallbacks(execute=True):
# When the Audio object is created it should trigger an alert.
transcript_response = {
"response": {
Expand Down Expand Up @@ -1757,7 +1765,7 @@ def test_send_alert_on_document_creation(self, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
# When the Audio object is created it should trigger an alert.
rt_oral_argument = AudioWithParentsFactory.create(
case_name="RT Test OA",
Expand Down Expand Up @@ -1785,7 +1793,7 @@ def test_send_alert_on_document_creation(self, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
# Audio object is updated.
rt_oral_argument.sha1 = "12345"
rt_oral_argument.save()
Expand Down Expand Up @@ -1919,13 +1927,13 @@ def test_send_alert_multiple_alert_rates(self, mock_abort_audio):
"""Confirm dly, wly and mly alerts are properly stored and sent
according to their periodicity.
"""

dly_oral_argument = AudioWithParentsFactory.create(
case_name="DLY Test OA",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="19-5739",
)
with self.captureOnCommitCallbacks(execute=True):
dly_oral_argument = AudioWithParentsFactory.create(
case_name="DLY Test OA",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="19-5739",
)
# When a new document is created, and it triggers a dly, wly or mly
# It's stored to send it later.
scheduled_alerts = ScheduledAlertHit.objects.filter(
Expand Down Expand Up @@ -1969,12 +1977,13 @@ def test_send_alert_multiple_alert_rates(self, mock_abort_audio):
)
# Create an additional document that should be included in wly and mly
# Alerts.
wly_oral_argument = AudioWithParentsFactory.create(
case_name="WLY Test OA",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="19-5741",
)
with self.captureOnCommitCallbacks(execute=True):
wly_oral_argument = AudioWithParentsFactory.create(
case_name="WLY Test OA",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="19-5741",
)
# Send wly alerts and check assertions.
current_date = timezone.localtime(timezone.now()).replace(
day=7, hour=0
Expand All @@ -1988,12 +1997,13 @@ def test_send_alert_multiple_alert_rates(self, mock_abort_audio):
alert_count=2,
)
# Create an additional document that should be included mly Alert.
mly_oral_argument = AudioWithParentsFactory.create(
case_name="MLY Test OA",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="19-5742",
)
with self.captureOnCommitCallbacks(execute=True):
mly_oral_argument = AudioWithParentsFactory.create(
case_name="MLY Test OA",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="19-5742",
)
# Send mly alerts on a day after 28th, it must fail.
with mock.patch(
"cl.api.webhooks.requests.post",
Expand Down Expand Up @@ -2034,7 +2044,7 @@ def test_group_alerts_and_hits(self, mock_logger, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
# When the Audio object is created it should trigger an alert.
rt_oral_argument_1 = AudioWithParentsFactory.create(
case_name="DLY Test OA",
Expand Down Expand Up @@ -2187,7 +2197,7 @@ def test_send_multiple_rt_alerts(self, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
rt_oral_argument = AudioWithParentsFactory.create(
case_name=f"RT Test OA",
docket__court=self.court_1,
Expand Down Expand Up @@ -2252,7 +2262,7 @@ def test_batched_alerts_match_documents_ingestion(self, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
audio = AudioWithParentsFactory.create(
case_name=f"Test OA",
docket__court=self.court_1,
Expand Down Expand Up @@ -2328,7 +2338,7 @@ def test_percolate_document_in_batches(self, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
rt_oral_argument = AudioWithParentsFactory.create(
case_name=f"Lorem Ipsum",
docket__court=self.court_1,
Expand Down Expand Up @@ -2423,7 +2433,7 @@ def test_avoid_re_sending_scheduled_sent_alerts(self, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
# When the Audio object is created it should trigger an alert.
oral_argument = AudioWithParentsFactory.create(
case_name="Scheduled+Alert",
Expand Down Expand Up @@ -2463,7 +2473,9 @@ def test_avoid_re_sending_scheduled_sent_alerts(self, mock_abort_audio):

# Create a new Audio Document which will schedule a new DLY Alert hit.
mock_date = now() + timedelta(days=DAYS_TO_DELETE - 5)
with time_machine.travel(mock_date, tick=False):
with time_machine.travel(
mock_date, tick=False
), self.captureOnCommitCallbacks(execute=True):
oral_argument_2 = AudioWithParentsFactory.create(
case_name="Scheduled+Alert",
docket__court=self.court_1,
Expand Down Expand Up @@ -2516,7 +2528,7 @@ def test_avoid_re_sending_scheduled_sent_alerts(self, mock_abort_audio):
side_effect=lambda *args, **kwargs: MockResponse(
200, mock_raw=True
),
):
), self.captureOnCommitCallbacks(execute=True):
# Schedule the MONTHLY Alert hit.
oral_argument_3 = AudioWithParentsFactory.create(
case_name="Monthly+Hit",
Expand Down Expand Up @@ -2576,23 +2588,24 @@ def test_scheduled_hits_limit(self, mock_abort_audio):

oa_created = []
for i in range(4):
oral_argument = AudioWithParentsFactory.create(
case_name="USA vs Bank",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="19-5735",
)
oa_created.append(oral_argument)

if i in (1, 2):
# Only schedule two hits for this one.
oral_argument_2 = AudioWithParentsFactory.create(
case_name="Texas vs Corp",
with self.captureOnCommitCallbacks(execute=True):
oral_argument = AudioWithParentsFactory.create(
case_name="USA vs Bank",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="20-5030",
docket__docket_number="19-5735",
)
oa_created.append(oral_argument_2)
oa_created.append(oral_argument)

if i in (1, 2):
# Only schedule two hits for this one.
oral_argument_2 = AudioWithParentsFactory.create(
case_name="Texas vs Corp",
docket__court=self.court_1,
docket__date_argued=now().date(),
docket__docket_number="20-5030",
)
oa_created.append(oral_argument_2)

# Call dly command
call_command("cl_send_scheduled_alerts", rate=Alert.DAILY)
Expand Down
11 changes: 6 additions & 5 deletions cl/audio/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUpTestData(cls) -> None:
with mock.patch(
"cl.lib.es_signal_processor.avoid_es_audio_indexing",
side_effect=lambda x, y, z: False,
):
), cls.captureOnCommitCallbacks(execute=True):
cls.audio = AudioWithParentsFactory.create(
docket=DocketFactory(
court=cls.court_1, date_argued=datetime.date(2014, 8, 16)
Expand Down Expand Up @@ -192,10 +192,11 @@ def test_do_search_podcasts_have_content(self) -> None:
)

# pubDate key must be omitted in Audios without date_argued.
self.audio.docket.date_argued = None
self.audio.docket.save()
self.audio_2.docket.date_argued = None
self.audio_2.docket.save()
with self.captureOnCommitCallbacks(execute=True):
self.audio.docket.date_argued = None
self.audio.docket.save()
self.audio_2.docket.date_argued = None
self.audio_2.docket.save()
response = self.client.get(
reverse("search_podcast", args=["search"]),
params,
Expand Down
Loading

0 comments on commit 9591f6f

Please sign in to comment.