Skip to content

Commit

Permalink
ft(Tests) Test the normalize_dates helper function
Browse files Browse the repository at this point in the history
- Test that the `validate_dates` function works if dates are correct or wrong
- Fix issue with past dates. Now we always use current dates in the tests

[Finishes #168261941]
  • Loading branch information
MandelaK committed Sep 12, 2019
1 parent 9b018de commit 8390fff
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion server/graphql_schemas/tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Module that tests helper methods"""
from unittest.mock import patch

import datetime

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

Expand Down Expand Up @@ -89,3 +93,29 @@ 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_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'})

0 comments on commit 8390fff

Please sign in to comment.