예제 #1
0
    def test_matching_tutorials_unregister(self, mock_get):
        """Simple Test Case where matches occur and a User has unregistered"""
        user_model = get_user_model()
        u1 = user_model.objects.create_user('john', email='*****@*****.**', password='******')
        u2 = user_model.objects.create_user('jane', email='*****@*****.**', password='******')

        tut1 = PyConTutorialProposalFactory(title='Tutorial1')
        PresentationFactory(proposal_base=tut1)
        tut2 = PyConTutorialProposalFactory(title='Tutorial2')
        PresentationFactory(proposal_base=tut2)

        # Add u2 to tut2
        tut2.registrants.add(u2)
        self.assertIsNone(tut1.max_attendees)
        self.assertIn(u2, tut2.registrants.all())

        mock_get.return_value = MockGet(tut1=tut1.pk,
                                        tut2=tut2.pk,
                                        u1=u1.pk,
                                        u2=u2.pk)
        call_command('update_tutorial_registrants')

        tut1 = PyConTutorialProposal.objects.get(pk=tut1.pk)
        self.assertEqual(8, tut1.max_attendees)
        self.assertEqual(2, tut1.registrants.all().count())
        for u in [u1, u2]:
            self.assertIn(u, tut1.registrants.all())

        tut2 = PyConTutorialProposal.objects.get(pk=tut2.pk)
        self.assertEqual(10, tut2.max_attendees)
        # updated; dropping u2 and adding u1
        self.assertEqual(1, tut2.registrants.all().count())
        self.assertIn(u1, tut2.registrants.all())
예제 #2
0
    def test_matching_tutorials(self, mock_get):
        """Simple Test Case where matches occur."""
        user_model = get_user_model()
        u1 = user_model.objects.create_user('john',
                                            email='*****@*****.**',
                                            password='******')
        u2 = user_model.objects.create_user('jane',
                                            email='*****@*****.**',
                                            password='******')

        tut1 = PyConTutorialProposalFactory.create(title='Tutorial1')
        tut2 = PyConTutorialProposalFactory.create(title='Tutorial2')

        for tut in [tut1, tut2]:
            self.assertIsNone(tut.max_attendees)
            self.assertEqual(0, tut.registrants.all().count())

        mock_get.return_value = MockGet(tut1=tut1.proposalbase_ptr_id,
                                        tut2=tut2.proposalbase_ptr_id)
        call_command('update_tutorial_registrants')

        tut1 = PyConTutorialProposal.objects.get(pk=tut1.pk)
        self.assertEqual(8, tut1.max_attendees)
        self.assertEqual(2, tut1.registrants.all().count())
        for u in [u1, u2]:
            self.assertIn(u, tut1.registrants.all())

        tut2 = PyConTutorialProposal.objects.get(pk=tut2.pk)
        self.assertEqual(10, tut2.max_attendees)
        self.assertEqual(1, tut2.registrants.all().count())
        self.assertIn(u1, tut2.registrants.all())
예제 #3
0
    def test_matching_tutorials_unregister(self, mock_get):
        """Simple Test Case where matches occur and a User has unregistered"""
        user_model = get_user_model()
        u1 = user_model.objects.create_user('john', email='*****@*****.**', password='******')
        u2 = user_model.objects.create_user('jane', email='*****@*****.**', password='******')

        tut1 = PyConTutorialProposalFactory.create(title='Tutorial1')
        tut2 = PyConTutorialProposalFactory.create(title='Tutorial2')

        # Add u2 to tut2
        tut2.registrants.add(u2)
        self.assertIsNone(tut1.max_attendees)
        self.assertIn(u2, tut2.registrants.all())

        mock_get.return_value = MockGet(tut1=tut1.proposalbase_ptr_id, tut2=tut2.proposalbase_ptr_id)
        call_command('update_tutorial_registrants')

        tut1 = PyConTutorialProposal.objects.get(pk=tut1.pk)
        self.assertEqual(8, tut1.max_attendees)
        self.assertEqual(2, tut1.registrants.all().count())
        for u in [u1, u2]:
            self.assertIn(u, tut1.registrants.all())

        tut2 = PyConTutorialProposal.objects.get(pk=tut2.pk)
        self.assertEqual(10, tut2.max_attendees)
        # updated; dropping u2 and adding u1
        self.assertEqual(1, tut2.registrants.all().count())
        self.assertIn(u1, tut2.registrants.all())
