示例#1
0
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()
示例#3
0
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()
示例#4
0
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()
示例#5
0
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()
示例#6
0
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
示例#7
0
 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()
示例#9
0
 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()
示例#10
0
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()
示例#11
0
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
示例#12
0
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
示例#13
0
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()
示例#14
0
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
示例#15
0
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'
示例#16
0
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'
示例#17
0
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
示例#18
0
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']
示例#19
0
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']
示例#20
0
 def do_grant():
     group = srusers.group('media-consent')
     group.user_add(username)
     group.save()
示例#21
0
 def del_if_in_db(groupname):
     grp = srusers.group(groupname)
     if grp.in_db:
         grp.rm()
示例#22
0
 def del_if_in_db(groupname):
     grp = srusers.group(groupname)
     if grp.in_db:
         grp.rm()
示例#23
0
def add_blueshirt_to_team_QWZ():
    g = srusers.group("team-QWZ")
    g.user_add("blueshirt")
    g.save()
示例#24
0
def remove_blueshirt_from_team_QWZ():
    g = srusers.group("team-QWZ")
    g.user_rm("blueshirt")
    g.save()
示例#25
0
 def do_grant():
     group = srusers.group('media-consent')
     group.user_add(username)
     group.save()
示例#26
0
 def do_unwithdrawal():
     group = srusers.group('withdrawn')
     group.user_rm(username)
     group.save()
示例#27
0
def remove_blueshirt_from_team_QWZ():
    g = srusers.group("team-QWZ")
    g.user_rm("blueshirt")
    g.save()
示例#28
0
def add_blueshirt_to_team_QWZ():
    g = srusers.group("team-QWZ")
    g.user_add("blueshirt")
    g.save()
示例#29
0
 def do_unwithdrawal():
     group = srusers.group('withdrawn')
     group.user_rm(username)
     group.save()