def test_review_section(self): talk = PyConTalkProposalFactory( title="My talk", description="Description of the talk", category__name="My talk category" ) # Make a few more talks to inflate the queries if we haven't optimized them properly for __ in range(10): ProposalResultFactory(proposal=PyConTalkProposalFactory()) tutorial = PyConTutorialProposalFactory( title="My tutorial", category__name="My tutorial category" ) self.user = self.create_user() self.login() # If we go to the talk section, we only see talk data (not # tutorial data). kind = ProposalKind.objects.get(slug='talk') section = kind.section url = reverse('review_section', kwargs={'section_slug': section.slug}) ct = ContentType.objects.get_for_model(Review) perm, __ = Permission.objects.get_or_create( codename="can_review_%s" % section.slug, content_type=ct, ) self.user.user_permissions.add(perm) # Run it once to force creation of result objects rsp = self.client.get(url) self.assertEqual(OK, rsp.status_code) # Now run it for the test, making sure we don't need more queries than reasonable with self.assertNumQueries(15): rsp = self.client.get(url) self.assertEqual(OK, rsp.status_code) self.assertContains(rsp, talk.title) self.assertContains(rsp, "My talk category") self.assertNotContains(rsp, tutorial.title) self.assertNotContains(rsp, "My tutorial category") # Now make sure the tutorial section has tutorial data but not talk. kind2 = ProposalKind.objects.get(slug='tutorial') section = kind2.section perm, __ = Permission.objects.get_or_create( codename="can_review_%s" % section.slug, content_type=ct, ) self.user.user_permissions.add(perm) url = reverse('review_section', kwargs={'section_slug': section.slug}) rsp = self.client.get(url) self.assertEqual(OK, rsp.status_code) self.assertNotContains(rsp, talk.title) self.assertNotContains(rsp, "My talk category") self.assertContains(rsp, tutorial.title) self.assertContains(rsp, "My tutorial category")
def setUp(self): self.group = ThunderdomeGroupFactory(code='fred') self.auth_key = APIAuth.objects.create(name="test") self.url = reverse('thunderdome_group_decide', args=(self.group.code, )) self.talk1 = PyConTalkProposalFactory(thunderdome_group=self.group) self.talk2 = PyConTalkProposalFactory(thunderdome_group=self.group) ProposalResultFactory(proposal=self.talk1, status="undecided") ProposalResultFactory(proposal=self.talk2, status="undecided")
def test_submit_review(self): # Reviewers can submit multiple reviews. Only their most recent vote counts. talk = PyConTalkProposalFactory(title="talk", description="talk", category__name="My talk category") self.user = self.create_user() perm, __ = Permission.objects.get_or_create( codename="can_review_talks", content_type=ContentType.objects.get_for_model(Review), ) self.user.user_permissions.add(perm) user2 = self.create_user(username="******") user2.user_permissions.add(perm) # User submits first vote: +1 talk = self.submit_review(talk, self.user, Votes.PLUS_ONE) # One +1 vote gives a score of 3 self.assertEqual(3, talk.result.score) # Let's try adding another vote - because it's from the same # user, it should supersede their previous vote in the score. talk = self.submit_review(talk, self.user, Votes.MINUS_ZERO) # A -0 vote is a score of -1 self.assertEqual(-1, talk.result.score) # Now, add a vote from a different user, which should be counted # separately and adjust the score talk = self.submit_review(talk, user2, Votes.PLUS_ONE) # Adding a new +1 vote adds 3 to the previous score self.assertEqual(2, talk.result.score)