def test_place_order(self, rpost): def mocked_post(url, json, headers): ok_(settings.REV_BASE_URL in url) eq_(json['notification']['url'], 'https://example.com/callback') eq_(json['notification']['level'], 'FinalOnly') eq_( json['caption_options']['inputs'][0]['uri'], 'urn:rev:inputmedia:P3VwbG9hZHMvMjAxNi0xMC0yM' ) eq_( json['caption_options']['output_file_formats'], ['DFXP'] ) ok_(settings.REV_CLIENT_API_KEY in headers['Authorization']) ok_(settings.REV_USER_API_KEY in headers['Authorization']) return Response('', status_code=201, headers={ 'Location': settings.REV_BASE_URL + '/api/v1/orders/CP000001', }) rpost.side_effect = mocked_post result = rev.place_order( 'urn:rev:inputmedia:P3VwbG9hZHMvMjAxNi0xMC0yM', webhook_url='https://example.com/callback', ) eq_(result, settings.REV_BASE_URL + '/api/v1/orders/CP000001')
def test_place_order(self, rpost): def mocked_post(url, json, headers): ok_(settings.REV_BASE_URL in url) eq_(json['notification']['url'], 'https://example.com/callback') eq_(json['notification']['level'], 'FinalOnly') eq_(json['caption_options']['inputs'][0]['uri'], 'urn:rev:inputmedia:P3VwbG9hZHMvMjAxNi0xMC0yM') eq_(json['caption_options']['output_file_formats'], ['DFXP']) ok_(settings.REV_CLIENT_API_KEY in headers['Authorization']) ok_(settings.REV_USER_API_KEY in headers['Authorization']) return Response('', status_code=201, headers={ 'Location': settings.REV_BASE_URL + '/api/v1/orders/CP000001', }) rpost.side_effect = mocked_post result = rev.place_order( 'urn:rev:inputmedia:P3VwbG9hZHMvMjAxNi0xMC0yM', webhook_url='https://example.com/callback', ) eq_(result, settings.REV_BASE_URL + '/api/v1/orders/CP000001')
def new_event_rev_order(request, event_id): event = get_object_or_404(Event, id=event_id) if request.method == 'POST': form = forms.RevInputForm(request.POST) if form.is_valid(): rev_input = RevInput.objects.create( url=form.cleaned_data['url'], content_type=form.cleaned_data['content_type'], filename=form.cleaned_data['filename'], ) uri = rev.input_order( rev_input.url, filename=rev_input.filename, content_type=rev_input.content_type, ) rev_input.uri = uri rev_input.save() rev_order = RevOrder.objects.create( event=event, input=rev_input, created_user=request.user, output_file_formats=form.cleaned_data['output_file_formats'], ) base_url = get_base_url(request) webhook_url = base_url + reverse('manage:rev_order_update_hook') webhook_url = 'http://requestb.in/sxwiousx' order_uri = rev.place_order( uri, output_file_formats=form.cleaned_data['output_file_formats'], webhook_url=webhook_url, ) rev_order.uri = order_uri rev_order.order_number = order_uri.split('/')[-1] rev_order.update_status(save=False) rev_order.save() return redirect('manage:event_rev_orders', event.pk) else: url = '' content_type = '' filename = '' # If the event is public, and has a vidly submission, use its # SD version in MPEG4 format. if event.template.name.lower().count('vid.ly'): submissions = VidlySubmission.objects.filter( event=event, tag=event.template_environment['tag'], finished__isnull=False, submission_error__isnull=True, ) for submission in submissions.order_by('-finished')[:1]: url = 'https://vid.ly/{}?content=video&format=mp4'.format( submission.tag, ) filename = '{}.mp4'.format(submission.tag) content_type = 'video/mpeg' # get the real URL response = requests.head(url) if response.status_code in (301, 302): url = response.headers['Location'] filename = os.path.basename(url.split('?')[0]) initial = { 'url': url, 'content_type': content_type, 'filename': filename, 'output_file_formats': ['Dfxp'], } form = forms.RevInputForm(initial=initial) context = { 'event': event, 'form': form, } return render(request, 'manage/new_event_rev_order.html', context)