Skip to content

Commit

Permalink
Add tests for organize app, fix fixture for future event
Browse files Browse the repository at this point in the history
  • Loading branch information
amakarudze committed Apr 1, 2021
1 parent 3c59841 commit aaf5a45
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 79 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def future_event(organizer_peter):
country="the Neverlands",
is_on_homepage=True,
main_organizer=organizer_peter,
date="2020-12-00",
date="2080-01-01",
page_url="bonn",
is_page_live=True)
event.team.add(organizer_peter)
Expand Down
101 changes: 36 additions & 65 deletions tests/organize/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, timedelta
from datetime import date, datetime, timedelta

import pytest

Expand Down Expand Up @@ -37,16 +37,6 @@ def application_on_hold(base_application):
return base_application


@pytest.fixture
def past_event():
return Event.objects.create(
name="Django Girls Berlin",
date="2014-06-21",
city="Berlin",
country="Germany",
latlng='52.5170365, 13.3888599')


@pytest.fixture
def previous_organizer_remote(past_event):
previous_event = {
Expand All @@ -59,9 +49,9 @@ def previous_organizer_remote(past_event):
'organizers-INITIAL_FORMS': '0',
'organizers-MIN_NUM_FORMS': '1',
'organizers-MAX_NUM_FORMS': '10',
'organizers-0-email': 'test@test.com',
'organizers-0-first_name': 'Anna',
'organizers-0-last_name': 'Smith',
'organizers-0-email': 'peter-pan@example.com',
'organizers-0-first_name': 'Peter',
'organizers-0-last_name': 'Pan',
'organizers-1-email': 'test1@test.com',
'organizers-1-first_name': 'Jane',
'organizers-1-last_name': 'Doe',
Expand All @@ -77,7 +67,8 @@ def previous_organizer_remote(past_event):
'workshop_remote-country': 'AO',
'workshop_remote-sponsorship': 'Yes, we hope to approach McKinsey and Accenture to sponsor our event.',
'workshop_remote-coaches': 'I know a number of coaches from our local meet-up.',
'workshop_remote-tools': 'We will use Zoom for video conferencing, share Google folder and GitHub to share links to resources.',
'workshop_remote-tools': 'We will use Zoom for video conferencing, share Google folder and GitHub to '
'share links to resources.',
'workshop_remote-diversity': 'Promote on social media and use videos',
'workshop_remote-additional': 'None',
'organize_form_wizard-current_step': 'workshop_remote'
Expand Down Expand Up @@ -157,9 +148,9 @@ def previous_organizer_in_person(past_event):
'organizers-INITIAL_FORMS': '0',
'organizers-MIN_NUM_FORMS': '1',
'organizers-MAX_NUM_FORMS': '10',
'organizers-0-email': 'jose@test.com',
'organizers-0-first_name': 'Jose',
'organizers-0-last_name': 'Jonas',
'organizers-0-email': 'peter-pan@example.com',
'organizers-0-first_name': 'Peter',
'organizers-0-last_name': 'Pan',
'organizers-1-email': 'jonas@test.com',
'organizers-1-first_name': 'Jonas',
'organizers-1-last_name': 'Jose Jnr',
Expand All @@ -170,7 +161,7 @@ def previous_organizer_in_person(past_event):
'organize_form_wizard-current_step': 'workshop_type'
}
workshop = {
'workshop-date': '2060-01-31',
'workshop-date': '2080-02-20',
'workshop-city': 'Beira',
'workshop-country': 'MZ',
'workshop-venue': 'Beira Hall',
Expand Down Expand Up @@ -371,70 +362,50 @@ def workshop_remote_form_date_year_only():
return data


@pytest.fixture
def previous_application():
return None


@pytest.fixture
def previous_event():
return None


@pytest.fixture
def previous_application_more_than_6_months():
return EventApplication.objects.create(
previous_application = EventApplication.objects.create(
city='Addis Ababa',
country='Ethiopia',
date='',
created_at='',
date='2070-01-30',
created_at=timedelta(days=-180),
main_organizer_email='test@test.com',
main_organizer_first_name='Anna',
main_organizer_last_name='Smith',
status='new'
)
return previous_application


@pytest.fixture
def previous_application_less_than_6_months():
return EventApplication.objects.create(
previous_application = EventApplication.objects.create(
city='Addis Ababa',
country='Ethiopia',
date='',
created_at='',
date='2070-01-30',
created_at=datetime.now(),
main_organizer_email='test@test.com',
main_organizer_first_name='Anna',
main_organizer_last_name='Smith',
status='new'
)
return previous_application


@pytest.fixture
def previous_event_in_6_months():
return Event.objects.create(
name="Django Girls Harare",
date="2014-06-21",
city="Harare",
country="Zimbabwe",
latlng='52.5170365, 13.3888599',
main_organizer_email='test@test.com'
def previous_event_more_than_6_months(organizer_peter):
previous_event = Event.objects.create(
email='harare@djangogirls.org',
city='Harare',
name='Django Girls Harare',
country='Zimbabwe',
latlng='-17.831773, 31.045686',
is_on_homepage=True,
main_organizer=organizer_peter,
date='2016-04-16',
page_url='harare',
is_page_live=True
)


@pytest.fixture
def previous_event_in_more_than_6_months():
return Event.objects.create(
name="Django Girls Harare",
date="2016-04-16",
city="Harare",
country="Zimbabwe",
latlng='52.5170365, 13.3888599',
main_organizer_email='test@test.com'
)


@pytest.fixture
def past_event():
return None


@pytest.fixture
def past_application():
return None
previous_event.team.add(organizer_peter)
return previous_event

2 changes: 1 addition & 1 deletion tests/organize/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_latlng_is_fetched_when_creating_application(base_application):
assert base_application.latlng == '0.0,0.0'
base_application.latlng = ''
base_application.save()
assert base_application.latlng == '39.4747112, -0.3798073'
assert base_application.latlng == '39.4747112, -0.3798074'


def test_has_past_team_members(organizer_peter, base_application):
Expand Down
35 changes: 23 additions & 12 deletions tests/organize/test_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.urls import reverse

from organize.views import organize_form_wizard
import pytest

from organize.models import Coorganizer, EventApplication


def test_form_thank_you(client):
Expand Down Expand Up @@ -40,30 +42,39 @@ def organize_view(client, workshop_data, previous_application, previous_event):
assert resp.status_code == 200
response = client.post(url, data_step)
if step == len(workshop_data):
# Check if event application is created - assumption is None or events/applications 6 months apart
# Check if organizer is added
assert response.status_code == 302
assert response['Location'] == reverse('organize:form_thank_you')


def test_organize_form_wizard_remote_previous_organizer(client, previous_organizer_remote):
@pytest.mark.django_db(transaction=True)
def test_organize_form_wizard_remote_previous_organizer(client, previous_organizer_remote,
previous_event_more_than_6_months,
previous_application=None):
# Test form submission for remote workshop with previous organizer
organize_view(client, previous_organizer_remote)
organize_view(client, previous_organizer_remote, previous_event_more_than_6_months, previous_application)


def test_organize_form_wizard_remote_new_organizer(client, new_organizer_remote, previous_application, previous_event):
def test_organize_form_wizard_remote_new_organizer(client, new_organizer_remote,
previous_application=None,
previous_event=None):
# Test form submission for remote workshop with new organizer
organize_view(client, new_organizer_remote, previous_application, previous_event)


def test_organize_form_wizard_in_person_previous_organizer(client, previous_organizer_in_person):
def test_organize_form_wizard_in_person_previous_organizer(client, previous_organizer_in_person,
previous_application_more_than_6_months,
previous_event_more_than_6_months):
# Test form submission for in-person workshop with previous organizer
organize_view(client, previous_organizer_in_person)
organize_view(client, previous_organizer_in_person,
previous_application_more_than_6_months,
previous_event_more_than_6_months)


def test_organize_form_wizard_in_person_new_organizer(client, new_organizer_in_person):
def test_organize_form_wizard_in_person_new_organizer(client, new_organizer_in_person,
previous_application=None,
previous_event=None):
# Test form submission for in-person with new organizer
organize_view(client, new_organizer_in_person)
organize_view(client, new_organizer_in_person, previous_application, previous_event)


def test_organize_form_wizard_applications_too_close(client, previous_organizer_remote,
Expand All @@ -79,8 +90,8 @@ def test_organize_form_wizard_applications_too_close(client, previous_organizer_
'have another open application.'


def test_organize_form_wizards_workshops_too_close(client, previous_organizer_in_person,
previous_event_in_6_months):
def test_organize_form_wizard_workshops_too_close(client, previous_organizer_in_person,
future_event):
# Test form submission with workshops less than 6 months apart
for step, data_step in previous_organizer_in_person:
url = '/organize/form/' + step + '/'
Expand Down

0 comments on commit aaf5a45

Please sign in to comment.