forked from bottlepy/bottle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized test setup and minor changes
- Loading branch information
Showing
13 changed files
with
85 additions
and
176 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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
import bottle | ||
|
||
class TestRouter(unittest.TestCase): | ||
def setUp(self): | ||
self.r = r = bottle.Router() | ||
|
||
def testBasic(self): | ||
add = self.r.add | ||
match = self.r.match | ||
add('/static', 'static') | ||
self.assertEqual(('static', None), match('/static')) | ||
add('/\\:its/:#.+#/:test/:name#[a-z]+#/', 'handler') | ||
self.assertEqual(('handler', {'test': 'cruel', 'name': 'world'}), match('/:its/a/cruel/world/')) | ||
add('/:test', 'notail') | ||
self.assertEqual(('notail', {'test': 'test'}), match('/test')) | ||
add(':test/', 'nohead') | ||
self.assertEqual(('nohead', {'test': 'test'}), match('test/')) | ||
add(':test', 'fullmatch') | ||
self.assertEqual(('fullmatch', {'test': 'test'}), match('test')) | ||
add('/:#anon#/match', 'anon') | ||
self.assertEqual(('anon', None), match('/anon/match')) | ||
self.assertEqual((None, None), match('//no/m/at/ch/')) | ||
|
||
def testErrorInPattern(self): | ||
self.assertRaises(bottle.RouteSyntaxError, self.r.add, '/:bug#(#/', 'buggy') | ||
|
||
def testBuild(self): | ||
add = self.r.add | ||
build = self.r.build | ||
add('/:test/:name#[a-z]+#/', 'handler', name='testroute') | ||
add('/anon/:#.#', 'handler', name='anonroute') | ||
url = build('testroute', test='hello', name='world') | ||
self.assertEqual('/hello/world/', url) | ||
self.assertRaises(bottle.RouteBuildError, build, 'test') | ||
# RouteBuildError: No route found with name 'test'. | ||
self.assertRaises(bottle.RouteBuildError, build, 'testroute') | ||
# RouteBuildError: Missing parameter 'test' in route 'testroute' | ||
self.assertRaises(bottle.RouteBuildError, build, 'testroute', test='hello', name='1234') | ||
# RouteBuildError: Parameter 'name' does not match pattern for route 'testroute': '[a-z]+' | ||
self.assertRaises(bottle.RouteBuildError, build, 'anonroute') | ||
# RouteBuildError: Anonymous pattern found. Can't generate the route 'anonroute'. | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
import bottle | ||
|
||
class TestSecureCookies(unittest.TestCase): | ||
def setUp(self): | ||
self.data = dict(a=5, b=u'unicode', c=[1,2,3,4,'5']) | ||
self.key = u'secret'.encode('utf8') | ||
|
||
def testDeEncode(self): | ||
cookie = bottle.cookie_encode(self.data, self.key) | ||
self.assertEqual('!RidFXtwOzjhv4wGg/P2gTA==?gAJ9cQEoVQFhSwVVAWNdcQIoSwFLAksDSwRVATVlVQFiWAcAAAB1bmljb2RlcQN1Lg==', cookie) | ||
decoded = bottle.cookie_decode(cookie, self.key) | ||
self.assertEqual(self.data, decoded) | ||
|
||
def testIsEncoded(self): | ||
cookie = bottle.cookie_encode(self.data, self.key) | ||
self.assertTrue(bottle.cookie_is_encoded(cookie)) | ||
self.assertFalse(bottle.cookie_is_encoded('some string')) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
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