def test_voting_basics(): l.add_proposal(data) standards = [l.add_standard("About Pythong"), l.add_standard("Awesome")] uid = l.add_user('*****@*****.**', 'Bob', 'bob') assert not l.get_votes(123) assert not l.vote(uid, 123, {k: 3 for k in standards}) assert not l.get_votes(123) assert l.get_proposal(123).vote_count == 0 l.approve_user(uid) assert not l.vote(uid, 123, {}) assert not l.get_votes(123) assert l.vote(uid, 123, {k: 2 for k in standards}) assert l.get_votes(123)[0].scores == {k: 2 for k in standards} assert l.get_proposal(123).vote_count == 1 assert not l.vote(uid, 123, {k: 7 for k in standards}) assert l.get_votes(123)[0].scores == {k: 2 for k in standards} assert l.vote(uid, 123, {k: 0 for k in standards}) assert len(l.get_votes(123)) == 1 assert l.get_votes(123)[0].scores == {k: 0 for k in standards} assert l.get_proposal(123).vote_count == 1
def test_voting_basics(): l.add_proposal(data) standards = [l.add_standard("About Pythong"), l.add_standard("Awesome")] uid = l.add_user('*****@*****.**', 'Bob', 'bob') assert not l.get_votes(123) assert not l.vote(uid, 123, {k:3 for k in standards}) assert not l.get_votes(123) assert l.get_proposal(123).vote_count == 0 l.approve_user(uid) assert not l.vote(uid, 123, {}) assert not l.get_votes(123) assert l.vote(uid, 123, {k:2 for k in standards}) assert l.get_votes(123)[0].scores == {k:2 for k in standards} assert l.get_proposal(123).vote_count == 1 assert not l.vote(uid, 123, {k:7 for k in standards}) assert l.get_votes(123)[0].scores == {k:2 for k in standards} assert l.vote(uid, 123, {k:0 for k in standards}) assert len(l.get_votes(123)) == 1 assert l.get_votes(123)[0].scores == {k:0 for k in standards} assert l.get_proposal(123).vote_count == 1
def test_user_basics(): for n in range(20): assert l.add_user(u"{}@example.com".format(n), u"Name {}".format(n), u"pw{}".format(n)) email = u"*****@*****.**" name = u"Ned Jackson Lovely" pw = u"password" assert not l.check_pw(email, pw) uid = l.add_user(email, name, pw) assert len(l.list_users()) == 21 for user in l.list_users(): assert not user.approved_on l.approve_user(uid) for user in l.list_users(): assert not user.approved_on if user.id != uid else user.approved_on assert l.get_user(uid).display_name == name assert l.check_pw(email, pw) assert l.check_pw(email.upper(), pw) assert not l.check_pw(email, pw.upper()) pw2 = u"\u2603" l.change_pw(uid, pw2) assert not l.check_pw(email, pw) assert l.check_pw(email, pw2)
def test_discussion(): l.add_proposal(data) proposal = data['id'] users = [] for n in range(10): uid = l.add_user('{}@example.com'.format(n), 'name {}'.format(n), 'blah') l.approve_user(uid) users.append(uid) l.add_to_discussion(users[0], proposal, 'Lorem ipsum') for u in users: assert len(l.get_unread(u)) == 0 assert len(l.get_discussion(proposal)) == 1 assert l.get_discussion(proposal)[0].body == 'Lorem ipsum' l.add_to_discussion(users[-1], proposal, 'dolor sit') assert [x.id for x in l.get_unread(users[0])] == [proposal] l.add_to_discussion(users[-1], proposal, 'amet, consectetur') assert [x.id for x in l.get_unread(users[0])] == [proposal] l.mark_read(users[0], proposal) for u in users: assert len(l.get_unread(u)) == 0 l.add_to_discussion(users[0], proposal, 'LOREM IPSUM') assert l.get_discussion(proposal)[-1].body == 'LOREM IPSUM' assert l.get_discussion(proposal)[0].body == 'Lorem ipsum'
def test_discussion(): l.add_proposal(data) proposal = data["id"] users = [] for n in range(10): uid = l.add_user("{}@example.com".format(n), "name {}".format(n), "blah") l.approve_user(uid) users.append(uid) l.add_to_discussion(users[0], proposal, "Lorem ipsum") for u in users: assert len(l.get_unread(u)) == 0 assert len(l.get_discussion(proposal)) == 1 assert l.get_discussion(proposal)[0].body == "Lorem ipsum" l.add_to_discussion(users[-1], proposal, "dolor sit") assert [x.id for x in l.get_unread(users[0])] == [proposal] l.add_to_discussion(users[-1], proposal, "amet, consectetur") assert [x.id for x in l.get_unread(users[0])] == [proposal] l.mark_read(users[0], proposal) for u in users: assert len(l.get_unread(u)) == 0 l.add_to_discussion(users[0], proposal, "LOREM IPSUM") assert l.get_discussion(proposal)[-1].body == "LOREM IPSUM" assert l.get_discussion(proposal)[0].body == "Lorem ipsum"
def test_user_basics(): for n in range(20): assert l.add_user(u'{}@example.com'.format(n), u'Name {}'.format(n), u'pw{}'.format(n)) email = u'*****@*****.**' name = u'Ned Jackson Lovely' pw = u'password' assert not l.check_pw(email, pw) uid = l.add_user(email, name, pw) assert len(l.list_users()) == 21 for user in l.list_users(): assert not user.approved_on l.approve_user(uid) for user in l.list_users(): assert not user.approved_on if user.id != uid else user.approved_on assert l.get_user(uid).display_name == name assert l.check_pw(email, pw) assert l.check_pw(email.upper(), pw) assert not l.check_pw(email, pw.upper()) pw2 = u'\u2603' l.change_pw(uid, pw2) assert not l.check_pw(email, pw) assert l.check_pw(email, pw2)
def approve_user(uid): l.approve_user(uid) user = l.get_user(uid) flash('Approved user {}'.format(user.email)) l.email_approved(uid) requests.post('https://slack.com/api/users.admin.invite', data=dict(token=os.environ['SLACK_TOKEN'], email=user.email)) return redirect(url_for('admin.list_users'))
def approve_user(uid): l.approve_user(uid) user = l.get_user(uid) flash('Approved user {}'.format(user.email)) l.email_approved(uid) requests.post('https://slack.com/api/users.admin.invite', data = dict(token=os.environ['SLACK_TOKEN'], email=user.email)) return redirect(url_for('admin.list_users'))
def main(): lt.transact() emails = ['user{}@example.com'.format(n) for n in range(50)] for e in emails[:25]: uid = l.add_user(e, '{} Person'.format(e.split('@')[0]), 'abc123') l.approve_user(uid) for n in range(6): l.add_standard(words(3, 10)[:50]) user_ids = [x.id for x in l.list_users()] standards = [x.id for x in l.get_standards()] proposal_ids = [] for n in range(200): prop_id = n*2 data = {'id': prop_id, 'authors': [{'email': random.choice(emails), 'name': 'Speaker Name Here'}], 'title': words(3,8).title(), 'category': words(1,2), 'duration': '30 minutes', 'description': ipsum(4), 'audience': ipsum(1), 'audience_level': 'Novice', 'notes': ipsum(2), 'objective': ipsum(1), 'recording_release': bool(random.random() > 0.05), 'abstract': ipsum(1), 'outline': ipsum(5)+"\n[test](http://www.google.com/)\n", 'additional_notes': ipsum(1), 'additional_requirements': ipsum(1)} l.add_proposal(data) proposal_ids.append(prop_id) if random.randint(0, 3) == 0: for n in range(random.randint(1, 10)): l.add_to_discussion(random.choice(user_ids), prop_id, ipsum(1)) if random.randint(0, 2) == 0: for n in range(random.randint(1, 5)): vote = {k:random.randint(0, 2) for k in standards} l.vote(random.choice(user_ids), prop_id, vote) if random.randint(0, 3) == 0: data['description'] = 'UPDATED ' + ipsum(4) l.add_proposal(data) random.shuffle(proposal_ids) proposal_ids = proposal_ids[:70] for n in range(0, len(proposal_ids), 5): l.create_group(words(2,4).title(), proposal_ids[n:n+5])
def main(): lt.transact() emails = ["user{}@example.com".format(n) for n in range(50)] for e in emails[:25]: uid = l.add_user(e, "{} Person".format(e.split("@")[0]), "abc123") l.approve_user(uid) for n in range(6): l.add_standard(words(3, 10)[:50]) user_ids = [x.id for x in l.list_users()] standards = [x.id for x in l.get_standards()] proposal_ids = [] for n in range(200): prop_id = n * 2 data = { "id": prop_id, "authors": [{"email": random.choice(emails), "name": "Speaker Name Here"}], "title": words(3, 8).title(), "category": words(1, 2), "duration": "30 minutes", "description": ipsum(4), "audience": ipsum(1), "audience_level": "Novice", "notes": ipsum(2), "objective": ipsum(1), "recording_release": bool(random.random() > 0.05), "abstract": ipsum(1), "outline": ipsum(5) + "\n[test](http://www.google.com/)\n", "additional_notes": ipsum(1), "additional_requirements": ipsum(1), } l.add_proposal(data) proposal_ids.append(prop_id) if random.randint(0, 3) == 0: for n in range(random.randint(1, 10)): l.add_to_discussion(random.choice(user_ids), prop_id, ipsum(1)) if random.randint(0, 2) == 0: for n in range(random.randint(1, 5)): vote = {k: random.randint(0, 2) for k in standards} l.vote(random.choice(user_ids), prop_id, vote) if random.randint(0, 3) == 0: data["notes"] = "UPDATED" + ipsum(2) l.add_proposal(data) random.shuffle(proposal_ids) proposal_ids = proposal_ids[:70] for n in range(0, len(proposal_ids), 5): l.create_group(words(2, 4).title(), proposal_ids[n : n + 5])
def test_needs_votes(): proposals = [] users = {} standards = [l.add_standard("About Pythong"), l.add_standard("Awesome")] sample_vote = {k: 2 for k in standards} for n in range(1, 10): prop = data.copy() prop['id'] = n * 2 prop['abstract'] = 'Proposal {}'.format(n) email = '{}@example.com'.format(n) uid = l.add_user(email, email, email) l.approve_user(uid) users[email] = uid prop['authors'] = [{'email': email, 'name': 'foo'}] l.add_proposal(prop) proposals.append(n * 2) non_author_email = '*****@*****.**' non_author_id = l.add_user(non_author_email, non_author_email, non_author_email) l.approve_user(non_author_id) random.seed(0) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set(proposals) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes('*****@*****.**', users['*****@*****.**'])) not_2_proposals = set(proposals) not_2_proposals.remove(4) assert seen_ids == not_2_proposals for n in range(1, 9): l.vote(users['*****@*****.**'], n * 2, sample_vote) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set([18]) l.vote(users['*****@*****.**'], 18, sample_vote) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set(proposals)
def test_needs_votes(): proposals = [] users = {} standards = [l.add_standard("About Pythong"), l.add_standard("Awesome")] sample_vote = {k: 2 for k in standards} for n in range(1, 10): prop = data.copy() prop["id"] = n * 2 prop["abstract"] = "Proposal {}".format(n) email = "{}@example.com".format(n) uid = l.add_user(email, email, email) l.approve_user(uid) users[email] = uid prop["authors"] = [{"email": email, "name": "foo"}] l.add_proposal(prop) proposals.append(n * 2) non_author_email = "*****@*****.**" non_author_id = l.add_user(non_author_email, non_author_email, non_author_email) l.approve_user(non_author_id) random.seed(0) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set(proposals) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes("*****@*****.**", users["*****@*****.**"])) not_2_proposals = set(proposals) not_2_proposals.remove(4) assert seen_ids == not_2_proposals for n in range(1, 9): l.vote(users["*****@*****.**"], n * 2, sample_vote) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set([18]) l.vote(users["*****@*****.**"], 18, sample_vote) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set(proposals)
def test_needs_votes(): proposals = [] users = {} standards = [l.add_standard("About Pythong"), l.add_standard("Awesome")] sample_vote = {k:2 for k in standards} for n in range(1,10): prop = data.copy() prop['id'] = n*2 prop['abstract'] = 'Proposal {}'.format(n) email = '{}@example.com'.format(n) uid = l.add_user(email, email, email) l.approve_user(uid) users[email] = uid prop['authors'] = [{'email':email, 'name':'foo'}] l.add_proposal(prop) proposals.append(n*2) non_author_email = '*****@*****.**' non_author_id = l.add_user(non_author_email, non_author_email, non_author_email) l.approve_user(non_author_id) random.seed(0) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set(proposals) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes('*****@*****.**', users['*****@*****.**'])) not_2_proposals = set(proposals) not_2_proposals.remove(4) assert seen_ids == not_2_proposals for n in range(1, 9): l.vote(users['*****@*****.**'], n*2, sample_vote) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set([18]) l.vote(users['*****@*****.**'], 18, sample_vote) seen_ids = set() for n in range(100): seen_ids.add(l.needs_votes(non_author_email, non_author_id)) assert seen_ids == set(proposals)
def test_batch(): user = l.add_user('*****@*****.**', 'Voter', '123') l.approve_user(user) submitter = l.add_user('*****@*****.**', 'Submitted', '123') l.approve_user(submitter) proposals = [] for n in range(1,50): prop = data.copy() prop['id'] = n if n == 6: prop['authors'] = [{'name':'Blah', 'email':'*****@*****.**'}] proposals.append(l.add_proposal(prop)) group_one = l.create_group('Group One', proposals[4:10]) group_two = l.create_group('Group Two', proposals[16:27]) assert l.get_group(group_one).name == 'Group One' group_one_proposals = l.get_group_proposals(group_one) assert set(x.id for x in group_one_proposals) == set(proposals[4:10]) all_groups = l.list_groups(user) assert set([group_one, group_two]) == set(x.id for x in all_groups) assert not any(x.voted for x in all_groups) votes1 = list(reversed(proposals[5:6])) votes2 = proposals[4:5] l.vote_group(group_one, user, votes1) all_groups = {x.id:x.voted for x in l.list_groups(user)} assert all_groups[group_one] assert not all_groups[group_two] assert l.get_batch_vote(group_one, user).accept == votes1 l.vote_group(group_one, user, votes2) assert l.get_batch_vote(group_one, user).accept == votes2 assert len(l.list_groups(submitter)) == 1
def test_batch(): user = l.add_user('*****@*****.**', 'Voter', '123') l.approve_user(user) submitter = l.add_user('*****@*****.**', 'Submitted', '123') l.approve_user(submitter) proposals = [] for n in range(1, 50): prop = data.copy() prop['id'] = n if n == 6: prop['authors'] = [{'name': 'Blah', 'email': '*****@*****.**'}] proposals.append(l.add_proposal(prop)) group_one = l.create_group('Group One', proposals[4:10]) group_two = l.create_group('Group Two', proposals[16:27]) assert l.get_group(group_one).name == 'Group One' group_one_proposals = l.get_group_proposals(group_one) assert set(x.id for x in group_one_proposals) == set(proposals[4:10]) all_groups = l.list_groups(user) assert set([group_one, group_two]) == set(x.id for x in all_groups) assert not any(x.voted for x in all_groups) votes1 = list(reversed(proposals[5:6])) votes2 = proposals[4:5] l.vote_group(group_one, user, votes1) all_groups = {x.id: x.voted for x in l.list_groups(user)} assert all_groups[group_one] assert not all_groups[group_two] assert l.get_batch_vote(group_one, user).accept == votes1 l.vote_group(group_one, user, votes2) assert l.get_batch_vote(group_one, user).accept == votes2 assert len(l.list_groups(submitter)) == 1
def test_batch(): user = l.add_user("*****@*****.**", "Voter", "123") l.approve_user(user) proposals = [] for n in range(1, 50): prop = data.copy() prop["id"] = n proposals.append(l.add_proposal(prop)) group_one = l.create_group("Group One", proposals[4:10]) group_two = l.create_group("Group Two", proposals[16:27]) assert l.get_group(group_one).name == "Group One" group_one_proposals = l.get_group_proposals(group_one) assert set(x.id for x in group_one_proposals) == set(proposals[4:10]) all_groups = l.list_groups(user) assert set([group_one, group_two]) == set(x.id for x in all_groups) assert not any(x.voted for x in all_groups) votes1 = list(reversed(proposals[5:6])) votes2 = proposals[4:5] l.vote_group(group_one, user, votes1) all_groups = {x.id: x.voted for x in l.list_groups(user)} assert all_groups[group_one] assert not all_groups[group_two] assert l.get_batch_vote(group_one, user).accept == votes1 l.vote_group(group_one, user, votes2) assert l.get_batch_vote(group_one, user).accept == votes2
def main(): lt.transact() emails = ['user{}@example.com'.format(n) for n in range(50)] for e in emails[:25]: uid = l.add_user(e, '{} Person'.format(e.split('@')[0]), 'abc123') l.approve_user(uid) """ for n in range(6): l.add_standard(words(3, 10)[:50]) """ standards = ["follows PyCon's Code of Conduct", "is complete, clearly written, and articulate", "has a thorough and achievable outline", "has a coherent and primarily technical subject", "is about the Python ecosystem", "has a sufficient audience among attendees"] for s in standards: l.add_standard(s) user_ids = [x.id for x in l.list_users()] standards = [x.id for x in l.get_standards()] proposal_ids = [] for n in range(200): prop_id = n*2 data = {'id': prop_id, 'authors': [{'email': random.choice(emails), 'name': 'Speaker Name Here'}], 'title': words(3,8).title(), 'category': words(1,2), 'duration': '30 minutes', 'description': ipsum(4), 'audience': ipsum(1), 'audience_level': 'Novice', 'notes': ipsum(2), 'objective': ipsum(1), 'recording_release': bool(random.random() > 0.05), 'abstract': ipsum(1), 'outline': ipsum(5)+"\n[test](http://www.google.com/)\n", 'additional_notes': ipsum(1), 'additional_requirements': ipsum(1)} l.add_proposal(data) proposal_ids.append(prop_id) if random.randint(0, 3) == 0: for n in range(random.randint(1, 10)): l.add_to_discussion(random.choice(user_ids), prop_id, ipsum(1)) if random.randint(0, 2) == 0: for n in range(random.randint(1, 5)): vote = {k:random.randint(0, 2) for k in standards} l.vote(random.choice(user_ids), prop_id, vote) if random.randint(0, 3) == 0: data['notes'] = 'UPDATED' + ipsum(2) l.add_proposal(data) random.shuffle(proposal_ids) proposal_ids = proposal_ids[:70] for n in range(0, len(proposal_ids), 5): l.create_group(words(2,4).title(), proposal_ids[n:n+5])
def approve_user(uid): l.approve_user(uid) user = l.get_user(uid) flash('Approved user {}'.format(user.email)) l.email_approved(uid) return redirect(url_for('list_users'))
def approve_user(uid): l.approve_user(uid) user = l.get_user(uid) flash("Approved user {}".format(user.email)) return redirect(url_for("list_users"))