Source code for uw.local.teaching.webui.accommodation_test

import unittest

from datetime import datetime, timedelta

from uw.local.teaching.webui.accommodation import *

[docs]class AccomodationTests (unittest.TestCase):
[docs] def setUp (self): """ Set up method that runs before each test case. """ pass
[docs] def test_format_room_valid_input (self): """ Tests if format_room () works as expected with valid input. """ self.assertEqual (format_room ('E7', 4433), 'E7 4433')
[docs] def test_format_room_no_building_code (self): """ Tests if format_room () works as expected when building code is None. """ self.assertIsNone (format_room (None, 4433))
[docs] def test_parse_class_id_invalid_class (self): """ Tests if parse_class_id () functions as expected when given an invalid class id. """ errors = [] self.assertIsNone (parse_class_id (None, [], errors, 'not an int', '1', 'ECE', 240)) self.assertEqual (errors, ["Invalid class number"])
[docs] def test_parse_class_id_invalid_section (self): """ Tests if parse_class_id () functions as expected when given an invalid section code. """ errors = [] self.assertIsNone (parse_class_id (None, [], errors, '1', 240, 'ECE', 'not an int')) self.assertEqual (errors, ["Invalid section number"])
[docs] def test_parse_class_id_both_invalid (self): """ Tests if parse_class_id () functions as expected when given an invalid section code and class id. """ errors = [] self.assertIsNone (parse_class_id (None, [], errors, 'not an int', 240, 'ECE', 'not an int')) self.assertEqual (errors, ["Invalid class number"])
[docs] def test_parse_class_id_nonexistent_class (self): """ TODO: Tests parse_class_id () given a nonexistent class section. """ pass
[docs] def test_parse_class_id_no_errors (self): """ TODO: Tests parse_class_id () given inputs that shouldn't hit any of the error checks. """ pass
[docs] def test_parse_start_time_invalid_exam_date (self): """Tests parse_start_time () given an invalid exam date """ errors = [] result = {} self.assertIsNone (parse_start_time (None, result, errors, 'invalid date string', '12:30 PM')) self.assertEqual (result, {}) self.assertEqual (errors, ['Invalid assessment date'])
[docs] def test_parse_start_time_invalid_start_time (self): """Tests parse_start_time () given an invalid start time """ errors = [] result = {} self.assertIsNone (parse_start_time (None, result, errors, '01/01/2018', 'invalid time string')) self.assertEqual (result, {}) self.assertEqual (errors, ['Invalid assessment time'])
[docs] def test_parse_start_time_valid_inputs (self): """Tests parse_start_time () given all inputs are valid """ errors = [] result = {} parsed_start_time = { 'start_time': datetime (2018, 1, 1, 12, 30), } self.assertIsNone (parse_start_time (None, result, errors, '01/01/2018', '12:30 PM')) self.assertEqual (parsed_start_time, result) self.assertEqual (errors, [])
[docs] def test_parse_duration_invalid_value (self): """Tests parse_duration () given an invalid value """ errors = [] result = {} self.assertIsNone (parse_duration (None, result, errors, 'not an int')) self.assertEqual (result, {}) self.assertEqual (errors, ['Invalid duration'])
[docs] def test_parse_duration_valid_inputs (self): """Tests parse_duration () given all inputs are valid """ errors = [] result = {} parsed_duration = { 'override_duration': timedelta (minutes=30) } self.assertIsNone (parse_duration (None, result, errors, 30)) self.assertEqual (parsed_duration, result) self.assertEqual (errors, [])
[docs] def test_parse_extra_input_not_none (self): """Tests parse_extra given a non-none input. """ self.assertEqual (parse_extra ('extra'), {'extra_candidate': 'extra'})
def test_parse_extra_input_is_none (self): """Tests parse_extra given a NoneType input. """ self.assertEqual (parse_extra (None), {'extra_candidate': False})
[docs] def test_parse_remove_input_not_none (self): """Tests parse_remove given a non-none input. """ self.assertEqual (parse_remove ('remove'), {'remove': 'remove'})
[docs] def test_parse_extra_input_is_none (self): """Tests parse_remove given a NoneType input. """ self.assertEqual (parse_remove (None), {'remove': False})