def test_creating_a_user_given_all_valid_arguments_then_user_is_created(self): self.assertEquals(len(self.users), 7) Project.command('create user [email protected] new test-user ta 1112223333 \"test st\"') self.assertEquals(len(self.users), 8)
def test_given_invalid_body_argument_then_error_is_thrown(self): with self.assertRaises(ValueError): Project.command("notify [email protected] \"subject\" 1234")
def test_given_user_is_already_logged_in__then_user_is_logged_out(self): Project.command('login [email protected] test') msg = Project.command('logout') self.assertEqual(msg, 'Goodbye, ta one')
def test_given_a_supervisor_tries_emailing_someone_then_email_is_sent( self): msg = Project.command("notify [email protected] \"subject\" \"body\"") self.assertEqual(msg, "Notification sent")
def test_given_too_many_arguments_then_an_error_message_is_displayed(self): msg = Project.command( "notify [email protected] \"subject\" \"body\" invalid") self.assertEqual(msg, "Too much info for one email")
def test_given_a_new_user_logging_in_for_the_first_time__then_the_user_is_greeted_and_told_to_enter_new_password( self): msg = Project.command('login [email protected]') self.assertEqual(msg, 'Welcome new user. Please enter your new password:')
def test_given_too_many_arguments__then_user_is_not_logged_in(self): msg = Project.command('login [email protected] tests hello') self.assertEqual( msg, 'Sorry, but that is too much information for one user')
def test_delete_a_user_given_user_does_not_exist_then_error_is_displayed(self): msg = Project.command('delete user [email protected]') self.assertEquals(msg, 'That user does not exist')
def test_editing_another_user_given_valid_arguments_then_user_is_edited(self): Project.command('edit user [email protected] firstName:\"newName\"') self.assertEquals(self.users[0]['firstName'], 'newName')
def test_creating_a_user_given_too_many_arguments(self): msg = Project.command('create user [email protected] new test-user ta 1112223333 \"test st\" too-many-arguments') self.assertEquals(msg, 'Too many arguments to create a user')
def test_delete_a_user_given_user_exists_then_user_is_removed(self): self.assertEquals(len(self.users), 7) Project.command('delete user [email protected]') self.assertEquals(len(self.users), 6)
def test_creating_a_user_given_too_few_arguments(self): msg = Project.command('create user [email protected] new test-user ta \"test st\"') self.assertEquals(msg, 'Too few arguments to create a user')
def test_creating_a_user_given_phone_number_has_special_characters_then_value_error_is_thrown(self): with self.assertRaises(ValueError): Project.command('create user [email protected] new test-user ta 111-222-3333 \"test st\"')
def test_creating_a_user_given_address_is_missing_quotes_then_value_error_is_thrown(self): with self.assertRaises(ValueError): Project.command('create user [email protected] new test-user ta 111-222-3333 test')
def test_given_invalid_email__then_user_is_not_logged_in(self): msg = Project.command('login [email protected] test') self.assertEqual(msg, INVALID_LOGIN_MESSAGE)
def test_editing_another_user_given_attribute_that_does_not_exist_then_error_is_displayed(self): msg = Project.command('edit user [email protected] invalid:\"newName\"') self.assertEquals(msg, 'That attribute does not exist')
def test_given_valid_login_and_then_another_login_attempt__then_user_notified_there_is_already_someone_logged_in( self): Project.command('login [email protected] test') msg = Project.command('login [email protected] test') self.assertEqual(msg, 'Sorry, there is already someone logged in.')
def setUp(self): Project.command('login [email protected] test') with open(user_data, 'r') as u_data: self.users = json.load(u_data)
def test_given_too_few_arguments_with_an_old_user__then_user_is_not_logged_in( self): msg = Project.command('login [email protected]') self.assertEqual(msg, INVALID_LOGIN_MESSAGE)
def test_editing_own_information_given_valid_arguments_then_user_info_is_edited(self): Project.command('edit firstName:\"newName\"') self.assertEquals(self.users[4]['firstName'], 'newName')
def setUp(self): Project.command("login [email protected] test")
def test_editing_own_information_given_invalid_arguments_then_error_is_displayed(self): msg = Project.command('edit invalid:\"newName\"') self.assertEquals(msg, 'That attribute does not exist')
def test_given_a_supervisor_tries_emailing_an_invalid_email_then_email_is_sent( self): msg = Project.command("notify [email protected] \"subject\" \"body\"") self.assertEqual(msg, "no@email is an invalid email")
def test_try_editing_other_users_info_then_error_is_displayed(self): msg = Project.command('edit user [email protected] firstName:\"newName\"') self.assertEquals(msg, 'You do not have permission to edit another user')
def test_given_too_few_arguments_then_an_error_message_is_displayed(self): msg = Project.command("notify [email protected] \"subject\"") self.assertEqual(msg, "Not enough info for an email")
def test_given_valid_login__then_user_is_logged_in(self): msg = Project.command('login [email protected] test') self.assertEqual(msg, 'Welcome ta one')
def test_given_a_ta_tries_emailing_someone_then_error_message_is_displayed( self): Project.command("login [email protected] test") msg = Project.command("notify [email protected] \"subject\" \"body\"") self.assertEqual(msg, "TAs cannot send notifications")
def test_given_valid_email_and_invalid_password__then_user_is_not_logged_in( self): msg = Project.command('login [email protected] hello') self.assertEqual(msg, INVALID_LOGIN_MESSAGE)
def test_given_user_is_not_logged_in__then_error_message_is_displayed( self): msg = Project.command('logout') self.assertEqual(msg, 'There are no users to sign out')
def test_assigning_a_lab_to_an_instructor_then_error_is_displayed(self): msg = Project.command('assign lab \"course with ta\" \"lab1\" [email protected]') self.assertEquals(msg, 'Only TAs can be assigned to labs')