# Path: gunstar/app.py
# class Application(object):
# 
#     def __init__(self, routes=None, config=None):
#         # set router
#         self.router = Router(routes)
# 
#         # set config
#         self.config = Config()
#         self.config.load_from_object(DefaultConfig)
#         self.config.load_from_object(config)
# 
#         # add static dir route
#         self.set_static_route()
# 
#         # handlers for 404 and 500
#         self.handler404 = import_object(
#             self.config.get('HANDLER_FOR_404')
#         )
#         self.handler500 = import_object(
#             self.config.get('HANDLER_FOR_500')
#         )
# 
#     def set_static_route(self):
#         # add static dir route
#         self.static_root = self.config.get('STATIC_ROOT')
#         self.static_path = self.config.get('STATIC_PATH')
#         if self.static_root and self.static_path:
#             self.router.add_route(
#                 self.static_path + '{file:path}',
#                 DirectoryApp,
#                 'static'
#             )
# 
#     def load_config(self, config):
#         self.config.load_from_object(config)
#         self.set_static_route()
# 
#     def add_route(self, pattern, handler, name):
#         self.router.add_route(pattern, handler, name)
# 
#     def __call__(self, environ, start_response):
#         self.request = Request(environ)
#         request_started_signal.send(self, request=self.request)
#         self.response = Response()
#         path = self.request.path_info
#         route = self.router.find_route(path)
#         if route:
#             try:
#                 func = route.resolve_func()
#                 # check is route for static files
#                 if route.name == 'static':
#                     static_handler = func(self.static_root)
#                     self.request.path_info = self.request.path_info.replace(
#                         self.static_path, ''
#                     )
#                     resp = self.request.get_response(static_handler)
#                     return resp(environ, start_response)
#                 args = route.get_args(path)
#                 handler = func(self, self.request, self.response)
#                 handler.dispatch(*args)
#                 request_finished_signal.send(self, response=handler.response)
#                 return handler.response(environ, start_response)
#             except Exception:
#                 exc_info = sys.exc_info()
#                 request_exception_signal.send(
#                     self, request=self.request, exc_info=exc_info
#                 )
#                 handler_500 = self.handler500(
#                     self, self.request, self.response
#                 )
#                 handler_500.dispatch(exc_info)
#                 return handler_500.response(environ, start_response)
#         else:
#             handler_404 = self.handler404(self, self.request, self.response)
#             handler_404.dispatch()
#             return handler_404.response(environ, start_response)
# 
# Path: gunstar/routing.py
# class Router(object):
# 
#     routes = ()
# 
#     def __init__(self, routes=None):
#         if isinstance(routes, tuple):
#             for route in routes:
#                 self.add_route(route[0], route[1], route[2])
# 
#     def add_route(self, pattern, func, name):
#         self.routes += (
#             Route(pattern, func, name),
#         )
# 
#     def find_route(self, path):
#         for route in self.routes:
#             match = re.search(route.regex_pattern, path)
#             if match:
#                 return route
#         return None
# 
#     def find_route_by_name(self, name):
#         for route in self.routes:
#             if route.name == name:
#                 return route
#         return None
# 
# Path: gunstar/config.py
# class Config(dict):
# 
#     def load_from_object(self, obj):
#         if isinstance(obj, six.string_types):
#             obj = import_object(obj)
#         for key in dir(obj):
#             if key.isupper():
#                 self[key] = getattr(obj, key)
# 
# Path: gunstar/http.py
# PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
# GUNSTAR_TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')
# class RequestHandler(object):
# class NotFoundHandler(RequestHandler):
# class ErrorHandler(RequestHandler):
#     def __init__(self, app, request, response):
#     def before_dispatch(self):
#     def dispatch(self, *args, **kwargs):
#     def after_dispatch(self):
#     def abort(self, code, message=None):
#     def redirect(self, redirect_url, permanent=False, status_code=302):
#     def get_template_globals(self):
#     def get_template_filters(self):
#     def create_template_env(self):
#     def render_template(self, template_name, **kwargs):
#     def reverse_route(self, name, *args):
#     def get(self):
#     def get(self, exc_info):


import unittest
import os
from gunstar.app import Application
from gunstar.routing import Router
from gunstar.config import Config
from gunstar.http import Request, Response
            isinstance(self.app.router, Router)
        )

        self.assertTrue(
            isinstance(self.app.config, Config)
        )

    def load_config(self):
        self.app.load_config(TestConfig)
        self.assertTrue('KEY1' in self.app.config)
        self.assertFalse('key2' in self.app.config)

    def test_add_route(self):
        self.app.add_route('/test/', 'handlers.TestHandler', 'test')
        self.assertTrue(self.app.router.find_route('/test/'))

    def test_call(self):
        self.app.load_config(TestConfig)
        req = Request.blank('/article?id=1')

        resp = req.get_response(self.app)
        self.assertTrue(isinstance(resp, Response))
        self.assertEqual(resp.status_code, 404)
        self.assertTrue('Not Found /article' in resp.text)

    def test_static_call(self):
        self.app.load_config(TestConfig)
        req = Request.blank('/static/readme.txt')

        resp = req.get_response(self.app)

