# Path: gargantua/app.py
# class Application(tornado.web.Application):
# 
#     def get_static_url_prefix(self):
#         return '/static/dist/'
# 
#     def __init__(self):
#         settings = {
#             'static_path': str(Path(CWD, 'static', 'dist')),
#             'static_url_prefix': self.get_static_url_prefix(),
#             'template_path': str(Path(CWD, 'html')),
#             'cookie_secret': get_default_config('SECRET_KEY'),
#             'login_url': '/login/',
#             'xsrf_cookies': True,
#             'autoescape': None,
#             'debug': options.debug
#         }
#         handlers = [
#             # ---------------- rss ----------------
#             url(r'^/(rss)/$', PostsHandler, name='post:rss'),
#             # ---------------- old api ----------------
#             url(r'^/(api/posts/.*)/$', PostsHandler, name='api:post'),
#             url(r'^/(api/user/.*)/$', UserHandler, name='api:user:login'),
#             # ---------------- rest api ----------------
#             url(r'^/api/v2/post/category/([a-zA-Z0-9\-_%]+)?/?$', PostCategoriesAPIHandler, name='rest:post_category'),
#             url(r'^/api/v2/post/([a-zA-Z0-9\-_%]+)?/?$', PostAPIHandler, name='rest:post'),
#             url(r'^/api/v2/tweets/([a-zA-Z0-9\-_]+)?/?$', TweetsAPIHandler, name='rest:tweets'),
#             # ---------------- react-router ----------------
#             url(r'/.*', ReactRender, name='root'),
#         ]
#         # handlers.append(('/(.*)', PageNotFound))
#         self.setup_db()
#         if not options.debug:
#             self.setup_mail_handler()
# 
#         super(Application, self).__init__(handlers, **settings)
# 
#     def setup_mail_handler(self):
#         # set mail handler
#         mh = LogMailHandler(mailhost=(options.mail_host, options.mail_port),
#                             fromaddr=options.mail_from_addr,
#                             toaddrs=options.mail_to_addrs,
#                             credentials=(options.mail_username, options.mail_passwd),
#                             subject=options.mail_subject)
#         mh.setFormatter(LogMailFormatter())
#         mh.setLevel(logging.ERROR)
#         logging.getLogger().addHandler(mh)
# 
#     def setup_db(self):
#         logger.debug('connect database at {}:{}'
#                      .format(options.dbhost, options.dbport))
# 
#         model = BaseBlogModel.make_connection(
#             host=options.dbhost,
#             port=options.dbport,
#             db=options.dbname,
#             username=options.dbuser,
#             passwd=options.dbpasswd,
#             )
#         self.conn = model.conn
#         self.db = model.db
#         self.mongo_conn = model.mongo_conn
#         self.mongo_db = model.mongo_db
# 
#         # ensure index
#         # posts
#         # posts_idx = pymongo.IndexModel([('post_name',)], unique=True)
#         # self.mongo_db.posts.create_indexes([posts_idx])
#         self.mongo_db.posts.ensure_index([('post_name', pymongo.ASCENDING)], unique=True)  # PyMongo2.8
#         # users
#         # account_idx = pymongo.IndexModel([('account',)], unique=True)
#         # username_idx = pymongo.IndexModel([('username',)], unique=True)
#         # self.mongo_db.users.create_indexes([account_idx, username_idx])
#         self.mongo_db.users.ensure_index([('account', pymongo.ASCENDING)], unique=True)   # PyMongo2.8
#         self.mongo_db.users.ensure_index([('username', pymongo.ASCENDING)], unique=True)  # PyMongo2.8


from urllib.parse import urlparse
from tornado.testing import AsyncHTTPTestCase
from tornado.ioloop import IOLoop
from tornado.options import options
from gargantua.app import Application




GA_ID = 'UA-65521906-1'


class GargantuaTestCase(AsyncHTTPTestCase):

    def get_app(self):
        options.debug = True

