Skip to content

Commit

Permalink
Merge branch 'DjangoGirls:main' into add-event-sponsorship
Browse files Browse the repository at this point in the history
  • Loading branch information
amakarudze authored Dec 31, 2023
2 parents 1984dac + d14425d commit cd02cc1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
5 changes: 4 additions & 1 deletion core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def get_event(page_url, is_user_authenticated, is_preview):
event = Event.objects.filter(page_url=page_url).order_by("-date").first()

if not (is_user_authenticated or is_preview) and not event.is_page_live:
past = event.date <= now_approx
try:
past = event.date <= now_approx
except AttributeError:
past = True
return page_url, past

return event
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ django>=3.2,<4
dnspython
easy-thumbnails
easydict==1.10
pillow==9.3.0
pillow==10.0.1
psycopg2-binary==2.8.3
pyquery==1.4.0
urlextract
Expand Down
21 changes: 15 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ autoflake==1.4
black==22.3.0
# via -r requirements.in
bleach[css]==5.0.1
# via django-bleach
# via
# bleach
# django-bleach
boto3==1.26.85
# via django-storages
botocore==1.29.85
Expand Down Expand Up @@ -47,7 +49,7 @@ distlib==0.3.6
# via virtualenv
dj-database-url==0.5.0
# via -r requirements.in
django==3.2.20
django==3.2.23
# via
# -r requirements.in
# django-admin-sortable2
Expand Down Expand Up @@ -90,7 +92,9 @@ django-recaptcha==3.0.0
django-sendgrid-v5==0.8.1
# via -r requirements.in
django-storages[boto3]==1.7.1
# via -r requirements.in
# via
# -r requirements.in
# django-storages
django-tinymce==3.5.0
# via -r requirements.in
django-unused-media==0.1.13
Expand Down Expand Up @@ -168,7 +172,7 @@ packaging==23.0
# pytest
pathspec==0.11.0
# via black
pillow==9.3.0
pillow==10.0.1
# via
# -r requirements.in
# easy-thumbnails
Expand All @@ -187,7 +191,7 @@ protobuf==4.24.4
# via
# google-api-core
# googleapis-common-protos
psycopg2-binary==2.9.9
psycopg2-binary==2.8.3
# via -r requirements.in
py==1.11.0
# via pytest
Expand Down Expand Up @@ -298,6 +302,11 @@ toml==0.10.2
# via
# pytest
# pytest-cov
tomli==2.0.1
# via
# black
# build
# pyproject-hooks
typing-extensions==4.5.0
# via django-countries
uritemplate==4.1.1
Expand All @@ -306,7 +315,7 @@ uritools==4.0.1
# via urlextract
urlextract==1.8.0
# via -r requirements.in
urllib3==1.26.14
urllib3==1.26.18
# via
# botocore
# requests
Expand Down
19 changes: 18 additions & 1 deletion tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,24 @@ def old_event(organizer_peter):
main_organizer=organizer_peter,
date="2023-01-01",
page_url="bonn",
is_page_live=True,
is_page_live=False,
)
event.team.add(organizer_peter)
return event


@pytest.fixture
def old_event_no_date(organizer_peter):
event = Event.objects.create(
email="bonn@djangogirls.org",
city="Bonn",
name="Django Girls Bonn",
country="the Neverlands",
is_on_homepage=True,
main_organizer=organizer_peter,
date="",
page_url="bonn",
is_page_live=False,
)
event.team.add(organizer_peter)
return event
32 changes: 31 additions & 1 deletion tests/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from freezegun import freeze_time

from core.utils import NOMINATIM_URL, get_coordinates_for_city, next_deadline
from core.utils import NOMINATIM_URL, get_coordinates_for_city, get_event, next_deadline


@mock.patch("requests.get")
Expand Down Expand Up @@ -87,3 +87,33 @@ def test_day_before_deadline(): # noqa: F811
result = next_deadline()

assert result == date(2016, 10, 30)


def test_get_event_past(old_event):
result = get_event("bonn", False, False)
assert result == ("bonn", True)


def test_get_event_not_past(future_event):
result = get_event("bonn", False, False)
assert result == future_event


def test_get_event_not_past_user_authenticated(future_event):
result = get_event("bonn", True, False)
assert result == future_event


def test_get_event_multiple_events(old_event, future_event):
result = get_event("bonn", True, False)
assert result == future_event


def test_get_event_none_exists():
result = get_event("bonn", True, False)
assert result is None


def test_get_event_no_date(old_event_no_date):
result = get_event("bonn", False, False)
assert result == ("bonn", True)

0 comments on commit cd02cc1

Please sign in to comment.