File size: 4,038 Bytes
550665c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
from unittest import TestCase
from gcsa.serializers.settings_serializer import SettingsSerializer
from gcsa.settings import Settings
class TestSettings(TestCase):
def test_repr_str(self):
settings = Settings(
auto_add_hangouts=True,
date_field_order='DMY',
default_event_length=45,
format24_hour_time=True,
hide_invitations=True,
hide_weekends=True,
locale='cz',
remind_on_responded_events_only=True,
show_declined_events=False,
timezone='Europe/Prague',
use_keyboard_shortcuts=False,
week_start=1,
)
expected_str = \
"User settings:\n" \
"auto_add_hangouts=True\n" \
"date_field_order=DMY\n" \
"default_event_length=45\n" \
"format24_hour_time=True\n" \
"hide_invitations=True\n" \
"hide_weekends=True\n" \
"locale=cz\n" \
"remind_on_responded_events_only=True\n" \
"show_declined_events=False\n" \
"timezone=Europe/Prague\n" \
"use_keyboard_shortcuts=False\n" \
"week_start=1"
self.assertEqual(settings.__str__(), expected_str)
self.assertEqual(settings.__repr__(), expected_str)
class TestSettingsSerializer(TestCase):
def test_to_json(self):
settings = Settings(
auto_add_hangouts=True,
date_field_order='DMY',
default_event_length=45,
format24_hour_time=True,
hide_invitations=True,
hide_weekends=True,
locale='cz',
remind_on_responded_events_only=True,
show_declined_events=False,
timezone='Europe/Prague',
use_keyboard_shortcuts=False,
week_start=1,
)
expected_json = {
'autoAddHangouts': settings.auto_add_hangouts,
'dateFieldOrder': settings.date_field_order,
'defaultEventLength': settings.default_event_length,
'format24HourTime': settings.format24_hour_time,
'hideInvitations': settings.hide_invitations,
'hideWeekends': settings.hide_weekends,
'locale': settings.locale,
'remindOnRespondedEventsOnly': settings.remind_on_responded_events_only,
'showDeclinedEvents': settings.show_declined_events,
'timezone': settings.timezone,
'useKeyboardShortcuts': settings.use_keyboard_shortcuts,
'weekStart': settings.week_start
}
self.assertDictEqual(SettingsSerializer(settings).get_json(), expected_json)
def test_to_object(self):
settings_json = {
'autoAddHangouts': True,
'dateFieldOrder': 'DMY',
'defaultEventLength': 45,
'format24HourTime': True,
'hideInvitations': True,
'hideWeekends': True,
'locale': 'cz',
'remindOnRespondedEventsOnly': True,
'showDeclinedEvents': False,
'timezone': 'Europe/Prague',
'useKeyboardShortcuts': False,
'weekStart': 1,
}
settings = SettingsSerializer(settings_json).get_object()
self.assertTrue(settings.auto_add_hangouts)
self.assertEqual(settings.date_field_order, 'DMY')
self.assertEqual(settings.default_event_length, 45)
self.assertTrue(settings.format24_hour_time)
self.assertTrue(settings.hide_invitations)
self.assertTrue(settings.hide_weekends)
self.assertEqual(settings.locale, 'cz')
self.assertTrue(settings.remind_on_responded_events_only)
self.assertFalse(settings.show_declined_events)
self.assertEqual(settings.timezone, 'Europe/Prague')
self.assertFalse(settings.use_keyboard_shortcuts)
self.assertEqual(settings.week_start, 1)
|