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 on_message(self, message): global ready_count global game_stage data = json.loads(message) # print(logic.players[identify_client(self)].name + ' is sending data: ' + data) client_id = identify_client(self) if data['type'] == 'choice': print('________got mes from ' + logic.players[identify_client(self)]['name']) # if game_stage == 1 and logic.players[logic.main_player]['socket'] == self: if game_stage == 1: logic.put_card(data['choice'], client_id) logic.cur_ass = data['data'] change_stage(2) elif game_stage == 2: logic.put_card(data['choice'], client_id) ready_count += 1 if all_ready(): change_stage(3) elif game_stage == 3: logic.vote(data['choice'], client_id) ready_count += 1 if all_ready(): change_stage(4) elif data['type'] == 'join': print(data['data'] + ' is joining game.') logic.new_player(data['data'], self) notify_all() elif data['type'] == 'start': new_game() else: print('Incorrect request')
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 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 vote(id): standards = l.get_standards() scores = {} for s in standards: scores[s.id] = int(request.values['standard-{}'.format(s.id)]) nominate = request.values.get('nominate', '0') == '1' l.vote(request.user.id, id, scores, nominate) return render_template('user_vote_snippet.html', standards=l.get_standards(), votes=l.get_votes(id), existing_vote=l.get_user_vote(request.user.id, id))
def vote(id): standards = l.get_standards() scores = {} for s in standards: scores[s.id] = int(request.values['standard-{}'.format(s.id)]) nominate = request.values.get('nominate', '0') == '1' l.vote(request.user.id, id, scores, nominate) return render_template('user_vote_snippet.html', standards=l.get_standards(), votes = l.get_votes(id), existing_vote=l.get_user_vote(request.user.id, id))
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 trx(): print("masuk") content = request.json sender_n = int(content['sender_n']) sender_e = int(content['sender_e']) sender_d = int(content['sender_d']) receiver_n = int(content['receiver_n']) receiver_e = int(content['receiver_e']) return logic.vote(sender_n, sender_e, sender_d, receiver_n, receiver_e)
def vote(id): standards = l.get_standards() scores = {} for s in standards: scores[s.id] = int(request.values["standard-{}".format(s.id)]) nominate = request.values.get("nominate", "0") == "1" redir = redirect(url_for("screening", id=id)) if l.vote(request.user.id, id, scores, nominate): proposal = l.get_proposal(id) return redir return redir
def vote(): vote_input = request.get_json() logic.vote(vote_input) return json.dumps(True)
def vote(): vote_input = request.get_json() logic.vote(vote_input) return json.dumps(vote_input['planet_name'])
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])