# Path: test/common.py
# def generate_handler_func(route_func, path, name=None):
#     if name is None:
#         name = route_func.__name__ + '_' + {'/': 'index'}[path]
#     f = generate_route_func(name)
#     return route_func(path)(f)


from collections import namedtuple
from .common import generate_handler_func
import pytest
import tornado.testing
import rw.scope
import rw.http
import rw.routing
import rw.template


## TODO
# def test_duplicated_functions():
#     m = rw.http.Module('test')
#
#     @m.get('/')
#     def foo():
#         pass
#
#     with pytest.raises(rw.routing.DuplicateError):
#         @m.get('/something_else')
#         def foo():
#             pass


class HTTPTest(tornado.testing.AsyncTestCase):
    def test_http(self):
        self.scope = rw.scope.Scope()
        with self.scope():
            self.scope.activate(rw.routing.plugin, callback=self.http)
        self.wait()

    def http(self, _):
        sub = rw.http.Module('sub')
        sub_index = generate_handler_func(sub.get, '/')
        sub_fun = generate_handler_func(sub.get, '/fun', 'fun')
        sub_posts = generate_handler_func(sub.get, '/<user_name:str>/posts', 'sub_posts')

        subsub = rw.http.Module('subsub')

# Path: test/common.py
# def generate_handler_func(route_func, path, name=None):
#     if name is None:
#         name = route_func.__name__ + '_' + {'/': 'index'}[path]
#     f = generate_route_func(name)
#     return route_func(path)(f)


# Path: test/test_http.py
from collections import namedtuple
from .common import generate_handler_func
import pytest
import tornado.testing
import rw.scope
import rw.http
import rw.routing
import rw.template



## TODO
# def test_duplicated_functions():
#     m = rw.http.Module('test')
#
#     @m.get('/')
#     def foo():
#         pass
#
#     with pytest.raises(rw.routing.DuplicateError):
#         @m.get('/something_else')
#         def foo():
#             pass


class HTTPTest(tornado.testing.AsyncTestCase):
    def test_http(self):
        self.scope = rw.scope.Scope()
        with self.scope():
            self.scope.activate(rw.routing.plugin, callback=self.http)
        self.wait()

    def http(self, _):
        sub = rw.http.Module('sub')
        sub_index = generate_handler_func(sub.get, '/')
        sub_fun = generate_handler_func(sub.get, '/fun', 'fun')
        sub_posts = generate_handler_func(sub.get, '/<user_name:str>/posts', 'sub_posts')

        subsub = rw.http.Module('subsub')

        subsub_index = generate_handler_func(subsub.get, '/')