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)
def test_get_logs_data(self): # Get a couple of lines # Create the lines we'll get LINE1 = "Now is the time for all good folks to dance." LINE2 = "A completely different log line" USER1 = "Jim Bob" USER2 = "George Washington" now = datetime.datetime.now() # make sure they have different timestamps, and that microseconds # are preserved then = now + datetime.timedelta(microseconds=1) IRCLogLine.objects.create(proposal=self.proposal, line=LINE1, user=USER1, timestamp=now.strftime(DATETIME_FORMAT)) IRCLogLine.objects.create(proposal=self.proposal, line=LINE2, user=USER2, timestamp=then.strftime(DATETIME_FORMAT)) # Create another proposal and a line to make sure we # don't get it in the results self.proposal2 = PyConTalkProposalFactory.create() later = then + datetime.timedelta(seconds=2) IRCLogLine.objects.create(proposal=self.proposal2, line="wrong", user="******", timestamp=later.strftime(DATETIME_FORMAT)) url = reverse('proposal_irc_logs', kwargs={ 'proposal_id': str(self.proposal.id), }) rsp = self.client.get(url, **self.get_signature(url)) self.assertEqual(200, rsp.status_code) logs = json.loads(rsp.content)['data'] self.assertEqual(2, len(logs)) # They should come out in timestamp order. Data, including time # to the microsecond, should be preserved. self.assertEqual(LINE1, logs[0]['line']) self.assertEqual(USER1, logs[0]['user']) self.assertEqual(now.strftime(DATETIME_FORMAT), logs[0]['timestamp']) self.assertEqual(LINE2, logs[1]['line']) self.assertEqual(then.strftime(DATETIME_FORMAT), logs[1]['timestamp']) self.assertEqual(USER2, logs[1]['user'])
def setUp(self): self.auth_key = APIAuth.objects.create(name="test") self.proposal = PyConTalkProposalFactory.create()
def test_skip_unsubmitted(self): PyConTalkProposalFactory.create(submitted=False) url = reverse('proposal_list') + '?type=talk' rsp = self.client.get(url, **self.get_signature(url)) self.assertEqual(rsp.status_code, 200, rsp.content) self.assertEqual(len(json.loads(rsp.content)['data']), 1)