def test_bitly_shorten(self, shorten, cache_set): long_url = 'http://example.com/long-url' short_url = 'http://bit.ly/short-url' # the usual case of returning a dict with a URL def short_mock(*args, **kwargs): return {'url': short_url} shorten.side_effect = short_mock eq_(bitly_shorten(long_url), short_url) shorten.assert_called_with(long_url) # in case of a key error def short_mock(*args, **kwargs): return {} shorten.side_effect = short_mock eq_(bitly_shorten(long_url), long_url) shorten.assert_called_with(long_url) # in case of an upstream error shorten.side_effect = bitly_api.BitlyError('500', 'fail fail fail') eq_(bitly_shorten(long_url), long_url)
def test_update_document_share_url_error(self, bitly): bitly.shorten.side_effect = bitly_api.BitlyError('500', 'fail') update_document_share_url(self.doc.pk) eq_(self.doc.share_url, None)