def test_success_change_secondary_subscribed_email(self): # setup institution_email = "*****@*****.**" old_alt_email = "*****@*****.**" new_alt_email = "*****@*****.**" self.user.profile.subscribed_newsletter = True self.user.profile.newsletter_recipient = "ALT" self.newsletter_service.add_subscription([{ "email": old_alt_email, "first_name": "Tosti", "last_name": "Broodjes" }], NEWSLETTER_LIST_ID) self.user.profile.save() # act form = ProfileUpdateForm( instance=self.user, data=get_profile_form_data(email="*****@*****.**")) form.full_clean() form.save() # runs update_newsletter_preferences # test self.assert_newsletter_subscription(institution_email, False) self.assert_newsletter_subscription(old_alt_email, False) self.assert_newsletter_subscription(new_alt_email, True)
def test_success_do_nothing(self): # setup c = get_logged_in_client() url = "/accounts/profile/" exp_status_code = 200 # act response = c.get(url, data=get_profile_form_data()) # test self.assertEqual(exp_status_code, response.status_code)
def test_success_remove_alternative_email(self): # setup c = get_logged_in_client() url = "/accounts/profile/" exp_alt_email = "" # act response = c.post(url, data=get_profile_form_data(email="")) # test form_data = response.wsgi_request.POST self.assertEqual(302, response.status_code) self.assertEqual(exp_alt_email, form_data["email"])
def test_success_change_nationality(self): # setup data = get_profile_form_data(nationality="Belgian") # act form = ProfileUpdateForm(instance=self.user, data=data) form.full_clean() form.save() # test self.assertTrue(form.is_valid()) self.assertEqual(form["nationality"].initial, "Dutch") user = User.objects.get(pk=self.user.pk) self.assertEqual(user.profile.nationality, "Belgian")
def test_success_change_program(self): # setup data = get_profile_form_data(program="Master") # act form = ProfileUpdateForm(instance=self.user, data=data) form.full_clean() form.save() # test self.assertTrue(form.is_valid()) self.assertEqual(form["program"].initial, "Bachelor") user = User.objects.get(pk=self.user.pk) self.assertEqual(user.profile.institution.program, "Master")
def test_success_remove_alternative_email(self): # setup data = get_profile_form_data(email="") # act form = ProfileUpdateForm(instance=self.user, data=data) form.full_clean() form.save() # test self.assertTrue(form.is_valid()) self.assertEqual(form["email"].initial, "*****@*****.**") user = User.objects.get(pk=self.user.pk) self.assertEqual(user.email, "")
def test_success_change_department(self): # setup c = get_logged_in_client() url = "/accounts/profile/" exp_department = "Electrical Engineering" # act response = c.post( url, data=get_profile_form_data(department="Electrical Engineering")) # test form_data = response.wsgi_request.POST self.assertEqual(302, response.status_code) self.assertEqual(exp_department, form_data["department"])
def test_success_change_department(self): # setup data = get_profile_form_data( department="Mathematics and Computer Science") # act form = ProfileUpdateForm(instance=self.user, data=data) form.full_clean() form.save() # test self.assertTrue(form.is_valid()) self.assertEqual(form["department"].initial, "Electrical Engineering") user = User.objects.get(pk=self.user.pk) self.assertEqual(user.profile.institution.department, "Mathematics and Computer Science")
def test_success_change_secondary_unsubscribed_email(self): # setup institution_email = "*****@*****.**" old_alt_email = "*****@*****.**" new_alt_email = "*****@*****.**" # act form = ProfileUpdateForm( instance=self.user, data=get_profile_form_data(email="*****@*****.**")) form.full_clean() form.save() # runs update_newsletter_preferences # test self.assert_newsletter_subscription(institution_email, False) self.assert_newsletter_subscription(old_alt_email, False) self.assert_newsletter_subscription(new_alt_email, False)