This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1132517 - Move bitly shortening to use official API library.
This also adds year long caching for the result.
- Loading branch information
Showing
7 changed files
with
58 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import test_utils | ||
from nose.tools import eq_ | ||
|
||
import bitly_api | ||
from django.conf import settings | ||
import mock | ||
from nose.tools import eq_, ok_ | ||
import test_utils | ||
|
||
from ..helpers import tag_description | ||
from kuma.core.cache import memcache | ||
from ..helpers import tag_description, bitly_shorten, bitly | ||
|
||
|
||
class HelperTestCase(test_utils.TestCase): | ||
|
||
def test_tag_description_no_description(self): | ||
settings.TAG_DESCRIPTIONS = {"tag_name": "test_tag", | ||
"title": "Testing tag without description"} | ||
settings.TAG_DESCRIPTIONS = { | ||
"tag_name": "test_tag", | ||
"title": "Testing tag without description", | ||
} | ||
description = tag_description("test_tag") | ||
eq_("test_tag", description) | ||
|
||
def test_tag_description_challenge_none(self): | ||
tag = 'challenge:none' | ||
description = tag_description(tag) | ||
eq_('Removed from Derby', description) | ||
|
||
@mock.patch.object(memcache, 'set') # prevent caching | ||
@mock.patch.object(bitly, 'shorten') | ||
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,3 +97,4 @@ src/py-amqp | |
src/django-celery | ||
src/django-banish | ||
src/django-honeypot | ||
src/bitly-api-python |
Submodule bitly-api-python
added at
8f51e7