def test_set_primary_email(self): """ Calling the set_as_primary method in the SecondaryEmail removes it from SecondaryEmail, replaces the current address on the User model, and adds the replaced address to the SecondaryEmail table. """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) new_primary = secondary_email.email for email in [old_primary, new_primary]: # Emails must be verified to make them primary. activation = ActivationProfile.objects.get_or_create( user=self.user, email=email)[0] ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get(email=new_primary) secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=new_primary) old_email = SecondaryEmail.objects.get(email=old_primary) self.assertTrue(old_email.verified) user = User.objects.get(email=new_primary)
def test_set_primary_email(self): """ Calling the set_as_primary method in the SecondaryEmail removes it from SecondaryEmail, replaces the current address on the User model, and adds the replaced address to the SecondaryEmail table. """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) new_primary = secondary_email.email for email in [old_primary, new_primary]: # Emails must be verified to make them primary. activation = ActivationProfile.objects.get_or_create(user=self.user, email=email)[0] ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get(email=new_primary) secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=new_primary) old_email = SecondaryEmail.objects.get(email=old_primary) self.assertTrue(old_email.verified) user = User.objects.get(email=new_primary)
def test_delete_secondary_email(self): """ Deleting a secondary email should also delete its activation profile """ self.assertEqual(ActivationProfile.objects.count(), 0) secondary_email = SecondaryEmailFactory(user=self.user) self.assertEqual(ActivationProfile.objects.count(), 1) secondary_email.delete() self.assertEqual(ActivationProfile.objects.count(), 0)
def test_delete_secondary_email(self): """ Deleting a secondary email should also delete its activation profile """ self.assertEqual(ActivationProfile.objects.count(), 0) secondary_email = SecondaryEmailFactory(user=self.user) self.assertEqual(ActivationProfile.objects.count(), 1) secondary_email.delete() self.assertEqual(ActivationProfile.objects.count(), 0)
def test_same_secondary_email(self): """ All emails are unique. If an email is used as a user's primary email or another secondary email, it may not be used as a secondary email again. """ secondary_email = SecondaryEmailFactory(user=self.user) with transaction.atomic(): with self.assertRaises(IntegrityError): new_secondary_email = SecondaryEmailFactory(user=self.user) new_secondary_email = SecondaryEmailFactory(user=self.user, email='*****@*****.**')
def test_unverified_primary_email(self): """ Only verified emails can be set as the primary email """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) primary = secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=old_primary) self.assertFalse(primary) user = User.objects.get(email=old_primary) self.assertEqual(user.email, old_primary)
def test_unverified_primary_email(self): """ Only verified emails can be set as the primary email """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) primary = secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=old_primary) self.assertFalse(primary) user = User.objects.get(email=old_primary) self.assertEqual(user.email, old_primary)
def test_email_activation_creation(self): """ Creating a new secondary email creates a corresponding unactivated ActivationProfile. """ secondary_email = SecondaryEmailFactory(user=self.user) activation = ActivationProfile.objects.get(email=secondary_email.email) self.assertEqual(secondary_email.email, activation.email)
def test_send_activation(self): """ The send_activation method in SecondaryEmail should send an activation link to the email address """ secondary_email = SecondaryEmailFactory(user=self.user) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [secondary_email.email]) self.assertTrue('secondary email' in mail.outbox[0].body)
def test_maintain_verification_state(self): """ For security reasons, the state of verification of the user email should be the same as it is when it is transferred into SecondaryEmail """ old_primary = self.user.email self.user.is_active = False self.user.save() secondary_email = SecondaryEmailFactory(user=self.user) activation = ActivationProfile.objects.get(user=self.user, email=secondary_email.email) ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get(user=self.user, email=secondary_email.email) new_primary = secondary_email.email secondary_email.set_as_primary() old_email = SecondaryEmail.objects.get(email=old_primary) self.assertFalse(old_email.verified) user = User.objects.get(email=new_primary)
def test_maintain_verification_state(self): """ For security reasons, the state of verification of the user email should be the same as it is when it is transferred into SecondaryEmail """ old_primary = self.user.email self.user.is_active = False self.user.save() secondary_email = SecondaryEmailFactory(user=self.user) activation = ActivationProfile.objects.get(user=self.user, email=secondary_email.email) ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get( user=self.user, email=secondary_email.email) new_primary = secondary_email.email secondary_email.set_as_primary() old_email = SecondaryEmail.objects.get(email=old_primary) self.assertFalse(old_email.verified) user = User.objects.get(email=new_primary)
def test_verify(self): """ Clicking the activation link sets the ActivationProfile object to activated and sets the SecondaryEmail object to verified. """ secondary_email = SecondaryEmailFactory(user=self.user) activation = ActivationProfile.objects.get(user=self.user, email=secondary_email.email) response = self.client.get( reverse('registration_activate', args=[activation.activation_key]) + '?verify=%s' % self.user.user_guid) secondary_email = SecondaryEmail.objects.get( user=self.user, email=secondary_email.email) activation = ActivationProfile.objects.get(user=self.user, email=secondary_email.email) self.assertEqual(response.status_code, 200) self.assertTrue(secondary_email.verified)
def test_candidate_page_load_with_profileunits_and_activites(self): # Building User with ProfileUnits self.name = PrimaryNameFactory(user=self.candidate_user) self.second_email = SecondaryEmailFactory(user=self.candidate_user) self.education = EducationFactory(user=self.candidate_user) self.address = AddressFactory(user=self.candidate_user) self.telephone = TelephoneFactory(user=self.candidate_user) self.employment = EmploymentHistoryFactory(user=self.candidate_user) self.candidate_user.save() response = self.client.post( reverse('candidate_information', ) + '?company=' + str(self.company.id) + '&user='******'div', { 'id': 'candidate-content' }).findAll('a', {'class': 'accordion-toggle'}) info = soup.find('div', {'id': 'candidate-content'}).findAll('li') self.assertEqual(len(titles), 6) self.assertEqual(len(info), 16) self.assertEqual(response.status_code, 200)