class TestTutorialMessageView(TestCase, TestMixin): def setUp(self): self.presentation = PresentationFactory() self.tutorial_url = reverse( 'schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user() def test_messaging_as_attendee(self): self.presentation.proposal.registrants.add(self.user) self.login() rsp = self.client.get(self.tutorial_url) self.assertIn('id="messages"', rsp.content) # We can display the page prompting for a message to send them url = reverse( 'tutorial_message', kwargs={'pk': self.presentation.proposal.pk}) rsp = self.client.get(url) self.assertEqual(200, rsp.status_code) # "Send" a message to those two applications test_message = 'One if by land and two if by sea' data = {'message': test_message, } rsp = self.client.post(url, data=data) self.assertEqual(302, rsp.status_code) msg = PyConTutorialMessage.objects.get( user=self.user, tutorial=self.presentation.proposal) self.assertEqual(test_message, msg.message) # For each message, it's visible, so it should have been emailed to # both the other attendees and speakers. Total: 1 message for this case self.assertEqual(1, len(mail.outbox)) def test_messaging_as_speaker(self): speaker = SpeakerFactory(user=self.user) self.presentation.speaker = speaker self.presentation.save() self.login() rsp = self.client.get(self.tutorial_url) self.assertIn('id="messages"', rsp.content) # We can display the page prompting for a message to send them url = reverse( 'tutorial_message', kwargs={'pk': self.presentation.proposal.pk}) rsp = self.client.get(url) self.assertEqual(200, rsp.status_code) # "Send" a message to those two applications test_message = 'One if by land and two if by sea' data = {'message': test_message, } rsp = self.client.post(url, data=data) self.assertEqual(302, rsp.status_code) msg = PyConTutorialMessage.objects.get( user=self.user, tutorial=self.presentation.proposal) self.assertEqual(test_message, msg.message) # For each message, it's visible, so it should have been emailed to # both the other attendees and speakers. Total: 1 message for this case self.assertEqual(1, len(mail.outbox))
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())
def setUp(self): super(TestTutorialMessageView, self).setUp() self.presentation = PresentationFactory( section__conference=Conference.objects.get( id=settings.CONFERENCE_ID)) self.tutorial_url = reverse('schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user()
class TestTutorialEmailView(TestCase, TestMixin): def setUp(self): super(TestTutorialEmailView, self).setUp() self.presentation = PresentationFactory() self.tutorial_url = reverse( 'schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user() @patch('pycon.tutorials.views.queue_email_message') def test_email_submit_as_attendee(self, mock_queue_mail): user = self.create_user('speaker', '*****@*****.**') speaker = SpeakerFactory(user=user) self.presentation.speaker = speaker self.presentation.save() self.presentation.proposal.registrants.add(self.user) self.login() data = { 'subject': 'Test Subject', 'body': 'Test Body' } # We can display the page prompting for a message to send them url = reverse( 'tutorial_email', kwargs={ 'pk': self.presentation.pk, 'pks': self.presentation.speaker.user.pk}) rsp = self.client.post(url, data) self.assertEqual(302, rsp.status_code, rsp.content) self.assertEqual(1, mock_queue_mail.call_count) args, kwargs = mock_queue_mail.call_args email = self.presentation.speaker.user.email self.assertEqual(kwargs['bcc'][0], email) @patch('pycon.tutorials.views.queue_email_message') def test_email_submit_as_speaker(self, mock_queue_mail): attendee = self.create_user(username='******', email="*****@*****.**") speaker = SpeakerFactory(user=self.user) self.presentation.speaker = speaker self.presentation.save() self.login() # Actually submit the thing data = { 'subject': 'Test Subject', 'body': 'Test Body' } # We can display the page prompting for a message to send them url = reverse( 'tutorial_email', kwargs={ 'pk': self.presentation.pk, 'pks': attendee.pk}) rsp = self.client.post(url, data) self.assertEqual(302, rsp.status_code, rsp.content) self.assertEqual(1, mock_queue_mail.call_count) args, kwargs = mock_queue_mail.call_args self.assertEqual(kwargs['bcc'][0], attendee.email)
class TestTutorialEmailView(TestCase, TestMixin): def setUp(self): self.presentation = PresentationFactory() self.tutorial_url = reverse( 'schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user() @patch('pycon.tutorials.views.send_email_message') def test_email_submit_as_attendee(self, mock_send_mail): user = self.create_user('speaker', '*****@*****.**') speaker = SpeakerFactory(user=user) self.presentation.speaker = speaker self.presentation.save() self.presentation.proposal.registrants.add(self.user) self.login() data = { 'subject': 'Test Subject', 'body': 'Test Body' } # We can display the page prompting for a message to send them url = reverse( 'tutorial_email', kwargs={ 'pk': self.presentation.pk, 'pks': self.presentation.speaker.user.pk}) rsp = self.client.post(url, data) self.assertEqual(302, rsp.status_code, rsp.content) self.assertEqual(1, mock_send_mail.call_count) args, kwargs = mock_send_mail.call_args email = self.presentation.speaker.user.email self.assertEqual(kwargs['bcc'][0], email) @patch('pycon.tutorials.views.send_email_message') def test_email_submit_as_speaker(self, mock_send_mail): attendee = self.create_user(username='******', email="*****@*****.**") speaker = SpeakerFactory(user=self.user) self.presentation.speaker = speaker self.presentation.save() self.login() # Actually submit the thing data = { 'subject': 'Test Subject', 'body': 'Test Body' } # We can display the page prompting for a message to send them url = reverse( 'tutorial_email', kwargs={ 'pk': self.presentation.pk, 'pks': attendee.pk}) rsp = self.client.post(url, data) self.assertEqual(302, rsp.status_code, rsp.content) self.assertEqual(1, mock_send_mail.call_count) args, kwargs = mock_send_mail.call_args self.assertEqual(kwargs['bcc'][0], attendee.email)
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)
def setUp(self): self.auth_key = APIAuth.objects.create(name="test") self.presentation = PresentationFactory( video_url='http://video.example.com', assets_url='http://assets.example.com', slides_url='http://slides.example.com', ) self.url = reverse('set_talk_urls', args=[self.presentation.slot.pk])
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]) )
def setUp(self): self.presentation = PresentationFactory() self.tutorial_url = reverse( 'schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user()
class TestTutorialSchedulePresentationView(TestMixin, TestCase): """ Tests for Schedule Presentation Detail view with enhancements for Tutorials """ def setUp(self): self.presentation = PresentationFactory() self.tutorial_url = reverse( 'schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user() def test_no_messaging(self): # Ensure Messages widgets are not in the content if not an attendee rsp = self.client.get(self.tutorial_url) self.assertNotIn('id="messages"', rsp.content) self.login() rsp = self.client.get(self.tutorial_url) self.assertNotIn('id="messages"', rsp.content) def test_attendee(self): # If an attendee, messaging avaialable self.presentation.proposal.registrants.add(self.user) self.login() rsp = self.client.get(self.tutorial_url) self.assertIn('id="messages"', rsp.content) def test_speaker(self): # Avaialable to speakers speaker = SpeakerFactory(user=self.user) self.presentation.speaker = speaker self.presentation.save() self.login() rsp = self.client.get(self.tutorial_url) self.assertIn('id="messages"', rsp.content) def test_cospeaker(self): # Avaialable to cospeakers speaker = SpeakerFactory(user=self.user) self.presentation.additional_speakers.add(speaker) self.login() rsp = self.client.get(self.tutorial_url) self.assertIn('id="messages"', rsp.content) def test_is_staff(self): # Avaialable to staff self.user.is_staff = True self.user.save() self.login() rsp = self.client.get(self.tutorial_url) self.assertIn('id="messages"', rsp.content) def test_post_message(self): # redirect to send message form self.presentation.proposal.registrants.add(self.user) self.login() data = { 'message_action': '', } msg_url = reverse( 'tutorial_message', kwargs={'pk': self.presentation.proposal.pk}) rsp = self.client.post(self.tutorial_url, data) self.assertEqual(302, rsp.status_code) self.assertIn(msg_url, rsp['Location']) def test_post_email_from_attendee(self): # validation error self.presentation.proposal.registrants.add(self.user) self.login() data = { 'email_action': '', } rsp = self.client.post(self.tutorial_url, data) self.assertEqual(302, rsp.status_code) self.assertIn(self.tutorial_url, rsp['Location']) def test_post_email_from_speaker(self): # redirect to send email form, , speaker = SpeakerFactory(user=self.user) self.presentation.speaker = speaker self.presentation.save() self.login() data = { 'email_action': '', 'user_1': 1 } email_url = reverse( 'tutorial_email', kwargs={ 'pk': self.presentation.pk, 'pks': 1}) rsp = self.client.post(self.tutorial_url, data) self.assertEqual(302, rsp.status_code) self.assertIn(email_url, rsp['Location'])
def setUp(self): super(TestTutorialMessageView, self).setUp() self.presentation = PresentationFactory() self.tutorial_url = reverse('schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user()
def setUp(self): super(TestTutorialMessageView, self).setUp() self.presentation = PresentationFactory() self.tutorial_url = reverse( 'schedule_presentation_detail', args=[self.presentation.pk]) self.user = self.create_user()
def test_can_edit(self): # If a presentation has been created, speaker can no longer edit their proposal prop = ProposalBaseFactory() self.assertTrue(prop.can_edit()) PresentationFactory(proposal_base=prop) self.assertFalse(prop.can_edit())