Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff79415

Browse files
committed
Implemented testing script. Disable chilpit expand, needs fixing.
1 parent492103e commitff79415

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
classService(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+
ifself.expand(turl)=='http://test.com':
70+
returnTrue
71+
else:
72+
returnFalse
73+
6074
defshrink(self,bigurl):
6175
"""Take a big url and make it smaller"""
6276
returnNone

‎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
ifsys.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
ifurl.startswith('http://'):
12-
returnurl
12+
returnurl.strip()
1313
else:
1414
raiseShortyError(url)
1515

1616
defexpand(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-
returnurl
26+
return url.strip('\n\r')
2427
else:
25-
raiseShortyError(url)
28+
raise ShortyError(url)"""
2629

2730
# get click stats of the tinyurl
2831
defstats(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
classService(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+
ifself.expand(turl)=='http://test.com':
115+
returnTrue
116+
else:
117+
returnFalse
118+
105119
defshrink(self,bigurl):
106120
"""Take a big url and make it smaller"""
107121
returnNone
@@ -433,20 +447,23 @@ def shrink(self, bigurl):
433447
resp=request('http://chilp.it/api.php', {'url':bigurl})
434448
url=resp.read()
435449
ifurl.startswith('http://'):
436-
returnurl
450+
returnurl.strip()
437451
else:
438452
raiseShortyError(url)
439453

440454
defexpand(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-
returnurl
464+
return url.strip('\n\r')
448465
else:
449-
raiseShortyError(url)
466+
raise ShortyError(url)"""
450467

451468
# get click stats of the tinyurl
452469
defstats(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+
importshorty
6+
7+
print'Running shorty tests...'
8+
9+
passes=0
10+
fails=0
11+
12+
forname,serviceinshorty.services.items():
13+
14+
try:
15+
ifservice.tested:
16+
# skip services with aliases
17+
continue
18+
service._test()
19+
passes+=1
20+
print'PASS: <%s>'%name
21+
exceptshorty.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)

[8]ページ先頭

©2009-2025 Movatter.jp