# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
import os.path
import logging
import datetime
from six import ensure_binary, ensure_str
from six.moves.urllib.parse import urlencode
from tornado.testing import AsyncHTTPTestCase
from tornado.web import create_signed_value
from scrapydd.main import make_app
from scrapydd.config import Config
from scrapydd.models import init_database, Node, session_scope
from scrapydd.models import Project, Spider, SpiderExecutionQueue
from scrapydd.poster.encode import multipart_encode
from scrapydd.schedule import SchedulerManager
from scrapydd.nodes import NodeManager
from scrapydd.workspace import RunnerFactory
from .base import AppTest

LOGGER = logging.getLogger(__name__)

TEST_EGG_FILE = os.path.join(os.path.dirname(__file__),
                             'test_project-1.0-py2.7.egg')


class MainTest(AsyncHTTPTestCase):
    @classmethod
    def setUpClass(cls):
        os.environ['ASYNC_TEST_TIMEOUT'] = '500'
        if os.path.exists('test.db'):
            os.remove('test.db')
        config = Config(values={'database_url': 'sqlite:///test.db'})
        init_database(config)

    def get_app(self):
        config = Config()
        scheduler_manager = SchedulerManager(config=config)
        scheduler_manager.init()