Skip to content

Commit

Permalink
fix: added three new fields to model along with test case (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
freaky4wrld committed Jun 5, 2024
1 parent 56e8462 commit e62140b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.11 on 2024-06-04 01:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0022_rename_sponsorpartner_affiliate_affiliation_and_more"),
]

operations = [
migrations.AddField(
model_name="event",
name="could_attend",
field=models.JSONField(default=list),
),
migrations.AddField(
model_name="event",
name="must_attend",
field=models.JSONField(default=list),
),
migrations.AddField(
model_name="event",
name="should_attend",
field=models.JSONField(default=list),
),
]
2 changes: 1 addition & 1 deletion app/core/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0022_rename_sponsorpartner_affiliate_affiliation_and_more
0023_event_could_attend_event_must_attend_and_more
13 changes: 9 additions & 4 deletions app/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,22 @@ class Event(AbstractBaseModel):
additional_info = models.TextField(blank=True)

project = models.ForeignKey(Project, on_delete=models.CASCADE)
must_attend = models.JSONField(default=list)
should_attend = models.JSONField(default=list)
could_attend = models.JSONField(default=list)
# location_id = models.ForeignKey("Location", on_delete=models.DO_NOTHING)
# event_type_id = models.ForeignKey("EventType", on_delete=models.DO_NOTHING)
# brigade_id = models.ForeignKey("Brigade", on_delete=models.DO_NOTHING)
# day_of_week = models.ForeignKey("DayOfWeek", on_delete=models.DO_NOTHING)
# must_roles = models.ManyToManyField("Role")
# should_roles = models.ManyToManyField("Role")
# could_roles = models.ManyToManyField("Role")
# frequency_id = models.ForeignKey("Frequency", on_delete=models.DO_NOTHING)

def __str__(self):
return f"{self.name}"
return (
f"Event: {self.name}, "
f"Must_Attend: {self.must_attend}, "
f"Should_Attend: {self.should_attend}, "
f"Could_Attend: {self.could_attend}"
)


class Affiliate(AbstractBaseModel):
Expand Down
32 changes: 30 additions & 2 deletions app/core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,36 @@ def project():


@pytest.fixture
def event(project):
return Event.objects.create(name="Test Event", project=project)
def event_pm(project):
return Event.objects.create(
name="PM",
project=project,
must_attend=[
{"practice_area": "Development", "permission_type": "practiceLeadProject"},
{"practice_area": "Design", "permission_type": "practiceLeadJrProject"},
],
should_attend=[
{"practice_area": "Development", "permission_type": "memberProject"},
{"practice_area": "Design", "permission_type": "adminProject"},
],
could_attend=[{"practice_area": "Design", "permission_type": "memberGeneral"}],
)


@pytest.fixture
def event_all(project):
return Event.objects.create(
name="All",
project=project,
must_attend=[
{
"practice_area": "Professional Development",
"permission_type": "adminProject",
}
],
should_attend=[],
could_attend=[],
)


@pytest.fixture
Expand Down
14 changes: 14 additions & 0 deletions app/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ def test_create_event(auth_client, project):
"video_conference_url": "https://zoom.com/link",
"additional_info": "Test description",
"project": project.uuid,
"must_attend": [
{
"practice_area": "Professional Development",
"permission_type": "adminProject",
},
{"practice_area": "Development", "permission_type": "practiceLeadProject"},
{"practice_area": "Design", "permission_type": "practiceLeadJrProject"},
],
"should_attend": [
{"practice_area": "Development", "permission_type": "memberProject"}
],
"could_attend": [
{"practice_area": "Design", "permission_type": "memberGeneral"}
],
}
res = auth_client.post(EVENTS_URL, payload)
assert res.status_code == status.HTTP_201_CREATED
Expand Down
16 changes: 14 additions & 2 deletions app/core/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from ..models import Event

pytestmark = pytest.mark.django_db


Expand All @@ -14,8 +16,18 @@ def test_project(project):
assert str(project) == "Test Project"


def test_event(event):
assert str(event) == "Test Event"
def filter_objects_by_name(objects_list, name):
return [obj for obj in objects_list if getattr(obj, "name", None) == name]


def test_event_projects_admins_must_attend(event_all, event_pm):
projects_admins_must_attend = Event.objects.filter(
must_attend__contains=[{"permission_type": "adminProject"}]
)

assert projects_admins_must_attend.count() == 1
assert len(filter_objects_by_name(projects_admins_must_attend, "All")) == 1
assert len(filter_objects_by_name(projects_admins_must_attend, "PM")) == 0


def test_practice_area(practice_area):
Expand Down

0 comments on commit e62140b

Please sign in to comment.