def test_find_existing_vote_by_reviewer(self): c, t = self.data_setup() subs_key = submissionrecord.make_submission(t.key, c.key, "track", "format") self.assertEquals( len(submission_queries.retrieve_conference_submissions(c.key)), 1) existing_vote = voterecord.find_existing_vote_by_reviewer( subs_key, "Reviewer", 1) self.assertTrue(existing_vote is None) vote = voterecord.VoteRecord(parent=subs_key) vote.cast_vote("Reviewer", 2, "Vote early, vote often", 1) existing_vote = voterecord.find_existing_vote_by_reviewer( subs_key, "Reviewer", 1) self.assertTrue(existing_vote is not None) existing_vote = voterecord.find_existing_vote_by_reviewer( subs_key, "Never voted reviewer", 1) self.assertTrue(existing_vote is None) # test cast_vote wrapper vote = voterecord.cast_new_vote(subs_key, "New reviewer", 1, "OK", 1) new_vote = voterecord.find_existing_vote_by_reviewer( subs_key, "New reviewer", 1) self.assertTrue(new_vote is not None) self.assertEquals(new_vote.comment, "OK")
def get(self): if not (self.request.params.has_key("sub")): self.response.write("Sorry, you shouldn't have been able to get here like that.") return submission_key = ndb.Key(urlsafe=self.request.get("sub")) submission = submission_key.get() conference = submission_key.parent().get() cospeakers = cospeaker.get_cospeakers(submission_key) speakers = [submission.talk.parent().get()] for cospeak in cospeakers: speakers = speakers + [cospeak.profile()] review_round = int(self.request.get("round")) user = self.get_crrt_user().email() existing_vote = voterecord.find_existing_vote_by_reviewer(submission_key, user, round=review_round) if existing_vote is not None: vote_safe_key = existing_vote.key.urlsafe() existing_score = existing_vote.score existing_comment = existing_vote.comment private_comment = votecomment.retrieve_comment_text(existing_vote.key) else: vote_safe_key = "" existing_score = 0 existing_comment = "" private_comment = "" conf_questions = confquestion.retrieve_questions(conference.key) conf_answers = self.conference_answers(conf_questions, submission_key) template_values = { "speakers": speakers, "readonly": "readonly", "talk_details": submission.talk.get(), "submissionrecord_track": conference.track_options()[submission.track], "submissionrecord_duration": conference.duration_options()[submission.duration], "submissionrecord_format": conference.delivery_format_options()[submission.delivery_format], "submissionrecord_expenses": conference.expenses_options()[submission.expense_expectations], "submissionrecord_key": submission_key.urlsafe(), "submission": submission, "cospeakers": cospeakers, "cospeakers_count": len(cospeakers), "voterecord": vote_safe_key, "existing_score": existing_score, "existing_comment": existing_comment, "private_comment": private_comment, "emaillocked": "disabled", "submission": submission, "conf_questions": conf_questions, "conf_answers": conf_answers, "review_round": review_round, } self.write_page('subreview_lib/classicsubscoring.html', template_values)
def test_mutiple_submissions_without_duplicate_votes(self): VotingRound = 1 submission_keys = self.common_data_setup() existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[0], "Allan", VotingRound) self.assertTrue(existing_vote is None) voterecord.cast_new_vote(submission_keys[0], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Anton", -1, "Minus 1", VotingRound) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], 1)), 3) existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[1], "Allan", VotingRound) self.assertTrue(existing_vote is None) voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Anton", -1, "Minus 1", VotingRound) self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 2) duplicates_list = dedupvotes.find_duplicate_votes( self.c.key, VotingRound) self.assertEquals(len(duplicates_list), 0) dedupvotes.remove_duplicates(duplicates_list) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], VotingRound)), 3) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[1], VotingRound)), 3) self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 2)
def vote(self, submission_key, ranking, comment, review_round): existing_vote = voterecord.find_existing_vote_by_reviewer( submission_key, self.get_crrt_user().email(), round=review_round) if existing_vote is None: existing_vote = self.new_vote(submission_key, ranking, comment, review_round) else: self.update_existing_vote(existing_vote, ranking, comment, review_round) return existing_vote
def test_dedup_leave_other_rounds(self): VotingRound = 1 submission_keys = self.common_data_setup() existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[0], "Allan", VotingRound) self.assertTrue(existing_vote is None) voterecord.cast_new_vote(submission_keys[0], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Anton", -1, "Minus 1", VotingRound) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], VotingRound)), 3) existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[1], "Allan", VotingRound) self.assertTrue(existing_vote is None) # Set up the bug voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Anton", -1, "Minus 1", VotingRound) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[1], VotingRound)), 5) # This is the bug # Because of extra vote the total is wrong self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 4) # Add votes for another round, also with duplicates voterecord.cast_new_vote(submission_keys[0], "Harry", 1, "One", VotingRound + 1) voterecord.cast_new_vote(submission_keys[0], "Ron", 2, "Two", VotingRound + 1) voterecord.cast_new_vote(submission_keys[0], "Percy", -1, "Minus 1", VotingRound + 1) self.assertEquals( len( voterecord.find_existing_votes(submission_keys[0], VotingRound + 1)), 3) voterecord.cast_new_vote(submission_keys[1], "Harry", 1, "One", VotingRound + 1) voterecord.cast_new_vote(submission_keys[1], "Harry", 1, "One", VotingRound + 1) voterecord.cast_new_vote(submission_keys[1], "Harry", 1, "One", VotingRound + 1) voterecord.cast_new_vote(submission_keys[1], "Ron", 2, "Two", VotingRound + 1) voterecord.cast_new_vote(submission_keys[1], "Percy", -1, "Minus 1", VotingRound + 1) self.assertEquals( len( voterecord.find_existing_votes(submission_keys[1], VotingRound + 1)), 5) duplicates_list = dedupvotes.find_duplicate_votes( self.c.key, VotingRound) self.assertEquals(len(duplicates_list), 1) self.assertEquals(len(duplicates_list[duplicates_list.keys()[0]]), 3) self.assertEquals(len(duplicates_list["Allan"]), 3) dedupvotes.remove_duplicates(duplicates_list) # Check it was all done self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], VotingRound)), 3) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[1], VotingRound)), 3) # And the total score is now correct self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 2) # Check second round wasn't touched self.assertEquals( len( voterecord.find_existing_votes(submission_keys[0], VotingRound + 1)), 3) self.assertEquals( len( voterecord.find_existing_votes(submission_keys[1], VotingRound + 1)), 5) # Fix it second_duplicates_list = dedupvotes.find_duplicate_votes( self.c.key, VotingRound + 1) dedupvotes.remove_duplicates(second_duplicates_list) self.assertEquals( len( voterecord.find_existing_votes(submission_keys[0], VotingRound + 1)), 3) self.assertEquals( len( voterecord.find_existing_votes(submission_keys[1], VotingRound + 1)), 3) self.assertEqual( submission_keys[0].get().get_scores(VotingRound + 1).total_score, 2) self.assertEqual( submission_keys[1].get().get_scores(VotingRound + 1).total_score, 2)
def test_multiple_submissions_with_duplicate_votes(self): VotingRound = 1 submission_keys = self.common_data_setup() existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[0], "Allan", VotingRound) self.assertTrue(existing_vote is None) voterecord.cast_new_vote(submission_keys[0], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Anton", -1, "Minus 1", VotingRound) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], 1)), 3) existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[1], "Allan", VotingRound) self.assertTrue(existing_vote is None) # Set up the bug voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Anton", -1, "Minus 1", VotingRound) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[1], VotingRound)), 5) # This is the bug # Because of extra vote the total is wrong self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 4) # Another submission with duplicae votes t3 = talk.Talk() t3.title = "Talk3 - Another submission with duplicates" t3.put() subs_key3 = submissionrecord.make_submission(t3.key, self.c.key, "track", "format") submission_keys.append(subs_key3) self.assertEquals( len(submissionrecord.retrieve_conference_submissions(self.c.key)), 3) voterecord.cast_new_vote(submission_keys[2], "Harry", 2, "One", VotingRound) voterecord.cast_new_vote(submission_keys[2], "Ron", 2, "One", VotingRound) voterecord.cast_new_vote(submission_keys[2], "Draco", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[2], "Draco", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[2], "Draco", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[2], "Percy", 3, "Three", VotingRound) # check the bug is in place self.assertEquals( len(voterecord.find_existing_votes(submission_keys[2], VotingRound)), 6) self.assertEqual( submission_keys[2].get().get_scores(VotingRound).total_score, 10) duplicates_list = dedupvotes.find_duplicate_votes( self.c.key, VotingRound) self.assertEquals(len(duplicates_list), 2) dedupvotes.remove_duplicates(duplicates_list) # Check it was all done self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], VotingRound)), 3) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[1], VotingRound)), 3) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[2], VotingRound)), 4) # And the total score is now correct self.assertEqual( submission_keys[0].get().get_scores(VotingRound).total_score, 2) self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 2) self.assertEqual( submission_keys[2].get().get_scores(VotingRound).total_score, 8)
def test_find_and_remove_duplicate_votes(self): VotingRound = 1 submission_keys = self.common_data_setup() existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[0], "Allan", VotingRound) self.assertTrue(existing_vote is None) voterecord.cast_new_vote(submission_keys[0], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[0], "Anton", -1, "Minus 1", VotingRound) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], VotingRound)), 3) existing_vote = voterecord.find_existing_vote_by_reviewer( submission_keys[1], "Allan", VotingRound) self.assertTrue(existing_vote is None) # Set up the bug voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Allan", 1, "One", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Grisha", 2, "Two", VotingRound) voterecord.cast_new_vote(submission_keys[1], "Anton", -1, "Minus 1", VotingRound) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[1], VotingRound)), 5) # This is the bug # Because of extra vote the total is wrong self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 4) duplicates_list = dedupvotes.find_duplicate_votes( self.c.key, VotingRound) self.assertEquals(len(duplicates_list), 1) self.assertEquals(len(duplicates_list[duplicates_list.keys()[0]]), 3) self.assertEquals(len(duplicates_list["Allan"]), 3) dedupvotes.remove_duplicates(duplicates_list) # Check it was all done self.assertEquals( len(voterecord.find_existing_votes(submission_keys[0], VotingRound)), 3) self.assertEquals( len(voterecord.find_existing_votes(submission_keys[1], VotingRound)), 3) # And the total score is now correct self.assertEqual( submission_keys[1].get().get_scores(VotingRound).total_score, 2)
def find_vote_sugar(subs_key, reviewer, rr): v = voterecord.find_existing_vote_by_reviewer(subs_key, reviewer, rr) if v is None: return "No vote" return v.score
def get(self): submission_key = ndb.Key(urlsafe=self.request.get("sub")) submission = submission_key.get() conference = submission_key.parent().get() user = self.get_crrt_user().email() existing_vote = voterecord.find_existing_vote_by_reviewer( submission_key, user, round=1) if existing_vote is not None: vote_safe_key = existing_vote.key.urlsafe() existing_score = existing_vote.score existing_comment = existing_vote.comment private_comment = votecomment.retrieve_comment_text( existing_vote.key) else: vote_safe_key = "" existing_score = 1 existing_comment = "" private_comment = "" conf_questions = confquestion.retrieve_questions(conference.key) conf_answers = self.conference_answers(conf_questions, submission_key) newscoringconfig = confreviewconfig.get_conference_review_factory(conference.key). \ get_round_config(int(self.request.get("round"))) speakers = {} if newscoringconfig.is_speaker_named(): show_name = True speakers = self.retrieve_speakers(submission) else: show_name = False template_values = { "speakers": speakers, "readonly": "readonly", "talk_details": submission.talk.get(), "submissionrecord_track": conference.track_options()[submission.track], "submissionrecord_duration": conference.duration_options()[submission.duration], "submissionrecord_format": conference.delivery_format_options()[submission.delivery_format], "submissionrecord_expenses": conference.expenses_options()[submission.expense_expectations], "submissionrecord_key": submission_key.urlsafe(), "voterecord": vote_safe_key, "existing_score": existing_score, "existing_comment": existing_comment, "private_comment": private_comment, "emaillocked": "disabled", "submission": submission, "conf_questions": conf_questions, "conf_answers": conf_answers, "newscoringconfig": newscoringconfig, "show_name": show_name, } self.write_page('subreview_lib/newscoringpage.html', template_values)