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

#168261941 Test the normalize_dates helper function #272

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion server/graphql_schemas/tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from tempfile import NamedTemporaryFile
from unittest.mock import patch
import datetime

from django.core.exceptions import ValidationError

from graphql_schemas.utils.helpers import (
update_event_status_on_calendar,
remove_event_from_all_calendars,
validate_image,
add_event_to_calendar
add_event_to_calendar,
normalize_dates
)
from api.tests.base_test_setup import BaseSetup

Expand Down Expand Up @@ -95,6 +97,7 @@ def test_add_event_to_calendar(self):
self.assertEqual(mock_build.call_count, 1)
self.assertEqual(event.event_id_in_calendar, 1)
mock_build_patcher.stop()

def test_validate_image_passes_for_valid_image(self):
"""
Test method that validates images are valid before uploading
Expand Down Expand Up @@ -130,3 +133,29 @@ def test_validate_image_fails_for_invalid_image_formats(self):

self.assertEquals(
e.exception.message, "You can only upload image files")

def test_normalize_dates_function_success(self):
"""
Test that dates have to be in the present for them to be accepted
"""
start_date = datetime.date.today()
end_date = start_date + datetime.timedelta(days=1)

result = normalize_dates(end_date, start_date, datetime.date.today())

self.assertEqual(
result, {'status': True, 'message': 'Validation successful'})

def test_normalize_dates_function_if_end_date_invalid(self):
"""
Test that the event must end in the future, after the event start date
"""
start_date = datetime.date.today() + datetime.timedelta(days=2)
end_date = datetime.date.today()

result = normalize_dates(end_date, start_date, datetime.date.today())

self.assertEqual(
result, {
'status': False,
'message': 'Sorry, end date must be after start date'})