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 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'
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)
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 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 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 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_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_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 get_account(self, username=''): accounts = list(Account.objects.filter(user=username)) if len(accounts) == 1: return accounts.__getitem__(0) return Account()
def __init__(self): self.current_user = Account() self.command_list = { "login": lambda *_: self.login(*_), "help": lambda: self.help() }
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")
def logout(self): self.current_user = Account() self.set_command_list() return 'logout successful...'
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")
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 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)