# Path: gunstar/app.py
# class Application(object):
# 
#     def __init__(self, routes=None, config=None):
#         # set router
#         self.router = Router(routes)
# 
#         # set config
#         self.config = Config()
#         self.config.load_from_object(DefaultConfig)
#         self.config.load_from_object(config)
# 
#         # add static dir route
#         self.set_static_route()
# 
#         # handlers for 404 and 500
#         self.handler404 = import_object(
#             self.config.get('HANDLER_FOR_404')
#         )
#         self.handler500 = import_object(
#             self.config.get('HANDLER_FOR_500')
#         )
# 
#     def set_static_route(self):
#         # add static dir route
#         self.static_root = self.config.get('STATIC_ROOT')
#         self.static_path = self.config.get('STATIC_PATH')
#         if self.static_root and self.static_path:
#             self.router.add_route(
#                 self.static_path + '{file:path}',
#                 DirectoryApp,
#                 'static'
#             )
# 
#     def load_config(self, config):
#         self.config.load_from_object(config)
#         self.set_static_route()
# 
#     def add_route(self, pattern, handler, name):
#         self.router.add_route(pattern, handler, name)
# 
#     def __call__(self, environ, start_response):
#         self.request = Request(environ)
#         request_started_signal.send(self, request=self.request)
#         self.response = Response()
#         path = self.request.path_info
#         route = self.router.find_route(path)
#         if route:
#             try:
#                 func = route.resolve_func()
#                 # check is route for static files
#                 if route.name == 'static':
#                     static_handler = func(self.static_root)
#                     self.request.path_info = self.request.path_info.replace(
#                         self.static_path, ''
#                     )
#                     resp = self.request.get_response(static_handler)
#                     return resp(environ, start_response)
#                 args = route.get_args(path)
#                 handler = func(self, self.request, self.response)
#                 handler.dispatch(*args)
#                 request_finished_signal.send(self, response=handler.response)
#                 return handler.response(environ, start_response)
#             except Exception:
#                 exc_info = sys.exc_info()
#                 request_exception_signal.send(
#                     self, request=self.request, exc_info=exc_info
#                 )
#                 handler_500 = self.handler500(
#                     self, self.request, self.response
#                 )
#                 handler_500.dispatch(exc_info)
#                 return handler_500.response(environ, start_response)
#         else:
#             handler_404 = self.handler404(self, self.request, self.response)
#             handler_404.dispatch()
#             return handler_404.response(environ, start_response)
# 
# Path: gunstar/routing.py
# class Router(object):
# 
#     routes = ()
# 
#     def __init__(self, routes=None):
#         if isinstance(routes, tuple):
#             for route in routes:
#                 self.add_route(route[0], route[1], route[2])
# 
#     def add_route(self, pattern, func, name):
#         self.routes += (
#             Route(pattern, func, name),
#         )
# 
#     def find_route(self, path):
#         for route in self.routes:
#             match = re.search(route.regex_pattern, path)
#             if match:
#                 return route
#         return None
# 
#     def find_route_by_name(self, name):
#         for route in self.routes:
#             if route.name == name:
#                 return route
#         return None
# 
# Path: gunstar/config.py
# class Config(dict):
# 
#     def load_from_object(self, obj):
#         if isinstance(obj, six.string_types):
#             obj = import_object(obj)
#         for key in dir(obj):
#             if key.isupper():
#                 self[key] = getattr(obj, key)
# 
# Path: gunstar/http.py
# PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
# GUNSTAR_TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')
# class RequestHandler(object):
# class NotFoundHandler(RequestHandler):
# class ErrorHandler(RequestHandler):
#     def __init__(self, app, request, response):
#     def before_dispatch(self):
#     def dispatch(self, *args, **kwargs):
#     def after_dispatch(self):
#     def abort(self, code, message=None):
#     def redirect(self, redirect_url, permanent=False, status_code=302):
#     def get_template_globals(self):
#     def get_template_filters(self):
#     def create_template_env(self):
#     def render_template(self, template_name, **kwargs):
#     def reverse_route(self, name, *args):
#     def get(self):
#     def get(self, exc_info):


# Path: tests/test_app.py
import unittest
import os
from gunstar.app import Application
from gunstar.routing import Router
from gunstar.config import Config
from gunstar.http import Request, Response

            isinstance(self.app.router, Router)
        )

        self.assertTrue(
            isinstance(self.app.config, Config)
        )

    def load_config(self):
        self.app.load_config(TestConfig)
        self.assertTrue('KEY1' in self.app.config)
        self.assertFalse('key2' in self.app.config)

    def test_add_route(self):
        self.app.add_route('/test/', 'handlers.TestHandler', 'test')
        self.assertTrue(self.app.router.find_route('/test/'))

    def test_call(self):
        self.app.load_config(TestConfig)
        req = Request.blank('/article?id=1')

        resp = req.get_response(self.app)
        self.assertTrue(isinstance(resp, Response))
        self.assertEqual(resp.status_code, 404)
        self.assertTrue('Not Found /article' in resp.text)

    def test_static_call(self):
        self.app.load_config(TestConfig)
        req = Request.blank('/static/readme.txt')

        resp = req.get_response(self.app)

        self.assertTrue(isinstance(resp, Response))