Example #1
0
    def create_account(self, username='', password='', role=''):
        if username == '' or password == '' or role == '':
            return 'Failed to create account. Invalid or missing argument'

        # check that current user has correct permissions to create account
        cur_user_role = self.get_current_user().role
        if cur_user_role != 'Supervisor' and cur_user_role != 'Administrator':
            return 'Failed to create account. Insufficient permissions'
        if cur_user_role == 'Administrator' and role == 'Supervisor':
            return 'Failed to create account. Insufficient permissions'

        valid_roles = ['Supervisor', 'Administrator', 'Instructor', 'TA']
        role_is_valid = valid_roles.__contains__(role)
        if not role_is_valid:
            msg = 'Failed to create account. Invalid account type'
            msg += '\nValid roles are ' + str(valid_roles)
            return msg

        existing_account = self.get_account(username)
        if existing_account.id is not None:
            return 'Failed to create account. User already exists'

        new_account = Account(user=username, password=password, role=role)
        new_account.save()
        return 'Successfully created account'
Example #2
0
 def test_view_ta_assignments_single_ta_multiple_course_as_ta(self):
     self.ui.login("usrTA", "password")
     test_ta2 = Account(user="******", password="******", role="TA")
     test_ta2.save()
     test_course = Course(name="CS103",
                          section="222",
                          days_of_week="M/W/F",
                          start_time="12:00",
                          end_time="13:00",
                          instructor=self.tst_instructor,
                          lab="333")
     test_course.save()
     test_course.tas.add(self.tst_ta)
     test_course2 = Course(name="CS104",
                           section="223",
                           days_of_week="M/W/F",
                           start_time="14:00",
                           end_time="15:00",
                           instructor=self.tst_instructor,
                           lab="363")
     test_course2.save()
     test_course2.tas.add(test_ta2)
     expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + \
                       ", TA(s): " + self.tst_ta.user + " </p><br />" + \
                       "<p>Course: " + test_course2.name + ", Section: " + test_course2.section + \
                       ", TA(s): " + test_ta2.user + " </p><br />"
     actual_output = self.ui.view_ta_assignments()
     self.assertEqual(expected_output, actual_output)
class TestReadContactInfo(TestCase):
    def setUp(self):
        self.ui = Commands()
        self.tst_supervisor = Account(
            user='******',
            password='******',
            role='Supervisor',
            street_address='3200 N Newport Ave Milwaukee WI 53211',
            email_address='*****@*****.**',
            phone_number='414-736-9565')
        self.tst_administrator = Account(
            user='******',
            password='******',
            role='Administrator',
            street_address='1026 S 27th St Milwaukee WI 53221',
            email_address='*****@*****.**',
            phone_number='920-223-5166')
        self.tst_instructor = Account(
            user='******',
            password='******',
            role='Instructor',
            street_address='2466 N 13th St Milwaukee WI 53201',
            email_address='*****@*****.**',
            phone_number='262-115-1107')
        self.tst_ta = Account(
            user='******',
            password='******',
            role='TA',
            street_address='2466A N 13th St Milwaukee WI 53201',
            email_address='*****@*****.**',
            phone_number='262-115-1109')
        self.tst_supervisor.save()
        self.tst_administrator.save()
        self.tst_instructor.save()
        self.tst_ta.save()

        # TODO: Create a string that is the expected output of read_contact_info()
        # Will probably have some html formatting in it
        self.expected_output = 'nothingYet'

    def test_supervisor_read_contact_info(self):
        self.ui.current_user = self.tst_supervisor
        actual_output = self.ui.read_contact_info()
        self.assertEqual(actual_output, self.expected_output)

    def test_administrator_read_contact_info(self):
        self.ui.current_user = self.tst_administrator
        actual_output = self.ui.read_contact_info()
        self.assertEqual(actual_output, self.expected_output)

    def test_instructor_read_contact_info(self):
        self.ui.current_user = self.tst_instructor
        actual_output = self.ui.read_contact_info()
        self.assertEqual(actual_output, self.expected_output)

    def test_ta_read_contact_info(self):
        self.ui.current_user = self.tst_ta
        actual_output = self.ui.read_contact_info()
        self.assertEqual(actual_output, self.expected_output)
