Skip to content

Commit

Permalink
make test more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsadetsky committed Mar 2, 2024
1 parent f84ef62 commit ae3cd50
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions core/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,46 @@ def test_database_event_search(self):
description=event_description,
starttime=get_current_new_york_datetime(),
)

partial_title = " ".join(event_title.split(" ")[-5:])

# search for event
response = self.client.get("/", {"s": event_title})
response = self.client.get("/", {"s": partial_title})

self.assertEqual(response.status_code, 200)
# find the title and the description in the results
# find the description in the results
self.assertContains(response, event_title)
self.assertContains(response, event_description)

def test_submitted_event_search(self):
# create an event that's user submitted i.e. not approved
event_title = " ".join(random.sample(RANDOM_WORDS, 10))
event_description = str(uuid.uuid4())
Event.objects.create(
event = Event.objects.create(
title=event_title,
description=event_description,
starttime=get_current_new_york_datetime(),
is_approved=False,
user_submitted=True,
)

partial_title = " ".join(event_title.split(" ")[-8:])

# search for event
response = self.client.get("/", {"s": event_title})
response = self.client.get("/", {"s": partial_title})

self.assertEqual(response.status_code, 200)
# we should NOT find the description in the test results
# (note that we WOULD find the title, because it's shown as
# "search results for: <title>") but that doesn't count...! :-)
self.assertNotContains(response, event_title)
self.assertNotContains(response, event_description)

# approve the event
event.is_approved = True
event.save()

# search for event
response = self.client.get("/", {"s": partial_title})

self.assertEqual(response.status_code, 200)
# find the title and the description in the results
self.assertContains(response, event_title)
self.assertContains(response, event_description)

0 comments on commit ae3cd50

Please sign in to comment.