-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63db301
commit fe99339
Showing
1 changed file
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest | ||
from tiny import tiny | ||
|
||
class TestTinyApp(unittest.TestCase): | ||
"""Base class for testing TinyApp.""" | ||
|
||
def setUp(self): | ||
"""Starts each test with a new, empty TinyApp object and a handler.""" | ||
|
||
self.app = tiny.TinyApp() | ||
self.handler = lambda x: x | ||
|
||
def tearDown(self): | ||
"""Ends each test by destroying the TinyApp object.""" | ||
|
||
del(self.app) | ||
del(self.handler) | ||
|
||
def test_app_init(self): | ||
"""Tests that each app is initialized with an empty routes dict.""" | ||
|
||
self.assertEqual(self.app.ROUTES, {}) | ||
|
||
def test_add_route(self): | ||
"""Tests that adding a route actually adds a route to the dictionary.""" | ||
|
||
self.app.add_route('/index', self.handler) | ||
self.assertEqual({'/index': (self.handler, ['GET'])}, self.app.ROUTES) | ||
|
||
def test_route(self): | ||
"""Tests that the route decorator also adds a route to the dictionary.""" | ||
|
||
@self.app.route('/index') | ||
def decorator_handler(): | ||
pass | ||
|
||
self.assertEqual({'/index': (decorator_handler, ['GET'])}, self.app.ROUTES) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |