Skip to content

Commit

Permalink
Add tests for OrganizerIssue model
Browse files Browse the repository at this point in the history
  • Loading branch information
amakarudze committed Jan 31, 2024
1 parent 977c123 commit b11866b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 7 deletions.
5 changes: 0 additions & 5 deletions core/models/managers/organizer.py

This file was deleted.

37 changes: 37 additions & 0 deletions tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from coach.models import Coach
from core.models import Event, EventPageContent, EventPageMenu
from core.models.organizerissue import OrganizerIssue
from globalpartners.models import GlobalPartner
from sponsor.models import Sponsor
from story.models import Story
Expand Down Expand Up @@ -151,3 +152,39 @@ def old_event_no_date(organizer_peter):
)
event.team.add(organizer_peter)
return event


@pytest.fixture
def organizer_issue(organizer_peter, old_event, admin_user):
issue = OrganizerIssue.objects.create(
organizer=organizer_peter,
event=old_event,
date_reported="2023-10-12",
reported_by="Jane Doe",
reporter_email="[email protected]",
issue="He was rude and disrespectful.",
issue_handled=True,
issue_handled_by=admin_user,
findings="He was rude indeed.",
comments="He should be blacklisted from organizing more events.",
)
return issue


@pytest.fixture
def reverse_blacklisting(organizer_julia, old_event, admin_user):
organizer_julia.is_blacklisted = True
organizer_julia.save()
issue = OrganizerIssue.objects.create(
organizer=organizer_julia,
event=old_event,
date_reported="2023-10-12",
reported_by="John Doe",
reporter_email="[email protected]",
issue="She was very arrogant.",
issue_handled=True,
issue_handled_by=admin_user,
findings="She was not polite.",
comments="It was just a misunderstanding.",
)
return issue
14 changes: 13 additions & 1 deletion tests/core/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.urls import reverse

from core.models import Event
from core.models import Event, User


def test_get_queryset_for_superuser(admin_client, events):
Expand Down Expand Up @@ -168,3 +168,15 @@ def test_unfreeze_events_action(admin_client, future_event):
def test_event_str(admin_client, events):
event = events[0]
assert str(event) == f"{event.name}, {event.date}"


def test_blacklist_organizer(organizer_issue, admin_client):
response = admin_client.get(reverse("admin:core_organizerissue_blacklist", args=(organizer_issue.pk,)))
assert response.status_code == 302
assert User.objects.filter(is_blacklisted=True).count() == 1


def test_reverse_blacklist(reverse_blacklisting, admin_client):
response = admin_client.get(reverse("admin:core_organizerissue_reverse_blacklist", args=(reverse_blacklisting.pk,)))
assert response.status_code == 302
assert User.objects.filter(is_blacklisted=True).count() == 0
4 changes: 4 additions & 0 deletions tests/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ def test_event_lnglat(future_event):

future_event.latlng = "sddasdasda"
assert future_event.lnglat == ""


def test_organizerissue_string_representation(organizer_issue):
assert str(organizer_issue) == f"{organizer_issue.organizer.get_full_name()} - {organizer_issue.event}"
39 changes: 38 additions & 1 deletion tests/organize/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from django_date_extensions.fields import ApproximateDate

from core.models import Event
from core.models import Event, User
from organize.constants import ON_HOLD
from organize.models import Coorganizer, EventApplication

Expand Down Expand Up @@ -482,3 +482,40 @@ def previous_application_approximate_date():
main_organizer_last_name="Smith",
status="deployed",
)


@pytest.fixture
def main_organizer_is_blacklisted():
main_organizer = User.objects.create(
first_name="Anna",
last_name="Smith",
email="[email protected]",
password="password",
is_active=True,
is_superuser=False,
is_staff=True,
is_blacklisted=True,
)
return main_organizer


@pytest.fixture
def data_dict_new_organizer():
return {
"about_you": "I am a volunteer in my local meet-up.",
"why": "There are a few women who know how to code in our meet-up.",
"involvement": "coach",
"experience": "I have volunteered at my local meet-up.",
"main_organizer_email": "[email protected]",
"main_organizer_first_name": "Anna",
"main_organizer_last_name": "Smith",
"remote": True,
"date": ApproximateDate(2081, 3, 10),
"city": "Harare",
"country": "ZW",
"sponsorship": "Yes",
"coaches": "Yes",
"tools": "Zoom",
"diversity": "Reach out",
"additional": "No",
}
16 changes: 16 additions & 0 deletions tests/organize/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,19 @@ def test_coorganizer_str(base_application):
event_application=base_application, email="[email protected]", first_name="Anna", last_name="Smith"
)
assert str(org) == f"{org.first_name} {org.last_name} <{org.email}>"


def test_main_organizer_is_blacklisted(data_dict, main_organizer_is_blacklisted):
event = EventApplication.object.create(**data_dict)
assert event.organizer_blacklisted is True
assert EventApplication.object.count() == 1


def test_main_organizer_is_not_blacklisted(data_dict):
EventApplication.object.create(**data_dict)
assert EventApplication.object.count() == 1


def test_new_organizer(data_dict_new_organizer):
EventApplication.object.create(**data_dict_new_organizer)
assert EventApplication.object.count() == 1

0 comments on commit b11866b

Please sign in to comment.