Example #4
0
 def test_login_bad_password(self):
     self.ui.current_user = Account()
     username = '******'
     expected_output = 'login failed! bad username/ password'
     actual_output = self.ui.login(username, 'badPassword')
     self.assertEqual(expected_output, actual_output)
     self.assertNotEqual(self.ui.current_user.user, username)
     self.assertTrue(self.ui.current_user.id is None)
Example #5
0
 def setUp(self):
     self.ui = Commands()
     self.tst_supervisor = Account(user='******', password='******', role='Supervisor')
     self.tst_administrator = Account(user='******', password='******', role='Administrator')
     self.tst_instructor = Account(user='******', password='******', role='Instructor')
     self.tst_ta = Account(user='******', password='******', role='TA')
     self.tst_supervisor.save()
     self.tst_administrator.save()
     self.tst_instructor.save()
     self.tst_ta.save()
Example #6
0
 def test_call_command_valid(self):
     self.ui.current_user = Account()
     self.ui.set_command_list()
     output1 = self.ui.call_command('help')
     output2 = self.ui.call_command('login usrSupervisor password')
     output3 = self.ui.call_command('logout')
     self.assertNotEqual(output1, 'You should type something...')
     self.assertNotEqual(output2, 'You should type something...')
     self.assertNotEqual(output3, 'You should type something...')
     self.assertNotEqual(output1, 'Too many arguments entered. Try again!')
     self.assertNotEqual(output2, 'Too many arguments entered. Try again!')
     self.assertNotEqual(output3, 'Too many arguments entered. Try again!')
     self.assertNotEqual(output1, 'ERROR: this is not an available command')
     self.assertNotEqual(output2, 'ERROR: this is not an available command')
     self.assertNotEqual(output3, 'ERROR: this is not an available command')
Example #7
0
 def test_view_course_assignments_multiple_courses_multiple_instructors_as_administrator(self):
     self.ui.login('usrAdministrator', 'password')
     test_instructor2 = Account(user='******', password='******', role='Instructor')
     test_instructor2.save()
     test_course1 = Course(name="CS103",
                           section="222",
                           days_of_week="M/W/F",
                           start_time="12:00",
                           end_time="13:00",
                           instructor=self.tst_instructor,
                           lab="333")
     test_course1.save()
     test_course2 = Course(name="CS104",
                           section="223",
                           days_of_week="M/W/F",
                           start_time="14:00",
                           end_time="15:00",
                           instructor=test_instructor2,
                           lab="363")
     test_course2.save()
     expected_output = "<p>Course: " + test_course1.name + ", Instructor: " + self.tst_instructor.user + "</p><br />" + \
                       "<p>Course: " + test_course2.name + ", Instructor: " + test_instructor2.user + "</p><br />"
     actual_output = self.ui.view_course_assignments()
     self.assertEqual(expected_output, actual_output)
Example #8
0
    def test_login_ta(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_ta)

        commands = self.ui.command_list
        expected_num_commands = 5
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))
Example #9
0
class TestEditAccount(TestCase):
    def setUp(self):
        self.ui = Commands()
        self.tst_supervisor = Account(user='******',
                                      password='******',
                                      role='Supervisor')
        self.tst_administrator = Account(user='******',
                                         password='******',
                                         role='Administrator')
        self.tst_instructor = Account(user='******',
                                      password='******',
                                      role='Instructor')
        self.tst_ta = Account(user='******', password='******', role='TA')
        self.tst_supervisor.save()
        self.tst_administrator.save()
        self.tst_instructor.save()
        self.tst_ta.save()

    def test_edit_account_insufficient_permissions(self):
        self.ui.login('usrSupervisor', 'password')
        newPhone = '414-368-6425'
        expected_output = 'Failed to edit account. Insufficient permissions'
        actual_output = self.ui.edit_account(self.tst_ta.user,
                                             phone_number=newPhone)
        self.assertNotEqual(expected_output, actual_output)

    def test_edit_account_address(self):
        self.ui.login('usrSupervisor', 'password')
        newAddress = '1026 Lake Dr Milwaukee WI'
        expected_output = 'Account information successfully changed'
        actual_output = self.ui.edit_account(self.tst_ta.user,
                                             street_address=newAddress)
        self.assertEqual(expected_output, actual_output)

    def test_edit_account_phone(self):
        self.ui.login('usrSupervisor', 'password')
        newPhone = '414-368-6425'
        expected_output = 'Account information successfully changed'
        actual_output = self.ui.edit_account(self.tst_ta.user,
                                             phone_number=newPhone)
        self.assertEqual(expected_output, actual_output)
