def setUpClass(cls): super().setUpClass() cls.password = '******' cls.user = UserFactory(password=cls.password) cls.partner = UserFactory(password=cls.password) cls.partner_obj = PartnerFactory(email_address=cls.partner.email) cls.student = UserFactory(password=cls.password) cls.student_obj = StudentFactory(email_address=cls.student.email) cls.admin = AdminFactory() cls.project = ProjectFactory() #default student cls.groupTypes = ['student', 'project'] #default current Semester (config.CURRENT_SEMESTER) cls.semesters = [s[0] for s in Semester.choices] cls.semesterCt = len(cls.semesters) #default ALL IN cls.filters = ['Sub', 'Rni', 'Int', 'Rwi', 'Ofs', 'Ofr', 'Ofa'] cls.filterTypes = ['ANY', 'ALL'] #default 'students' cls.applicantTypes = ['students', 'scholars'] cls.default_link_values = '&any_all=ANY&Sub=True&Rni=True&Int=True&Rwi=True&Ofs=True&Ofr=True&Ofa=True'
def test_fail_username_override(self): # noqa """ UserFactory will raise IntegrityError when username is collided """ existing_user = UserFactory() with self.assertRaises(IntegrityError): UserFactory(username=existing_user.username)
def setUpClass(cls): super().setUpClass() cls.password = '******' cls.user = UserFactory(password=cls.password) cls.partner = UserFactory(password=cls.password) cls.partner_obj = PartnerFactory(email_address=cls.partner.email) cls.student = UserFactory(password=cls.password) cls.student_obj = StudentFactory(email_address=cls.student.email) cls.logon_redirect = "/profile/login?next=/profile/"
def test_set_up(self): """ setUp: Faker has been seeded, creates Users with the same username """ self.m_unique_username.return_value = (x for x in ('zbeard', 'vporter', 'frobinson')) result = [UserFactory(), UserFactory(), UserFactory()] expected_usernames = ['zbeard', 'vporter', 'frobinson'] self.assertEqual([user.username for user in result], expected_usernames)
def setUp(cls): cls.password = '******' cls.user = UserFactory(password=cls.password) cls.partner = UserFactory(password=cls.password) cls.partner_obj = PartnerFactory(email_address=cls.partner.email) cls.student = UserFactory(password=cls.password) cls.student_obj = StudentFactory(email_address=cls.student.email) cls.admin = AdminFactory()
def setUpClass(cls): super().setUpClass() cls.password = '******' cls.user = UserFactory(password=cls.password) cls.partner = UserFactory(password=cls.password) cls.partner_obj = PartnerFactory(email_address=cls.partner.email) cls.student = UserFactory(password=cls.password) cls.student_obj = StudentFactory(email_address=cls.student.email) cls.project = ProjectFactory()
def setUp(cls): cls.password = '******' cls.user = UserFactory(password=cls.password) cls.partner = UserFactory(password=cls.password) cls.partner_obj = PartnerFactory(email_address=cls.partner.email) cls.student = UserFactory(password=cls.password) cls.student_obj = StudentFactory(email_address=cls.student.email) cls.admin = AdminFactory(password=cls.password) cls.sem_map = {k:v for k, v in Project.sem_mapping.items()} cls.app_status_map = {k:v for k, v in Application.app_status_mapping.items()}
def test_access_roster_partner_with_projects_login_not_reviewable(self): projCt = random.randint(1, 10) partnerProjList = [] partner = UserFactory(password=self.password) partner_obj = PartnerFactory(email_address=partner.email) for i in range(0, projCt): partnerProjList.append( PartnerProjectInfoFactory(project=ProjectFactory(), partner=partner_obj)) config.APPLICATIONS_REVIEWABLE = False self.user_login(partner) self.assertEqual(self.logonRedirect, self.selenium.current_url) self.selenium.get( '%s%s' % (self.live_server_url, reverse('display_student_team_roster'))) expectedMsgs = ["Partners view the roster in applications."] for i, x in enumerate( self.selenium.find_elements_by_class_name("alert-info")): self.assertEqual(x.text, expectedMsgs[i]) expectedMsg = "Applications are not yet open for review. If you believe you have received this message in error, please email [email protected]." self.assertEqual( expectedMsg, self.selenium.find_element_by_id("application-questions").text)
def test_access_get_profile_as_student(self): student = UserFactory(password=self.password) student_obj = StudentFactory(email_address=student.email, first_name=student.first_name, last_name=student.last_name) # add application associate to the student appCt = random.randint(1, 10) appList = [] for i in range(1, appCt): appList.append( ApplicationFactory(project=ProjectFactory(), student=student_obj)) self.user_login(student) # need to reload the page again for now self.selenium.get('%s%s' % (self.live_server_url, reverse('get_profile'))) # show Basic Information directly information page self.basic_information_page_validation(student, student_obj, student_obj._skills)
def test_no_email(self): """ UserFactory can create user without email address """ UserFactory(email='') # act user = self.user_model.objects.first() self.assertEqual(user.email, '')
def test_inactive(self): """ UserFactory can create inactive user """ UserFactory(is_active=False) # act user = self.user_model.objects.first() self.assertFalse(user.is_active)
def test_staff(self): """ UserFactory can create staff user """ UserFactory(is_staff=True) # act user = self.user_model.objects.first() self.assertTrue(user.is_staff)
def test_create_single_existing(self): """ RepositoryFactory fails if user already exists """ UserFactory(username='******') with self.assertRaises(IntegrityError): RepositoryFactory(creator__username='******')
def test_custom_password(self): """ UserFactory can be passed a custom password and sets it """ UserFactory(password='******') # act user = self.user_model.objects.first() self.assertTrue(user.check_password('custom$password'))
def test_fail_validation_username(self): # noqa """ UserFactory will fail with invalid username """ with self.assertRaises(ValidationError) as cm: UserFactory(username='******') self.assertEqual(list(cm.exception.error_dict), ['username'])
def test_create_unusable_pw(self): """ UserFactory can create a user with an unusable password """ UserFactory(password=None) # act user = self.user_model.objects.first() self.assertFalse(user.has_usable_password()) self.assertTrue(user.is_active)
def test_fail_validation_last_name(self): # noqa """ UserFactory with last name too long will fail validation Django limits last names to 30 characters. """ with self.assertRaises(ValidationError) as cm: UserFactory(last_name=151 * 'a') self.assertEqual(list(cm.exception.error_dict), ['last_name'])
def test_retry(self): """ UserFactory retries username generation in case of collision """ self.m_unique_username.return_value = (x for x in ('zbeard', 'vporter')) self.model.objects.create(username='******') result = UserFactory() self.assertEqual(result.username, 'vporter')
def test_documentation(self): """ UserFactory can generate User that can log in as per README README doctring: User can log in """ UserFactory(username='******', password='******') result = self.client.login(username='******', password='******') self.assertIs(result, True)
def test_fail_validation_first_name(self): # noqa """ UserFactory with first name too long will fail validation Before Django 3.1, first names were limited to 30 characters, 150 chars afterwards. """ with self.assertRaises(ValidationError) as cm: UserFactory(first_name=151 * 'a') self.assertEqual(list(cm.exception.error_dict), ['first_name'])
def test_access_student_signup_as_partner(self): partner = UserFactory(password=self.password) partner_obj = PartnerFactory(email_address=partner.email, first_name=partner.first_name, last_name=partner.last_name) projCt = random.randint(1, 10) partnerProjList = [] for i in range(0, projCt): partnerProjList.append( PartnerProjectInfoFactory(project=ProjectFactory(), partner=partner_obj)) self.user_login(partner) self.selenium.get('%s%s' % (self.live_server_url, reverse('student_signup'))) self.assertTrue( self.selenium.find_elements_by_xpath('//h3')[0].text == 'Edit Profile') student = StudentFactory(email_address=partner.email) ifield = [ "first_name", "last_name", "student_id", "major", "resume_link", "general_question", "additional_skills" ] for j in range(0, len(ifield)): self.selenium.find_element_by_name(ifield[j]).send_keys( getattr(student, ifield[j])) bfield = ["college", "year"] for j in range(0, len(bfield)): Select(self.selenium.find_element_by_name( bfield[j])).select_by_value(getattr(student, bfield[j])) skillset = {} for skill in Student.default_skills: skillset[skill] = random.choice( list(filter(None, Student.skill_levels_options.keys()))) for j in skillset: Select(self.selenium.find_element_by_name(j)).select_by_value( skillset[j]) self.selenium.find_element_by_xpath("//input[@type='submit']").click() #show personal information page self.personal_information_page_validation(partner, partnerProjList)
def test_retry_cap(self): # noqa """ UserFactory will only retry 200 times, then raises RuntimeError """ profile_values = ('zbeard',) * 200 profile_values += (ValueError('201st call'),) self.m_unique_username.return_value = (x for x in profile_values) self.model.objects.create(username='******') with self.assertRaises(RuntimeError) as cm: UserFactory() self.assertEqual(self.model.objects.count(), 1) message = cm.exception.args[0] self.assertIn('Unique username not found', message) self.assertIn('Unique values tried: "zbeard"', message)
def test_access_edit_student_profile_as_student_no_update(self): student = UserFactory(password=self.password) student_obj = StudentFactory(email_address=student.email, first_name=student.first_name, last_name=student.last_name) print(student_obj._skills) print(student_obj.to_dict()['skills']) # add application associate to the student appCt = random.randint(1, 10) appList = [] for i in range(1, appCt): appList.append( ApplicationFactory(project=ProjectFactory(), student=student_obj)) self.user_login(student) # need to reload the page again for now self.selenium.get( '%s%s' % (self.live_server_url, reverse('edit_student_profile'))) self.assertTrue( self.selenium.find_elements_by_xpath('//h3')[0].text == 'Edit Profile') # student may not fill up all the skills. UI doesn't allow non-selected skill Level; # update all for now skillset = {} for skill in Student.default_skills: skillset[skill] = random.choice( list(filter(None, Student.skill_levels_options.keys()))) for j in skillset: Select(self.selenium.find_element_by_name(j)).select_by_value( skillset[j]) # no update self.selenium.find_element_by_xpath("//input[@type='submit']").click() self.basic_information_page_validation(student, student_obj, skillset)
def test_access_student_signup_as_student(self): student = UserFactory(password=self.password) student_obj = StudentFactory(email_address=student.email, first_name=student.first_name, last_name=student.last_name) # add application associate to the student appCt = random.randint(1, 10) appList = [] for i in range(1, appCt): appList.append( ApplicationFactory(project=ProjectFactory(), student=student_obj)) self.user_login(student) self.selenium.get('%s%s' % (self.live_server_url, reverse('student_signup')))
def test_make_single(self): """ UserFactory can make a single User * Names and email are generated by Fuzzy and are more than the empty string. * Default password is 'password'. """ result = UserFactory() self.assertEqual(self.user_model.objects.count(), 1) user = self.user_model.objects.first() self.assertEqual(result, user) self.assertGreater(user.username, '') self.assertGreater(user.first_name, '') self.assertGreater(user.last_name, '') self.assertGreater(user.email, '') self.assertTrue(user.check_password('password')) self.assertTrue(user.is_active) self.assertFalse(user.is_staff) self.assertFalse(user.is_superuser)
def test_access_get_profile_as_partner(self): partner = UserFactory(password=self.password) partner_obj = PartnerFactory(email_address=partner.email, first_name=partner.first_name, last_name=partner.last_name) projCt = random.randint(1, 10) partnerProjList = [] for i in range(0, projCt): partnerProjList.append( PartnerProjectInfoFactory(project=ProjectFactory(), partner=partner_obj)) self.user_login(partner) self.selenium.get('%s%s' % (self.live_server_url, reverse('get_profile'))) #show personal information page self.personal_information_page_validation(partner, partnerProjList)
def test_fail_integrity(self): # noqa """ UserFactory will raise IntegrityError saving to DB with missing field """ with self.assertRaises(IntegrityError): UserFactory(first_name=None)