Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#168108377 Write tests for event helpers #273

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions server/api/tests/base_test_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.test import TestCase
from django.utils import timezone
from datetime import datetime, timedelta

from api.models import (AndelaUserProfile, Event, Category, UserProxy)

Expand Down Expand Up @@ -34,3 +35,28 @@ def setUp(self):
social_event=self.category1,
active=True
)

self.event_2 = Event.objects.create(
title='event2',
description='event2 description',
venue='event2 venue',
start_date = str(datetime.now()),
end_date = (datetime.now()),
creator=self.andela_user1,
social_event=self.category1,
active=True,
timezone = 'utc'
)

self.event_3 = Event.objects.create(
title='event3',
description='event3 description',
venue='event3 venue',
start_date = str(timezone.now() + timedelta(hours=24)),
end_date = (timezone.now() + timedelta(hours=25)),
creator=self.andela_user1,
social_event=self.category1,
active=True,
timezone = 'utc'
)

44 changes: 44 additions & 0 deletions server/graphql_schemas/tests/utils/test_event_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Module that tests event helper methods"""
from api.utils.event_helpers import is_not_past_event, save_user_attendance
from api.tests.base_test_setup import BaseSetup
from api.models import Attend
from unittest.mock import MagicMock, Mock
from unittest.mock import patch

class EventHelpersTests(BaseSetup):
"""
Tests the event helper file methods
"""
def test_is_not_past_event(self):
"""
Test method that check if event has passed
Args:
self (Instance): the test instance
"""
event = self.event_2
check_event = is_not_past_event(event)
self.assertEqual(check_event, False)

def test_is_not_past_event_with_future_event(self):
"""
Test method that saves user that is attending an event
using a future event
Args:
self (Instance): the test instance
"""
event = self.event_3
check_event = is_not_past_event(event)
self.assertEqual(check_event, True)

def test_save_user_attendance(self):
"""
Test method that saves user that is attending an event
Args:
self (Instance): the test instance
"""
event = self.event_3
user = self.andela_user1
save_user_attendance(event, user, 'attending')
Attend.objects = MagicMock(return_value=True)
self.assertEqual(Attend.objects.called, False)