Skip to content

Commit 748e0a9

Browse files
author
Claudio
committed
url shortening first tests
1 parent f8f7865 commit 748e0a9

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.svn
2-
*.pyc
2+
*.pyc
3+
.coverage

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test: clean
2+
@nosetests --verbose --with-coverage --cover-package=bitly -sd
3+
clean:
4+
@find . -name "*.pyc" -delete

test/test_shortening_urls.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
#!/usr/bin/env python
22
#-*- coding:utf-8 -*-
33

4+
from nose.tools import assert_raises
5+
46
import bitly
57

68
def test_urls_shortening_scenario():
79

810
api = bitly.Api(login='jcfigueiredo', apikey='R_1cf5dc0fa14c2df34261fb620bd256aa')
11+
yield should_raise_when_an_invalid_credential_is_provided
12+
yield should_have_an_API_authenticated_by_my_credentials, api
13+
yield should_shorten_an_url_consistently_when_a_single_string_urls_is_provided, api
14+
yield should_shorten_many_urls_consistently_when_a_list_of_urls_is_provided, api
15+
16+
def should_raise_when_an_invalid_credential_is_provided():
17+
api = bitly.Api(login='inexistent_login', apikey='or_invalid_key')
18+
assert_raises(bitly.BitlyError, api.shorten, 'http://anylong.url')
19+
20+
def should_have_an_API_authenticated_by_my_credentials(api):
21+
assert api, 'Should have a valid API'
22+
23+
def should_shorten_an_url_consistently_when_a_single_string_urls_is_provided(api):
24+
url_to_be_shortened = 'http://globoesporte.globo.com/motor/formula-1/noticia/2010/10/apos-maus-resultados-ferrari-reforca-apoio-massa-no-fim-da-temporada.html'
25+
expected_url = 'http://bit.ly/9n93fw'
26+
27+
shortened_url = api.shorten(longURLs=url_to_be_shortened)
28+
29+
assert shortened_url == expected_url, 'The shortened version of %s url should\'ve been %s but was %s' % (url_to_be_shortened, expected_url, shortened_url)
30+
31+
def should_shorten_many_urls_consistently_when_a_list_of_urls_is_provided(api):
32+
urls_to_be_shortened = [ 'http://globoesporte.globo.com/motor/formula-1/noticia/2010/10/apos-maus-resultados-ferrari-reforca-apoio-massa-no-fim-da-temporada.html'
33+
,
34+
'http://globoesporte.globo.com/basquete/noticia/2010/10/leandrinho-faz-19-pontos-na-vitoria-do-toronto-sobre-o-philadelphia.html'
35+
]
36+
37+
expected_urls = ['http://bit.ly/9n93fw','http://bit.ly/aprECg']
938

10-
i_have_an_API_validated_by_my_credentials(api)
39+
shortened_urls = api.shorten(longURLs=urls_to_be_shortened)
1140

12-
def i_have_an_API_validated_by_my_credentials(api):
13-
assert api, 'Should have a valid API'
41+
for expected_url in expected_urls:
42+
assert expected_url in shortened_urls, 'The list os shortened urls should contain %s but it wasn\'t found in %s' % (expected_url, shortened_urls)

0 commit comments

Comments
 (0)