示例#1
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()
示例#2
0
def my_setUp():
    # Create a temp user
    sru = srusers.user('st_user1')
    sru.email = '*****@*****.**'
    sru.cname = 'steve'
    sru.sname = 'user1'
    sru.save()
示例#3
0
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 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()
示例#5
0
def test_college_set_in_db():
    u = User.create_user('st_user1')

    u.set_college(NEW_COLLEGE_NAME)
    u.save()

    sru = srusers.user('st_user1')
    sru_groups = sru.groups()
    assert set(sru_groups) == set([NEW_COLLEGE_NAME, 'st_other_group'])
示例#6
0
def test_team_set_in_db():
    u = User.create_user('st_user1')

    u.set_team(NEW_TEAM_NAME)
    u.save()

    sru = srusers.user('st_user1')
    sru_groups = sru.groups()
    assert set(sru_groups) == set([NEW_TEAM_NAME, 'st_other_group'])
示例#7
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()
示例#8
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
示例#9
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
示例#10
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
示例#11
0
def test_withdrawal():
    username = '******'
    sru = srusers.user(username)
    sru.cname = 'to'
    sru.sname = 'withdraw'
    sru.email = ''
    sru.save()

    u = User.create_user(username)
    assert not u.has_withdrawn
    u.withdraw()
    u.save()
    assert u.has_withdrawn
示例#12
0
def tearDown():
    # Remove the temp user & teams
    def del_if_in_db(groupname):
        grp = srusers.group(groupname)
        if grp.in_db:
            grp.rm()

    del_if_in_db('st_other_group')
    del_if_in_db(ORIG_TEAM_NAME)
    del_if_in_db(NEW_TEAM_NAME)
    sru = srusers.user('st_user1')
    if sru.in_db:
        sru.delete()
示例#13
0
    def test_clear_old_registrations(self):
        first_name = 'old'
        last_name = 'user'
        old_user = srusers.user('old')
        old_user.cname = first_name
        old_user.sname = last_name
        old_user.email = ''
        old_user.save()

        old_team_leader = User('teacher_coll1')

        pu = PendingUser('old')
        pu.teacher_username = old_team_leader.username
        pu.college = 'college-1'
        pu.team = 'team-ABC'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble-old'
        pu.save()

        self._make_old('registrations', 'old')

        pu = PendingUser('abc')
        pu.teacher_username = '******'
        pu.college = 'new-college-1'
        pu.team = 'team-NEW'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble'
        pu.save()

        helpers.clear_old_registrations()

        pu = PendingUser('old')
        assert not pu.in_db

        pu = PendingUser('abc')
        assert pu.in_db

        ps = last_email()
        toaddr = ps.toaddr
        team_lead_email = old_team_leader.email
        assert toaddr == team_lead_email

        vars = ps.template_vars
        team_lead_first = old_team_leader.first_name
        assert team_lead_first == vars['name']
        assert first_name == vars['pu_first_name']
        assert last_name == vars['pu_last_name']

        template = ps.template_name
        assert template == 'registration_expired'
示例#14
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()
示例#15
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()
示例#16
0
def test_media_consent_admin_can_view_all_competitors():
    blueshirt_mcf = srusers.user('blueshirt-mcf')
    groups = blueshirt_mcf.groups()
    # Sanity check
    assert set(groups) == set(['mentors', 'media-consent-admin'])

    def helper(other_username):
        u = User.create_user("blueshirt-mcf", "blueshirt")
        other = User.create_user(other_username)
        assert u.can_view(other)

    yield helper, "student_coll1_1"
    yield helper, "student_coll2_2"
    yield helper, "teacher_coll1"
    yield helper, "teacher_coll2"
示例#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_media_consent_grant():
    username = '******'
    sru = srusers.user(username)
    sru.cname = 'to'
    sru.sname = 'consent'
    sru.email = ''
    sru.save()

    u = User.create_user(username)
    # Sanity check
    assert not u.has_media_consent, "Fresh user should not have granted media consent"

    u.got_media_consent()
    u.save()
    assert u.has_media_consent, "Should have recorded the media-consent grant"

    # Fresh instance
    u = User.create_user(username)
    assert u.has_media_consent, "Media consent grant should persist"
示例#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 test_clear_old_registrations(self):
        first_name = 'old'
        last_name = 'user'
        old_user = srusers.user('old')
        old_user.cname = first_name
        old_user.sname = last_name
        old_user.email = ''  # match what libnemesis does when registering users
        old_user.save()

        old_team_leader = User('teacher_coll1')

        pu = PendingUser('old')
        email = '*****@*****.**'
        pu.teacher_username = old_team_leader.username
        pu.college = 'college-1'
        pu.team = 'team-ABC'
        pu.email = email
        pu.verify_code = 'bibble-old'
        pu.save()

        self._make_old('registrations', 'old')

        pu = PendingUser('abc')
        pu.teacher_username = '******'
        pu.college = 'new-college-1'
        pu.team = 'team-NEW'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble'
        pu.save()

        helpers.clear_old_registrations()

        pu = PendingUser('old')
        assert not pu.in_db

        pu = PendingUser('abc')
        assert pu.in_db

        emails = last_n_emails(2)

        # Check we emailed the competitor
        ps = emails[0]
        toaddr = ps.toaddr
        assert email == toaddr

        vars = ps.template_vars
        assert first_name == vars['name']

        template = ps.template_name
        assert template == 'registration_expired'

        assert_load_template(template, vars)

        # Check we emailed the team leader
        ps = emails[1]
        toaddr = ps.toaddr
        team_lead_email = old_team_leader.email
        assert toaddr == team_lead_email

        vars = ps.template_vars
        team_lead_first = old_team_leader.first_name
        assert team_lead_first == vars['name']
        assert first_name == vars['pu_first_name']
        assert last_name == vars['pu_last_name']

        template = ps.template_name
        assert template == 'registration_expired_team_leader'

        assert_load_template(template, vars)
示例#21
0
 def tearDown(self):
     delete_db()
     u = srusers.user('old')
     if u.in_db:
         u.delete()