def test_make_student(): u = User.create_user('st_user1') u.make_student() u.save() assert not u.is_teacher students = srusers.group('students').members assert 'st_user1' in students teachers = srusers.group('teachers').members assert 'st_user1' not in teachers
def setUp(): # Create a temp user & colleges sru = srusers.user('st_user1') sru.email = '*****@*****.**' sru.cname = 'steve' sru.sname = 'user1' sru.save() other_group = srusers.group('st_other_group') other_group.user_add(sru) other_group.save() orig_college = srusers.group(ORIG_COLLEGE_NAME) orig_college.user_add(sru) orig_college.save() new_college = srusers.group(NEW_COLLEGE_NAME) new_college.save()
def setUp(): # Create a temp user & teams sru = srusers.user('st_user1') sru.email = '*****@*****.**' sru.cname = 'steve' sru.sname = 'user1' sru.save() other_group = srusers.group('st_other_group') other_group.user_add(sru) other_group.save() orig_team = srusers.group(ORIG_TEAM_NAME) orig_team.user_add(sru) orig_team.save() new_team = srusers.group(NEW_TEAM_NAME) new_team.save()
def test_make_student_teacher(): students = srusers.group('students') students.user_add('st_user1') students.save() u = User.create_user('st_user1') u.make_teacher() u.save() assert u.is_teacher teachers = srusers.group('teachers').members assert 'st_user1' in teachers students = srusers.group('students').members assert 'st_user1' not in students
def helper(): u = srusers.user(username) assert u.in_db if groupname in u.groups(): g = srusers.group(groupname) g.user_rm(username) g.save()
def helper(): u = srusers.user(name) if u.in_db: for gid in u.groups(): g = srusers.group(gid) g.user_rm(u.username) g.save() u.delete()
def my_tearDown(): # Remove the temp user & its memberships sru = srusers.user('st_user1') groups = sru.groups() if sru.delete(): for g in groups: srg = srusers.group(g) srg.user_rm('st_user1') srg.save()
def create_media_consent(username): sru = srusers.user(username) sru.cname = 'to' sru.sname = 'consent' sru.email = '' sru.save() g = srusers.group('media-consent') g.user_add(sru) g.save() return sru
def create_withdrawn(username): sru = srusers.user(username) sru.cname = 'to' sru.sname = 'withdraw' sru.email = '' sru.save() g = srusers.group('withdrawn') g.user_add(sru) g.save() return sru
def create_user(username, first, last): # Add the new user u = srusers.user(username) u.cname = first u.sname = last u.email = '' u.save() g = srusers.group('college-1') g.user_add(u) g.save()
def test_delete_user(): username = '******' sru = srusers.user(username) sru.cname = 'to-be' sru.sname = 'deleted' sru.email = '' sru.save() for gid in ['students', 'team-ABC', 'college-1']: g = srusers.group(gid) g.user_add(sru) g.save() u = User.create_user(username) u.delete() sru = srusers.user(username) assert not sru.in_db for gid in ['students', 'team-ABC', 'college-1']: g = srusers.group(gid) assert not username in g.members
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_media_consent_true_1(): username = '******' sru = srusers.user(username) sru.cname = 'admin' sru.sname = 'consent' sru.email = '' sru.save() # Sanity check u = User.create_user(username) assert not u.can_record_media_consent g = srusers.group('media-consent-admin') g.user_add(sru) g.save() u = User.create_user(username) assert u.can_record_media_consent
def test_user_withdrawn_true(): username = '******' sru = srusers.user(username) sru.cname = 'to' sru.sname = 'consent' sru.email = '' sru.save() for gid in ['students', 'withdrawn', 'college-2']: g = srusers.group(gid) g.user_add(sru) g.save() params = {"username":"******", "password":"******", } r,data = test_helpers.server_get("/user/to-withdraw", params) data = json.loads(data) assert r.status == 200 assert data['has_withdrawn']
def test_user_withdrawn_true(): username = '******' sru = srusers.user(username) sru.cname = 'to' sru.sname = 'consent' sru.email = '' sru.save() for gid in ['students', 'withdrawn', 'college-2']: g = srusers.group(gid) g.user_add(sru) g.save() params = { "username": "******", "password": "******", } r, data = test_helpers.server_get("/user/to-withdraw", params) data = json.loads(data) assert r.status == 200 assert data['has_withdrawn']
def do_grant(): group = srusers.group('media-consent') group.user_add(username) group.save()
def del_if_in_db(groupname): grp = srusers.group(groupname) if grp.in_db: grp.rm()
def add_blueshirt_to_team_QWZ(): g = srusers.group("team-QWZ") g.user_add("blueshirt") g.save()
def remove_blueshirt_from_team_QWZ(): g = srusers.group("team-QWZ") g.user_rm("blueshirt") g.save()
def do_unwithdrawal(): group = srusers.group('withdrawn') group.user_rm(username) group.save()