# Path: gargantua/app.py
# class Application(tornado.web.Application):
# 
#     def get_static_url_prefix(self):
#         return '/static/dist/'
# 
#     def __init__(self):
#         settings = {
#             'static_path': str(Path(CWD, 'static', 'dist')),
#             'static_url_prefix': self.get_static_url_prefix(),
#             'template_path': str(Path(CWD, 'html')),
#             'cookie_secret': get_default_config('SECRET_KEY'),
#             'login_url': '/login/',
#             'xsrf_cookies': True,
#             'autoescape': None,
#             'debug': options.debug
#         }
#         handlers = [
#             # ---------------- rss ----------------
#             url(r'^/(rss)/$', PostsHandler, name='post:rss'),
#             # ---------------- old api ----------------
#             url(r'^/(api/posts/.*)/$', PostsHandler, name='api:post'),
#             url(r'^/(api/user/.*)/$', UserHandler, name='api:user:login'),
#             # ---------------- rest api ----------------
#             url(r'^/api/v2/post/category/([a-zA-Z0-9\-_%]+)?/?$', PostCategoriesAPIHandler, name='rest:post_category'),
#             url(r'^/api/v2/post/([a-zA-Z0-9\-_%]+)?/?$', PostAPIHandler, name='rest:post'),
#             url(r'^/api/v2/tweets/([a-zA-Z0-9\-_]+)?/?$', TweetsAPIHandler, name='rest:tweets'),
#             # ---------------- react-router ----------------
#             url(r'/.*', ReactRender, name='root'),
#         ]
#         # handlers.append(('/(.*)', PageNotFound))
#         self.setup_db()
#         if not options.debug:
#             self.setup_mail_handler()
# 
#         super(Application, self).__init__(handlers, **settings)
# 
#     def setup_mail_handler(self):
#         # set mail handler
#         mh = LogMailHandler(mailhost=(options.mail_host, options.mail_port),
#                             fromaddr=options.mail_from_addr,
#                             toaddrs=options.mail_to_addrs,
#                             credentials=(options.mail_username, options.mail_passwd),
#                             subject=options.mail_subject)
#         mh.setFormatter(LogMailFormatter())
#         mh.setLevel(logging.ERROR)
#         logging.getLogger().addHandler(mh)
# 
#     def setup_db(self):
#         logger.debug('connect database at {}:{}'
#                      .format(options.dbhost, options.dbport))
# 
#         model = BaseBlogModel.make_connection(
#             host=options.dbhost,
#             port=options.dbport,
#             db=options.dbname,
#             username=options.dbuser,
#             passwd=options.dbpasswd,
#             )
#         self.conn = model.conn
#         self.db = model.db
#         self.mongo_conn = model.mongo_conn
#         self.mongo_db = model.mongo_db
# 
#         # ensure index
#         # posts
#         # posts_idx = pymongo.IndexModel([('post_name',)], unique=True)
#         # self.mongo_db.posts.create_indexes([posts_idx])
#         self.mongo_db.posts.ensure_index([('post_name', pymongo.ASCENDING)], unique=True)  # PyMongo2.8
#         # users
#         # account_idx = pymongo.IndexModel([('account',)], unique=True)
#         # username_idx = pymongo.IndexModel([('username',)], unique=True)
#         # self.mongo_db.users.create_indexes([account_idx, username_idx])
#         self.mongo_db.users.ensure_index([('account', pymongo.ASCENDING)], unique=True)   # PyMongo2.8
#         self.mongo_db.users.ensure_index([('username', pymongo.ASCENDING)], unique=True)  # PyMongo2.8


# Path: tests/test_blog_page.py
from urllib.parse import urlparse
from tornado.testing import AsyncHTTPTestCase
from tornado.ioloop import IOLoop
from tornado.options import options
from gargantua.app import Application





GA_ID = 'UA-65521906-1'


class GargantuaTestCase(AsyncHTTPTestCase):

    def get_app(self):
        options.debug = True

        options.dbhost = 'localhost'