def test_errored_updating_vidly_submission(self, p_urlopen): def mocked_urlopen(request): xml = SAMPLE_XML.replace( '<Status>Finished</Status>', '<Status>Error</Status>', ) return StringIO(xml.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() vidly_submission = VidlySubmission.objects.create( event=event, url='https://example.com', tag='abc123' ) archive(event) vidly_submission = VidlySubmission.objects.get(id=vidly_submission.id) ok_(vidly_submission.errored) ok_(not vidly_submission.finished)
def test_finished(self, p_urlopen): def mocked_urlopen(request): return StringIO(SAMPLE_XML.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') event.status = Event.STATUS_PENDING event.archive_time = None vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() archive(event) eq_(len(mail.outbox), 0) event = Event.objects.get(pk=event.pk) now = timezone.now() eq_( event.archive_time.strftime('%Y%m%d %H%M'), now.strftime('%Y%m%d %H%M'), ) eq_(event.status, Event.STATUS_SCHEDULED)
def test_a_bad_event_parameter_2(self, mocked_logging): event = Event.objects.get(title='Test event') vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.save() archive(event) mocked_logging.warn.assert_called_with( 'Event %r does not have a Vid.ly tag', u'Test event' )
def handle(self, **options): events = ( Event.objects .filter(status=Event.STATUS_PENDING, archive_time__isnull=True, template__name__contains='Vid.ly') ) for event in events: archive(event, swallow_email_exceptions=True)
def event_archive_auto(request, id): event = get_object_or_404(Event, id=id) assert 'Vid.ly' in event.template.name assert event.template_environment.get('tag') archiver.archive(event) messages.info( request, "Archiving started for this event" ) url = reverse('manage:event_edit', args=(event.pk,)) return redirect(url)
def test_processing(self, p_urlopen): def mocked_urlopen(request): xml = SAMPLE_XML.replace( '<Status>Finished</Status>', '<Status>Processing</Status>', ) return StringIO(xml.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() archive(event) eq_(len(mail.outbox), 0)
def test_still_not_found(self, p_urlopen): def mocked_urlopen(request): return StringIO(SAMPLE_MEDIALIST_XML.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'NOTKNOWN'} event.save() archive(event) sent_email = mail.outbox[-1] eq_(sent_email.to, [x[1] for x in settings.ADMINS]) ok_('NOTKNOWN' in sent_email.subject) ok_(reverse('manage:event_edit', args=(event.pk,)) in sent_email.body)
def test_finished_updating_vidly_submission(self, p_urlopen): def mocked_urlopen(request): return StringIO(SAMPLE_XML.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') event.status = Event.STATUS_PENDING event.archive_time = None vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() vidly_submission = VidlySubmission.objects.create( event=event, url='https://example.com', tag='abc123') archive(event) vidly_submission = VidlySubmission.objects.get(id=vidly_submission.id) ok_(not vidly_submission.errored) ok_(vidly_submission.finished)
def test_errored(self, p_urlopen): def mocked_urlopen(request): xml = SAMPLE_XML.replace( '<Status>Finished</Status>', '<Status>Error</Status>', ) return StringIO(xml.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() archive(event) sent_email = mail.outbox[-1] eq_(sent_email.to, [x[1] for x in settings.ADMINS]) ok_('Unable to archive pending event' in sent_email.subject) ok_('abc123' in sent_email.subject) ok_(reverse('manage:event_edit', args=(event.pk, )) in sent_email.body)
def test_errored_updating_vidly_submission(self, p_urlopen): def mocked_urlopen(request): xml = SAMPLE_XML.replace( '<Status>Finished</Status>', '<Status>Error</Status>', ) return StringIO(xml.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() vidly_submission = VidlySubmission.objects.create( event=event, url='https://example.com', tag='abc123') archive(event) vidly_submission = VidlySubmission.objects.get(id=vidly_submission.id) ok_(vidly_submission.errored) ok_(not vidly_submission.finished)
def test_errored(self, p_urlopen): def mocked_urlopen(request): xml = SAMPLE_XML.replace( '<Status>Finished</Status>', '<Status>Error</Status>', ) return StringIO(xml.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() archive(event) sent_email = mail.outbox[-1] eq_(sent_email.to, [x[1] for x in settings.ADMINS]) ok_('Unable to archive pending event' in sent_email.subject) ok_('abc123' in sent_email.subject) ok_(reverse('manage:event_edit', args=(event.pk,)) in sent_email.body)
def test_finished_updating_vidly_submission(self, p_urlopen): def mocked_urlopen(request): return StringIO(SAMPLE_XML.strip()) p_urlopen.side_effect = mocked_urlopen event = Event.objects.get(title='Test event') event.status = Event.STATUS_PENDING event.archive_time = None vidly_template = Template.objects.create(name='Vid.ly Test') event.template = vidly_template event.template_environment = {'tag': 'abc123'} event.save() vidly_submission = VidlySubmission.objects.create( event=event, url='https://example.com', tag='abc123' ) archive(event) vidly_submission = VidlySubmission.objects.get(id=vidly_submission.id) ok_(not vidly_submission.errored) ok_(vidly_submission.finished)
def test_a_bad_event_parameter_1(self, mocked_logging): event = Event.objects.get(title='Test event') archive(event) mocked_logging.warn.assert_called_with( 'Event %r not a Vid.ly event', 'Test event' )