def test_add_media(self, p_urllib2, p_logging): def mocked_urlopen(request): return StringIO(""" <?xml version="1.0"?> <Response> <Message>All medias have been added.</Message> <MessageCode>2.1</MessageCode> <BatchID>47520</BatchID> <Success> <MediaShortLink> <SourceFile>http://www.com/file.flv</SourceFile> <ShortLink>8oxv6x</ShortLink> <MediaID>13969839</MediaID> <QRCode>http://vid.ly/8oxv6x/qrcodeimg</QRCode> <HtmlEmbed>code code</HtmlEmbed> <EmailEmbed>more code code</EmailEmbed> </MediaShortLink> </Success> </Response> """) p_urllib2.urlopen = mocked_urlopen shortcode, error = utils.vidly_add_media('http//www.com') eq_(shortcode, '8oxv6x') ok_(not error) # same thing should work with optional extras shortcode, error = utils.vidly_add_media( 'http//www.com', email='*****@*****.**', token_protection=True ) eq_(shortcode, '8oxv6x') ok_(not error)
def test_add_media(self, p_urllib2, p_logging): def mocked_urlopen(request): return StringIO(""" <?xml version="1.0"?> <Response> <Message>All medias have been added.</Message> <MessageCode>2.1</MessageCode> <BatchID>47520</BatchID> <Success> <MediaShortLink> <SourceFile>http://www.com/file.flv</SourceFile> <ShortLink>8oxv6x</ShortLink> <MediaID>13969839</MediaID> <QRCode>http://vid.ly/8oxv6x/qrcodeimg</QRCode> <HtmlEmbed>code code</HtmlEmbed> <EmailEmbed>more code code</EmailEmbed> </MediaShortLink> </Success> </Response> """) p_urllib2.urlopen = mocked_urlopen shortcode, error = utils.vidly_add_media('http//www.com') eq_(shortcode, '8oxv6x') ok_(not error) # same thing should work with optional extras shortcode, error = utils.vidly_add_media('http//www.com', email='*****@*****.**', token_protection=True) eq_(shortcode, '8oxv6x') ok_(not error)
def vidly_url_to_shortcode(request, id): get_object_or_404(Event, id=id) form = forms.VidlyURLForm(data=request.POST) if form.is_valid(): url = form.cleaned_data['url'] email = form.cleaned_data['email'] token_protection = form.cleaned_data['token_protection'] shortcode, error = vidly_add_media(url, email=email, token_protection=token_protection) if shortcode: return {'shortcode': shortcode} else: return HttpResponseBadRequest(error) return HttpResponseBadRequest(str(form.errors))
def vidly_url_to_shortcode(request, id): get_object_or_404(Event, id=id) form = forms.VidlyURLForm(data=request.POST) if form.is_valid(): url = form.cleaned_data['url'] email = form.cleaned_data['email'] token_protection = form.cleaned_data['token_protection'] shortcode, error = vidly_add_media( url, email=email, token_protection=token_protection ) if shortcode: return {'shortcode': shortcode} else: return HttpResponseBadRequest(error) return HttpResponseBadRequest(str(form.errors))
def test_add_media_failure(self, p_urllib2, p_logging): def mocked_urlopen(request): # I don't actually know what it would say return StringIO(""" <?xml version="1.0"?> <Response> <Message>Error</Message> <MessageCode>0.0</MessageCode> <Errors> <Error> <ErrorCode>0.0</ErrorCode> <ErrorName>Error message</ErrorName> <Description>bla bla</Description> <Suggestion>ble ble</Suggestion> </Error> </Errors> </Response> """) p_urllib2.urlopen = mocked_urlopen shortcode, error = utils.vidly_add_media('http//www.com') ok_(not shortcode) ok_('0.0' in error)