Skip to content

Commit

Permalink
Modify tests as required
Browse files Browse the repository at this point in the history
  • Loading branch information
hfaran committed Feb 16, 2014
1 parent 81c56c6 commit 1ffc41d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demos/helloworld/helloworld/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get(self):
return "Hello world!"


class GreetingHandler(APIHandler):
class Greeting(APIHandler):

apid = {
"get": {
Expand Down
23 changes: 15 additions & 8 deletions tornado_json/test/test_tornado_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ class TestRoutes(TestTornadoJSONBase):
def test_get_routes(self):
"""Tests routes.get_routes"""
assert routes.get_routes(
helloworld) == [("/api/helloworld",
helloworld.api.HelloWorldHandler)]
helloworld) == [
("/api/helloworld", helloworld.api.HelloWorldHandler),
("/api/greeting/(?P<name>[a-zA-Z0-9_]+)/?$",
helloworld.api.Greeting)
]

def test_gen_submodule_names(self):
"""Tests routes.gen_submodule_names"""
Expand All @@ -56,8 +59,11 @@ def test_gen_submodule_names(self):
def test_get_module_routes(self):
"""Tests routes.get_module_routes"""
assert routes.get_module_routes(
'helloworld.api') == [("/api/helloworld",
helloworld.api.HelloWorldHandler)]
'helloworld.api') == [
("/api/helloworld", helloworld.api.HelloWorldHandler),
("/api/greeting/(?P<name>[a-zA-Z0-9_]+)/?$",
helloworld.api.Greeting)
]


class TestUtils(TestTornadoJSONBase):
Expand Down Expand Up @@ -126,8 +132,9 @@ class ReasonableHandler(MockRequestHandler):
}

@utils.io_schema
def get(self):
return "I am the handler you are looking for."
def get(self, fname, lname):
return "I am the handler you are looking for, {} {}".format(
fname, lname)

@utils.io_schema
def post(self):
Expand All @@ -140,15 +147,15 @@ def test_io_schema(self):

# Expect a TypeError to be raised because of invalid output
with pytest.raises(TypeError):
th.get()
th.get("Duke", "Flywalker")

# Expect a validation error because of invalid input
with pytest.raises(ValidationError):
th.post()

# Both of these should succeed as the body matches the schema
with pytest.raises(SuccessException):
rh.get()
rh.get("J", "S")
with pytest.raises(SuccessException):
rh.post()

Expand Down

0 comments on commit 1ffc41d

Please sign in to comment.