Example #10
0
    def setUp(self):
        self.ui = Commands()
        self.tst_supervisor = Account(user='******',
                                      password='******',
                                      role='Supervisor')
        self.tst_administrator = Account(user='******',
                                         password='******',
                                         role='Administrator')
        self.tst_instructor = Account(user='******',
                                      password='******',
                                      role='Instructor')
        self.tst_ta = Account(user='******', password='******', role='TA')
        self.tst_supervisor.save()
        self.tst_administrator.save()
        self.tst_instructor.save()
        self.tst_ta.save()

        self.tst_course = Course(name="EE-554",
                                 section="004",
                                 days_of_week="M/W/F",
                                 start_time="11:00",
                                 end_time="11:50")
        self.tst_course.save()
Example #11
0
    def test_login_supervisor(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_supervisor)

        commands = self.ui.command_list
        expected_num_commands = 13
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('delete_account'))
        self.assertTrue(commands.__contains__('edit_account'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('assign_instructor'))
        self.assertTrue(commands.__contains__('assign_ta_to_course'))
        self.assertTrue(commands.__contains__('assign_ta_to_lab'))
        self.assertTrue(commands.__contains__('view_course_assignments'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))
Example #12
0
 def get_account(self, username=''):
     accounts = list(Account.objects.filter(user=username))
     if len(accounts) == 1:
         return accounts.__getitem__(0)
     return Account()
Example #13
0
 def __init__(self):
     self.current_user = Account()
     self.command_list = {
         "login": lambda *_: self.login(*_),
         "help": lambda: self.help()
     }
Example #14
0
 def logout(self):
     self.current_user = Account()
     self.set_command_list()
     return 'logout successful...'
Example #15
0
 def test_CommandsAssignTaToCourse1(self):
     self.co.current_user = Account()
     response = self.co.assign_ta_to_course('Joe', 'CS-361')
     self.assertEqual(
         response, "You do not have permissions to assign TAs to courses")
Example #16
0
 def test_CommandsAssignInstructor1(self):
     self.co.current_user = Account()
     response = self.co.assign_instructor('Joe', 'CS-361')
     self.assertEqual(
         response,
         "You do not have permissions to assign instructors to courses")
Example #17
0
 def test_help_with_no_current_user(self):
     self.ui.current_user = Account()
     output = self.ui.help()
     self.assertTrue(output.find('login'))
     self.assertTrue(output.find('help'))
Example #18
0
class TestCommands(TestCase):
    def setUp(self):
        self.ui = Commands()
        self.tst_supervisor = Account(user='******',
                                      password='******',
                                      role='Supervisor')
        self.tst_administrator = Account(user='******',
                                         password='******',
                                         role='Administrator')
        self.tst_instructor = Account(user='******',
                                      password='******',
                                      role='Instructor')
        self.tst_ta = Account(user='******', password='******', role='TA')
        self.tst_supervisor.save()
        self.tst_administrator.save()
        self.tst_instructor.save()
        self.tst_ta.save()

        self.tst_course = Course(name="EE-554",
                                 section="004",
                                 days_of_week="M/W/F",
                                 start_time="11:00",
                                 end_time="11:50")
        self.tst_course.save()

    def test_call_command_valid(self):
        self.ui.current_user = Account()
        self.ui.set_command_list()
        output1 = self.ui.call_command('help')
        output2 = self.ui.call_command('login usrSupervisor password')
        output3 = self.ui.call_command('logout')
        self.assertNotEqual(output1, 'You should type something...')
        self.assertNotEqual(output2, 'You should type something...')
        self.assertNotEqual(output3, 'You should type something...')
        self.assertNotEqual(output1, 'Too many arguments entered. Try again!')
        self.assertNotEqual(output2, 'Too many arguments entered. Try again!')
        self.assertNotEqual(output3, 'Too many arguments entered. Try again!')
        self.assertNotEqual(output1, 'ERROR: this is not an available command')
        self.assertNotEqual(output2, 'ERROR: this is not an available command')
        self.assertNotEqual(output3, 'ERROR: this is not an available command')

    def testCallCommandInvalid(self):
        expected_output = 'ERROR: this is not an available command'
        actual_output = self.ui.call_command('invalidCommand')
        self.assertEqual(expected_output, actual_output)

    def test_call_command_too_many_args(self):
        expected_output = 'Too many arguments entered. Try again!'
        actual_output = self.ui.call_command('login user password oops')
        self.assertEqual(expected_output, actual_output)

    def test_call_command_no_args(self):
        expected_output = ''
        actual_output = self.ui.call_command()
        self.assertEqual(expected_output, actual_output)

    def test_help_with_no_current_user(self):
        self.ui.current_user = Account()
        output = self.ui.help()
        self.assertTrue(output.find('login'))
        self.assertTrue(output.find('help'))

    def test_help_as_supervisor(self):
        self.ui.current_user = self.tst_supervisor
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('delete_account'))
        self.assertTrue(output.find('edit_account'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('assign_instructor'))
        self.assertTrue(output.find('assign_ta_to_course'))
        self.assertTrue(output.find('assign_ta_to_lab'))
        self.assertTrue(output.find('view_course_assignments'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_help_as_administrator(self):
        self.ui.current_user = self.tst_administrator
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('delete_account'))
        self.assertTrue(output.find('edit_account'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('view_course_assignments'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_help_as_instructor(self):
        self.ui.current_user = self.tst_instructor
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('assign_ta_to_lab'))
        self.assertTrue(output.find('view_course_assignments'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_help_as_ta(self):
        self.ui.current_user = self.tst_ta
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_login_bad_username(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login failed! bad username/ password'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertNotEqual(self.ui.current_user.user, username)
        self.assertTrue(self.ui.current_user.id is None)

    def test_login_bad_password(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login failed! bad username/ password'
        actual_output = self.ui.login(username, 'badPassword')
        self.assertEqual(expected_output, actual_output)
        self.assertNotEqual(self.ui.current_user.user, username)
        self.assertTrue(self.ui.current_user.id is None)

    def test_login_supervisor(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_supervisor)

        commands = self.ui.command_list
        expected_num_commands = 13
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('delete_account'))
        self.assertTrue(commands.__contains__('edit_account'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('assign_instructor'))
        self.assertTrue(commands.__contains__('assign_ta_to_course'))
        self.assertTrue(commands.__contains__('assign_ta_to_lab'))
        self.assertTrue(commands.__contains__('view_course_assignments'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_login_administrator(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_administrator)

        commands = self.ui.command_list
        expected_num_commands = 10
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('delete_account'))
        self.assertTrue(commands.__contains__('edit_account'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('view_course_assignments'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_login_instructor(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_instructor)

        commands = self.ui.command_list
        expected_num_commands = 7
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('assign_ta_to_lab'))
        self.assertTrue(commands.__contains__('view_course_assignments'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_login_ta(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_ta)

        commands = self.ui.command_list
        expected_num_commands = 5
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_logout(self):
        self.ui.login('usrSupervisor', 'password')
        expected_output = 'logout successful...'
        actual_output = self.ui.logout()
        self.assertEqual(expected_output, actual_output)
        self.assertIsNone(self.ui.get_current_user().id)

        commands = self.ui.command_list
        expected_num_commands = 2
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('login'))
        self.assertTrue(commands.__contains__('help'))

    def test_create_account_as_supervisor(self):
        self.ui.login('usrSupervisor', 'password')
        username = '******'
        password = '******'
        role = 'Supervisor'
        expected_output = 'Successfully created account'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNotNone(created_account.id)
        self.assertEqual(created_account.user, username)
        self.assertEqual(created_account.password, password)
        self.assertEqual(created_account.role, role)

    def test_create_account_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        expected_output = 'Successfully created account'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNotNone(created_account.id)
        self.assertEqual(created_account.user, username)
        self.assertEqual(created_account.password, password)
        self.assertEqual(created_account.role, role)

    def test_create_supervisor_account_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        username = '******'
        password = '******'
        role = 'Supervisor'
        expected_output = 'Failed to create account. Insufficient permissions'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNone(created_account.id)

    def test_create_account_as_instructor(self):
        self.ui.login('usrInstructor', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        expected_output = 'Failed to create account. Insufficient permissions'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNone(created_account.id)

    def test_create_account_as_ta(self):
        self.ui.login('usrTA', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        initial_count = Account.objects.count()
        expected_output = 'Failed to create account. Insufficient permissions'
        actual_output = self.ui.create_account(username, password, role)
        final_count = Account.objects.count()
        created_account = self.ui.get_account(username)
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)
        self.assertIsNone(created_account.id)

    def test_create_account_existing_user(self):
        self.ui.login('usrSupervisor', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        expected_output = 'Failed to create account. User already exists'
        initial_count = Account.objects.count()
        actual_output = self.ui.create_account(username, password, role)
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_as_supervisor(self):
        self.ui.login('usrSupervisor', 'password')
        self.ui.create_account('tstDeleteAcc', 'password', 'TA')
        expected_output = 'Successfully deleted account'
        initial_count = Account.objects.count()
        expected_count = initial_count - 1
        actual_output = self.ui.delete_account('tstDeleteAcc')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(expected_count, final_count)

    def test_delete_account_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        self.ui.create_account('tstDeleteAcc', 'password', 'TA')
        initial_count = Account.objects.count()
        expected_count = initial_count - 1
        expected_output = 'Successfully deleted account'
        actual_output = self.ui.delete_account('tstDeleteAcc')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(expected_count, final_count)

    def test_delete_account_not_exist(self):
        self.ui.login('usrSupervisor', 'password')
        expected_output = 'Failed to delete account. User not found'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('notExist')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_supervisor_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        expected_output = 'Failed to delete account. Insufficient permissions'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('usrSupervisor')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_as_Instructor(self):
        self.ui.login('usrInstructor', 'password')
        expected_output = 'Failed to delete account. Insufficient permissions'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('usrTA')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_as_TA(self):
        self.ui.login('usrTA', 'password')
        expected_output = 'Failed to delete account. Insufficient permissions'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('usrTA')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_assigned_to_course(self):
        self.ui.login('usrSupervisor', 'password')
        self.tst_course.instructor = self.tst_instructor
        self.tst_course.save()
        self.assertEqual(self.tst_course.instructor, self.tst_instructor)
        num_courses_initial = Course.objects.count()
        num_accounts_initial = Account.objects.count()
        expected_output = 'Failed to delete account. User is assigned to a course'
        actual_output = self.ui.delete_account(self.tst_instructor.user)
        self.assertEqual(self.tst_course.instructor, self.tst_instructor)
        num_courses_final = Course.objects.count()
        num_accounts_final = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(num_accounts_initial, num_accounts_final)
        self.assertEqual(num_courses_initial, num_courses_final)
Example #19
0
def get_offers(request):

	CommonUtilsInstance = CommonUtils()
	# built of date selector
	# days list
	days_choices = CommonUtilsInstance.get_days_list_choice()
	# months list
	months_choices = CommonUtilsInstance.get_months_list_choice()
	# years list
	years_choices = CommonUtilsInstance.get_years_list_choice()

	context = {
		"post" : request.POST,
		"days_choices" : days_choices,
		"months_choices" : months_choices,
		"years_choices" : years_choices,
	}

	# se la mail dell'utente non esiste inserisco i dati
	# altrimenti per il momento non permetto la modifica di una mail gia esistente
	if (request.POST.get("get_offers_form_sent", "")):
		if(request.POST.get("email", "") and request.POST.get("disclaimer", "")):
			try:
				account_obj = Account.objects.get(email=request.POST['email'])
			except (KeyError, Account.DoesNotExist):
				logger.debug('Nuovo utente registrato: ' + str(request.POST['email']))
				account_obj = Account(
					first_name = request.POST['first_name'],
					last_name = request.POST['last_name'],
					email = request.POST['email'],
					mobile_phone = request.POST['phone'],
					receive_promotions = 1,
				)

				try:
					birthday = datetime.date(int(request.POST['birthday_year']),
                                                    int(request.POST['birthday_month']),
                                                    int(request.POST['birthday_day'])
					)
					account_obj.birthday_date = birthday
				except:
					logger.debug("Data di nascita non inserita")
					pass

				# saving account information
				account_obj.save()

				# if user successfully inserted, than showing a success message
				messages.add_message(request, messages.SUCCESS, 'Grazie per la tua registrazione!')
				return HttpResponseRedirect(reverse(get_offers))
			else:
				messages.add_message(request, messages.ERROR, "Attenzione utente già esistente")
				logger.debug("Utente gia' esistente in db")
		else:
			messages.add_message(request, messages.ERROR, 'Per continuare è necessario inserire una mail e confermare il trattamento dei dati personali.')
			logger.debug('Attenzione: inserire email e/o confermare disclaimer')
	else:
		# logger.debug('Attenzione: submit del form non ancora eseguito')
		pass

	return render(request, 'website/get_offers.html', context)
Example #20
0
class TestViewCourseAssignments(TestCase):

    def setUp(self):
        self.ui = Commands()
        self.tst_supervisor = Account(user='******', password='******', role='Supervisor')
        self.tst_administrator = Account(user='******', password='******', role='Administrator')
        self.tst_instructor = Account(user='******', password='******', role='Instructor')
        self.tst_ta = Account(user='******', password='******', role='TA')
        self.tst_supervisor.save()
        self.tst_administrator.save()
        self.tst_instructor.save()
        self.tst_ta.save()

    def test_view_course_assignments_no_user(self):
        expected_output = "Failed to view course assignments. No current user"
        actual_output = self.ui.view_course_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_course_assignments_as_ta(self):
        self.ui.login('usrTA', 'password')
        expected_output = "Failed to view course assignments. Insufficient permissions"
        actual_output = self.ui.view_course_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_course_assignments_as_instructor(self):
        self.ui.login('usrInstructor', 'password')
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        expected_output = "<p>Course: " + test_course.name + ", Instructor: " + self.tst_instructor.user + "</p><br />"
        actual_output = self.ui.view_course_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_course_assignments_as_supervisor(self):
        self.ui.login('usrSupervisor', 'password')
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        expected_output = "<p>Course: " + test_course.name + ", Instructor: " + self.tst_instructor.user + "</p><br />"
        actual_output = self.ui.view_course_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_course_assignments_as_Administrator(self):
        self.ui.login('usrAdministrator', 'password')
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        expected_output = "<p>Course: " + test_course.name + ", Instructor: " + self.tst_instructor.user + "</p><br />"
        actual_output = self.ui.view_course_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_course_assignments_multiple_courses_multiple_instructors_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        test_instructor2 = Account(user='******', password='******', role='Instructor')
        test_instructor2.save()
        test_course1 = Course(name="CS103",
                              section="222",
                              days_of_week="M/W/F",
                              start_time="12:00",
                              end_time="13:00",
                              instructor=self.tst_instructor,
                              lab="333")
        test_course1.save()
        test_course2 = Course(name="CS104",
                              section="223",
                              days_of_week="M/W/F",
                              start_time="14:00",
                              end_time="15:00",
                              instructor=test_instructor2,
                              lab="363")
        test_course2.save()
        expected_output = "<p>Course: " + test_course1.name + ", Instructor: " + self.tst_instructor.user + "</p><br />" + \
                          "<p>Course: " + test_course2.name + ", Instructor: " + test_instructor2.user + "</p><br />"
        actual_output = self.ui.view_course_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_course_assignments_no_instructor_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             lab="333")
        test_course.save()
        test_course2 = Course(name="CS104",
                              section="223",
                              days_of_week="M/W/F",
                              start_time="14:00",
                              end_time="15:00",
                              instructor=self.tst_instructor,
                              lab="363")
        test_course2.save()
        expected_output = "<p>Course: " + test_course2.name + ", Instructor: " + self.tst_instructor.user + "</p><br />"
        actual_output = self.ui.view_course_assignments()
        self.assertEqual(expected_output, actual_output)

    # =====================================================================
    def test_view_ta_assignments_no_user(self):
        expected_output = "Failed to view ta assignments. No current user"
        actual_output = self.ui.view_ta_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_ta_assignments_single_ta_single_course_as_ta(self):
        self.ui.login("usrTA", "password")
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        test_course.tas.add(self.tst_ta)
        expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + ", TA(s): " + self.tst_ta.user + " </p><br />"
        actual_output = self.ui.view_ta_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_ta_assignments_single_ta_single_course_as_instructor(self):
        self.ui.login("usrInstructor", "password")
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        test_course.tas.add(self.tst_ta)
        expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + ", TA(s): " + self.tst_ta.user + " </p><br />"
        actual_output = self.ui.view_ta_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_ta_assignments_single_ta_single_course_as_supervisor(self):
        self.ui.login("usrSupervisor", "password")
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        test_course.tas.add(self.tst_ta)
        expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + ", TA(s): " + self.tst_ta.user + " </p><br />"
        actual_output = self.ui.view_ta_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_ta_assignments_single_ta_single_course_as_administrator(self):
        self.ui.login("usrAdministrator", "password")
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        test_course.tas.add(self.tst_ta)
        expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + ", TA(s): " + self.tst_ta.user + " </p><br />"
        actual_output = self.ui.view_ta_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_ta_assignments_multiple_ta_single_course_as_ta(self):
        self.ui.login("usrTA", "password")
        test_ta2 = Account(user="******", password="******", role="TA")
        test_ta2.save()
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        test_course.tas.add(self.tst_ta)
        test_course.tas.add(test_ta2)
        expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + ", TA(s): " + self.tst_ta.user + " " + test_ta2.user + " </p><br />"
        actual_output = self.ui.view_ta_assignments()
        self.assertEqual(expected_output, actual_output)

    def test_view_ta_assignments_single_ta_multiple_course_as_ta(self):
        self.ui.login("usrTA", "password")
        test_ta2 = Account(user="******", password="******", role="TA")
        test_ta2.save()
        test_course = Course(name="CS103",
                             section="222",
                             days_of_week="M/W/F",
                             start_time="12:00",
                             end_time="13:00",
                             instructor=self.tst_instructor,
                             lab="333")
        test_course.save()
        test_course.tas.add(self.tst_ta)
        test_course2 = Course(name="CS104",
                              section="223",
                              days_of_week="M/W/F",
                              start_time="14:00",
                              end_time="15:00",
                              instructor=self.tst_instructor,
                              lab="363")
        test_course2.save()
        test_course2.tas.add(test_ta2)
        expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + \
                          ", TA(s): " + self.tst_ta.user + " </p><br />" + \
                          "<p>Course: " + test_course2.name + ", Section: " + test_course2.section + \
                          ", TA(s): " + test_ta2.user + " </p><br />"
        actual_output = self.ui.view_ta_assignments()
        self.assertEqual(expected_output, actual_output)