Skip to content

Commit ff79415

Browse files
committed
Implemented testing script. Disable chilpit expand, needs fixing.
1 parent 492103e commit ff79415

File tree

5 files changed

+70
-10
lines changed

5 files changed

+70
-10
lines changed

common.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ def http_error_302(self, req, fp, code, smg, headers):
5757
"""Base interface that all services implement."""
5858
class Service(object):
5959

60+
tested = False
61+
62+
def _test(self):
63+
self.tested = True
64+
65+
# first shrink an url
66+
turl = self.shrink('http://test.com')
67+
68+
# second expand url and verify
69+
if self.expand(turl) == 'http://test.com':
70+
return True
71+
else:
72+
return False
73+
6074
def shrink(self, bigurl):
6175
"""Take a big url and make it smaller"""
6276
return None

compile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def compile_shorty(services):
8484
print 'Usage: compile.py <services>'
8585
print ' services -- names of the services to include in compiled module'
8686
print 'Example: compile.py sandbox tinyurl bitly'
87+
sys.exit(1)
8788

8889
# get list of services to compile
8990
if sys.argv[1] == '--all':

services/chilpit.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ def shrink(self, bigurl):
99
resp = request('http://chilp.it/api.php', {'url': bigurl})
1010
url = resp.read()
1111
if url.startswith('http://'):
12-
return url
12+
return url.strip()
1313
else:
1414
raise ShortyError(url)
1515

1616
def expand(self, tinyurl):
17-
turl = urlparse(tinyurl)
17+
Service.expand(self, tinyurl)
18+
19+
# needs fixing
20+
"""turl = urlparse(tinyurl)
1821
if turl.netloc.lstrip('www.') != 'chilp.it':
1922
raise ShortyError('Not a chilp.it url')
20-
resp = request('http://p.chilp.it/api.php?' + turl.path.strip('/'))
23+
resp = request('http://p.chilp.it/api.php?' + turl.query)
2124
url = resp.read()
2225
if url.startswith('http://'):
23-
return url
26+
return url.strip('\n\r')
2427
else:
25-
raise ShortyError(url)
28+
raise ShortyError(url)"""
2629

2730
# get click stats of the tinyurl
2831
def stats(self, tinyurl):

shorty.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ def http_error_302(self, req, fp, code, smg, headers):
102102
"""Base interface that all services implement."""
103103
class Service(object):
104104

105+
tested = False
106+
107+
def _test(self):
108+
self.tested = True
109+
110+
# first shrink an url
111+
turl = self.shrink('http://test.com')
112+
113+
# second expand url and verify
114+
if self.expand(turl) == 'http://test.com':
115+
return True
116+
else:
117+
return False
118+
105119
def shrink(self, bigurl):
106120
"""Take a big url and make it smaller"""
107121
return None
@@ -433,20 +447,23 @@ def shrink(self, bigurl):
433447
resp = request('http://chilp.it/api.php', {'url': bigurl})
434448
url = resp.read()
435449
if url.startswith('http://'):
436-
return url
450+
return url.strip()
437451
else:
438452
raise ShortyError(url)
439453

440454
def expand(self, tinyurl):
441-
turl = urlparse(tinyurl)
455+
Service.expand(self, tinyurl)
456+
457+
# needs fixing
458+
"""turl = urlparse(tinyurl)
442459
if turl.netloc.lstrip('www.') != 'chilp.it':
443460
raise ShortyError('Not a chilp.it url')
444-
resp = request('http://p.chilp.it/api.php?' + turl.path.strip('/'))
461+
resp = request('http://p.chilp.it/api.php?' + turl.query)
445462
url = resp.read()
446463
if url.startswith('http://'):
447-
return url
464+
return url.strip('\n\r')
448465
else:
449-
raise ShortyError(url)
466+
raise ShortyError(url)"""
450467

451468
# get click stats of the tinyurl
452469
def stats(self, tinyurl):

test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Shorty
2+
# Copyright 2009 Joshua Roesslein
3+
# See LICENSE
4+
5+
import shorty
6+
7+
print 'Running shorty tests...'
8+
9+
passes = 0
10+
fails = 0
11+
12+
for name, service in shorty.services.items():
13+
14+
try:
15+
if service.tested:
16+
# skip services with aliases
17+
continue
18+
service._test()
19+
passes += 1
20+
print 'PASS: <%s>' % name
21+
except shorty.ShortyError, e:
22+
fails += 1
23+
print 'FAIL: <%s> %s' % (name, e)
24+
25+
print 'PASSES: %i FAILS: %i' % (passes, fails)

0 commit comments

Comments
 (0)