def test_email_change_request(): """ Test that change requests via POST at /user/ are handled correclty. """ username = "******" old_email = User(username).email new_email = "*****@*****.**" params = {"username":"******", "password":"******", "new_email":new_email, } r,data = test_helpers.server_post("/user/student_coll1_1", params) assert r.status == 200, data user = User(username) assert user.email == old_email ps = test_helpers.last_email() toaddr = ps.toaddr assert toaddr == new_email vars = ps.template_vars first_name = user.first_name assert first_name == vars['name'] template = ps.template_name assert template == 'change_email' pe = PendingEmail(username) assert pe.in_db assert pe.new_email == new_email
def test_post_any_blueshirt_can_record_student_media_consent(): blueshirt_mcf = srusers.user('blueshirt-mcf') groups = blueshirt_mcf.groups() # Sanity check assert set(groups) == set(['mentors', 'media-consent-admin']) params = { "username": "******", "password": "******", "media_consent": 'true', } r, data = test_helpers.server_post("/user/student_coll1_1", params) assert r.status == 200, (r.status, data) u = User("student_coll1_1") assert u.has_media_consent ps = test_helpers.last_email() toaddr = ps.toaddr expected_addr = u.email assert toaddr == expected_addr vars = ps.template_vars first_name = u.first_name assert first_name == vars['first_name'] template = ps.template_name assert template == 'ticket_available' test_helpers.assert_load_template(template, vars)
def test_post_any_blueshirt_can_record_student_media_consent(): blueshirt_mcf = srusers.user('blueshirt-mcf') groups = blueshirt_mcf.groups() # Sanity check assert set(groups) == set(['mentors', 'media-consent-admin']) params = {"username":"******", "password":"******", "media_consent":'true', } r, data = test_helpers.server_post("/user/student_coll1_1", params) assert r.status == 200, (r.status, data) u = User("student_coll1_1") assert u.has_media_consent ps = test_helpers.last_email() toaddr = ps.toaddr expected_addr = u.email assert toaddr == expected_addr vars = ps.template_vars first_name = u.first_name assert first_name == vars['first_name'] template = ps.template_name assert template == 'ticket_available' test_helpers.assert_load_template(template, vars)
def test_email_change_request(): """ Test that change requests via POST at /user/ are handled correclty. """ username = "******" old_email = User(username).email new_email = "*****@*****.**" params = { "username": "******", "password": "******", "new_email": new_email, } r, data = test_helpers.server_post("/user/student_coll1_1", params) assert r.status == 200, data user = User(username) assert user.email == old_email ps = test_helpers.last_email() toaddr = ps.toaddr assert toaddr == new_email vars = ps.template_vars first_name = user.first_name assert first_name == vars['name'] template = ps.template_name assert template == 'change_email' test_helpers.assert_load_template(template, vars) pe = PendingEmail(username) assert pe.in_db assert pe.new_email == new_email
def test_post_by_blueshirt(self): params = {"username": "******", "password": "******"} r, data = test_helpers.server_post( "/send-password-reset/student_coll1_1", params) self.assertEqual(202, r.status, data) user = User('student_coll1_1') ps = test_helpers.last_email() toaddr = ps.toaddr self.assertEqual(user.email, toaddr) vars = ps.template_vars self.assertEqual(user.first_name, vars['name'], "Wrong first name") self.assertEqual('Blue Shirt', vars['requestor_name'], "Wrong requestor name") template = ps.template_name self.assertEqual('password_reset', template, "Wrong email template") test_helpers.assert_load_template(template, vars) ppr = PendingPasswordReset('student_coll1_1') self.assertTrue(ppr.in_db, "{0} should been in the database.".format(ppr)) self.assertEqual('blueshirt', ppr.requestor_username, "Wrong requestor username.") self.assertIn(ppr.verify_code, vars['password_reset_url'], "Wrong verify code")
def test_post_by_blueshirt(self): params = {"username":"******", "password":"******"} r, data = test_helpers.server_post("/send-password-reset/student_coll1_1", params) self.assertEqual(202, r.status, data) user = User('student_coll1_1') ps = test_helpers.last_email() toaddr = ps.toaddr self.assertEqual(user.email, toaddr) vars = ps.template_vars self.assertEqual(user.first_name, vars['name'], "Wrong first name") self.assertEqual('Blue Shirt', vars['requestor_name'], "Wrong requestor name") template = ps.template_name self.assertEqual('password_reset', template, "Wrong email template") test_helpers.assert_load_template(template, vars) ppr = PendingPasswordReset('student_coll1_1') self.assertTrue(ppr.in_db, "{0} should been in the database.".format(ppr)) self.assertEqual('blueshirt', ppr.requestor_username, "Wrong requestor username.") self.assertIn(ppr.verify_code, vars['password_reset_url'], "Wrong verify code")
def test_store_temaplate(self): exp_addr = '*****@*****.**' exp_tpl = 'tpl' exp_vars = {'foo':'bar'} ps = mailer.store_template(exp_addr, exp_tpl, exp_vars) assert ps.in_db stored = last_email() toaddr = stored.toaddr assert exp_addr == toaddr tpl = stored.template_name assert exp_tpl == tpl vars = stored.template_vars assert exp_vars == vars
def test_store_temaplate(self): exp_addr = '*****@*****.**' exp_tpl = 'tpl' exp_vars = {'foo': 'bar'} ps = mailer.store_template(exp_addr, exp_tpl, exp_vars) assert ps.in_db stored = last_email() toaddr = stored.toaddr assert exp_addr == toaddr tpl = stored.template_name assert exp_tpl == tpl vars = stored.template_vars assert exp_vars == vars
def test_activate_success(): username = '******' rq_user = User.create_user("teacher_coll1", "facebees") cu = User.create_new_user(rq_user, 'college-1', 'James', 'Activate') assert cu.username == username pu = create_pending_user(username) pu.save() r, data = test_helpers.server_get("/activate/" + username + "/bibble") status = r.status assert status == 200, data u = User(username) email = u.email assert pu.email == email teams = [t.name for t in u.teams] assert pu.team in teams colleges = u.colleges assert pu.college in colleges students = srusers.group('students').members assert username in students pu = PendingUser(username) assert not pu.in_db, "registration DB entry should have been removed" # ensure we sent the team-leader a confirmation ps = test_helpers.last_email() toaddr = ps.toaddr tl_email = rq_user.email assert toaddr == tl_email vars = ps.template_vars tl_name = rq_user.first_name assert tl_name == vars['name'] first_name = cu.first_name assert first_name == vars['au_first_name'] last_name = cu.last_name assert last_name == vars['au_last_name'] assert username == vars['au_username'] template = ps.template_name assert template == 'user_activated_team_leader'
def test_activate_success(): username = '******' rq_user = User.create_user("teacher_coll1", "facebees") cu = User.create_new_user(rq_user, 'college-1', 'James', 'Activate') assert cu.username == username pu = create_pending_user(username) pu.save() r,data = test_helpers.server_get("/activate/" + username + "/bibble") status = r.status assert status == 200, data u = User(username) email = u.email assert pu.email == email teams = [t.name for t in u.teams] assert pu.team in teams colleges = u.colleges assert pu.college in colleges students = srusers.group('students').members assert username in students pu = PendingUser(username) assert not pu.in_db, "registration DB entry should have been removed" # ensure we sent the team-leader a confirmation ps = test_helpers.last_email() toaddr = ps.toaddr tl_email = rq_user.email assert toaddr == tl_email vars = ps.template_vars tl_name = rq_user.first_name assert tl_name == vars['name'] first_name = cu.first_name assert first_name == vars['au_first_name'] last_name = cu.last_name assert last_name == vars['au_last_name'] assert username == vars['au_username'] template = ps.template_name assert template == 'user_activated_team_leader'
def test_send_email(): first_name = 'jim' verification_url = 'http://verify' new_email = '*****@*****.**' pe = PendingEmail('abc') pe.new_email = new_email pe.send_verification_email(first_name, verification_url) ps = test_helpers.last_email() vars = ps.template_vars assert first_name == vars['name'] assert verification_url == vars['url'] toaddr = ps.toaddr assert new_email == toaddr template = ps.template_name assert template == 'change_email'
def test_send_email(): first_name = 'jim' verification_url = 'https://verify' email = '*****@*****.**' requestor_name = 'Dave Smith' ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.send_reset_email(email, first_name, verification_url, requestor_name) ps = test_helpers.last_email() vars = ps.template_vars assert first_name == vars['name'] assert verification_url == vars['password_reset_url'] assert requestor_name == vars['requestor_name'] toaddr = ps.toaddr assert email == toaddr template = ps.template_name assert template == 'password_reset' test_helpers.assert_load_template(template, vars)
def test_send_email(): first_name = 'jim' verification_url = 'http://verify' email = '*****@*****.**' requestor_name = 'Dave Smith' ppr = PendingPasswordReset('abc') ppr.requestor_username = '******' ppr.send_reset_email(email, first_name, verification_url, requestor_name) ps = test_helpers.last_email() vars = ps.template_vars assert first_name == vars['name'] assert verification_url == vars['password_reset_url'] assert requestor_name == vars['requestor_name'] toaddr = ps.toaddr assert email == toaddr template = ps.template_name assert template == 'password_reset' test_helpers.assert_load_template(template, vars)