예제 #4
0
    def test_tutorials_presentation(self):
        section = Section.objects.get(name='Tutorials')
        schedule = Schedule.objects.get(section=section)
        prop_kind = ProposalKind.objects.get(name__iexact='tutorial')
        proposal = PyConTutorialProposalFactory(kind=prop_kind, )
        day = Day.objects.create(schedule=schedule, date=date.today())
        kind = SlotKind.objects.create(schedule=schedule, label="Foo")
        slot = Slot.objects.create(
            day=day,
            kind=kind,
            start=now().time(),
            end=now().time(),
        )
        pres = PresentationFactory(
            title=proposal.title,
            abstract=proposal.abstract,
            section=section,
            slot=slot,
            cancelled=False,
            proposal_base=proposal,
        )
        rsp = self.client.get(self.url)
        self.assertEqual(OK, rsp.status_code)
        self.assertEqual('attachment; filename=program_export.zip',
                         rsp['Content-Disposition'])

        zipfile = ZipFile(StringIO(rsp.content), "r")
        # Check out the zip - testzip() returns None if no errors found
        self.assertIsNone(zipfile.testzip())

        fname = "program_export/presentations/csv/tutorials.csv"
        file_contents = zipfile.open(fname, "U").read().decode('utf-8')
        self.assertIn(pres.title, file_contents)
        self.assertIn(pres.abstract, file_contents)
예제 #5
0
    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")
예제 #6
0
    def test_surprise_email_address(self, mock_get):
        """Simple Test Case where registrant has a different email than our DB"""
        user_model = get_user_model()
        u1 = user_model.objects.create_user('john', email='*****@*****.**', password='******')
        u2 = user_model.objects.create_user('jane', email='*****@*****.**', password='******')

        tut1 = PyConTutorialProposalFactory(title='Tutorial1')
        PresentationFactory(proposal_base=tut1)
        tut2 = PyConTutorialProposalFactory(title='Tutorial2')
        PresentationFactory(proposal_base=tut2)

        # Add u2 to tut2
        tut2.registrants.add(u2)
        self.assertIsNone(tut1.max_attendees)
        self.assertIn(u2, tut2.registrants.all())

        mock_get.return_value = MockGet(tut1=tut1.pk,
                                        tut2=tut2.pk,
                                        u1=u1.pk,
                                        u2=u2.pk)
        call_command('update_tutorial_registrants')

        tut1 = PyConTutorialProposal.objects.get(pk=tut1.pk)
        self.assertEqual(8, tut1.max_attendees)
        self.assertEqual(2, tut1.registrants.all().count())
        for u in [u1, u2]:
            self.assertIn(u, tut1.registrants.all())

        tut2 = PyConTutorialProposal.objects.get(pk=tut2.pk)
        self.assertEqual(10, tut2.max_attendees)
        # updated; dropping u2 and adding u1
        self.assertEqual(1, tut2.registrants.all().count())
        self.assertIn(u1, tut2.registrants.all())

        emails1 = EmailAddress.objects.filter(user=u1)
        emails2 = EmailAddress.objects.filter(user=u2)

        self.assertEqual(['*****@*****.**'], [e.email for e in emails1])
        self.assertEqual(
            sorted(['*****@*****.**', '*****@*****.**']),
            sorted([e.email for e in emails2])
        )
예제 #7
0
    def test_reverse_relation(self):
        user = User.objects.create_user("Foo")
        tutorial = PyConTutorialProposalFactory.create()
        self.assertFalse(tutorial.tutorial_messages.all())

        # Just the minimum required fields
        x = PyConTutorialMessage.objects.create(
            tutorial=tutorial,
            user=user,
            message="Foo",
        )
        # the reverse relation works
        self.assertEqual(x, tutorial.tutorial_messages.all()[0])
예제 #8
0
파일: test_forms.py 프로젝트: PyCon/pycon
    def test_message_form(self):
        user = User.objects.create_user("Foo")
        tutorial = PyConTutorialProposalFactory.create()
        instance = PyConTutorialMessage(tutorial=tutorial, user=user)
        form = TutorialMessageForm(instance=instance)
        self.assertFalse(form.is_valid())
        data = {'message': 'A Message!', }
        instance = PyConTutorialMessage(tutorial=tutorial, user=user)
        form = TutorialMessageForm(data, instance=instance)
        self.assertTrue(form.is_valid(), msg=form.errors)

        # Leave out a required field
        del data['message']
        form = TutorialMessageForm(data, instance=instance)
        self.assertFalse(form.is_valid())
예제 #9
0
    def test_message_form(self):
        user = User.objects.create_user("Foo")
        tutorial = PyConTutorialProposalFactory.create()
        instance = PyConTutorialMessage(tutorial=tutorial, user=user)
        form = TutorialMessageForm(instance=instance)
        self.assertFalse(form.is_valid())
        data = {
            'message': 'A Message!',
        }
        instance = PyConTutorialMessage(tutorial=tutorial, user=user)
        form = TutorialMessageForm(data, instance=instance)
        self.assertTrue(form.is_valid(), msg=form.errors)

        # Leave out a required field
        del data['message']
        form = TutorialMessageForm(data, instance=instance)
        self.assertFalse(form.is_valid())