示例#1
0
def test_tappedout() -> None:
    prev = APP.config['SERVER_NAME']
    APP.config['SERVER_NAME'] = configuration.server_name()
    with APP.app_context():  # type: ignore
        # pylint: disable=no-member
        tappedout.ad_hoc()
    APP.config['SERVER_NAME'] = prev
 def test_trailing_slashes(self) -> None:
     with APP.app_context():
         for rule in self.tester.url_map.iter_rules():
             if 'GET' in rule.methods:
                 url = rule.rule
                 if not url.startswith('/api/') and rule.endpoint not in ['favicon', 'robots_txt']:
                     assert url.endswith('/')
示例#3
0
def setup() -> None:
    from decksite import APP
    with APP.app_context():
        db().execute('CREATE TABLE IF NOT EXISTS db_version (version INTEGER UNIQUE NOT NULL)')
        version = db_version()
        patches = os.listdir('decksite/sql')
        patches.sort(key=lambda n: int(n.split('.')[0]))
        for fn in patches:
            path = os.path.join('decksite/sql', fn)
            n = int(fn.split('.')[0])
            if version < n:
                logger.warning('Patching database to v{0}'.format(n))
                fh = open(path, 'r')
                sql = fh.read()
                for stmt in sql.split(';'):
                    if stmt.strip() != '':
                        db().execute(stmt)
                fh.close()
                db().execute('INSERT INTO db_version (version) VALUES ({n})'.format(n=n))
示例#4
0
def setup_in_app_context() -> None:
    # pylint: disable=import-outside-toplevel
    from decksite import APP
    with APP.app_context():  # type: ignore
        setup()
示例#5
0
def init(debug: bool = True, port: Optional[int] = None) -> None:
    """This method is only called when initializing the dev server.  uwsgi (prod) doesn't call this method"""
    APP.logger.setLevel(logging.INFO)  # pylint: disable=no-member,no-name-in-module
    APP.run(host='0.0.0.0', debug=debug, port=port)
示例#6
0
            'Aether Hub', 'Siege Rhino', 'Greater Good', "Mind's Desire",
            "God-Pharaoh's Gift", 'Kiln Fiend', 'Akroma, Angel of Wrath',
            'Reanimate'
        ]
        background = 'Rofellos, Llanowar Emissary'

    path = image_fetcher.generate_banner(cardnames, background)
    return send_file(os.path.abspath(path))


@APP.before_request
def before_request() -> None:
    g.p = perf.start()


@APP.teardown_request
def teardown_request(response: Response) -> Response:
    if g.get('p') is not None:
        perf.check(g.p, 'slow_page', request.path, 'decksite')
    db().close()
    return response


def init(debug: bool = True, port: Optional[int] = None) -> None:
    """This method is only called when initializing the dev server.  uwsgi (prod) doesn't call this method"""
    APP.logger.setLevel(logging.INFO)  # pylint: disable=no-member,no-name-in-module
    APP.run(host='0.0.0.0', debug=debug, port=port)


APP.register_blueprint(SEASONS)
示例#7
0
def init():
    # This makes sure that the method decorators are called.
    import decksite.api as _  # pylint: disable=unused-import
    APP.config['SECRET_KEY'] = configuration.get('oauth2_client_secret')
    APP.run(host='0.0.0.0', debug=True)
def init(debug=True, port=None):
    """This method is only called when initializing the dev server.  uwsgi (prod) doesn't call this method"""
    APP.run(host='0.0.0.0', debug=debug, port=port)
示例#9
0
def setup():
    db().execute(
        'CREATE TABLE IF NOT EXISTS db_version (version INTEGER UNIQUE NOT NULL)'
    )
    version = db_version()
    patches = os.listdir('decksite/sql')
    patches.sort(key=lambda n: int(n.split('.')[0]))
    for fn in patches:
        path = os.path.join('decksite/sql', fn)
        n = int(fn.split('.')[0])
        if version < n:
            print("Patching database to v{0}".format(n))
            fh = open(path, 'r')
            sql = fh.read()
            for stmt in sql.split(';'):
                if stmt.strip() != "":
                    db().execute(stmt)
            fh.close()
            db().execute(
                "INSERT INTO db_version (version) VALUES ({n})".format(n=n))


def db_version() -> int:
    return db().value(
        'SELECT version FROM db_version ORDER BY version DESC LIMIT 1', [], 0)


with APP.app_context():
    setup()
示例#10
0
def test_goldfish() -> None:
    with APP.app_context():  # type: ignore
        mtggoldfish.scrape(1)
示例#11
0
def test_manual_tappedout() -> None:
    with APP.app_context():  # type: ignore
        tappedout.scrape_url('https://tappedout.net/mtg-decks/60-island/')
示例#12
0
 def test_api_no_trailing_slashes(self) -> None:
     with APP.app_context():
         for rule in self.tester.url_map.iter_rules():
             url = rule.rule
             if url.startswith('/api/'):
                 assert not url.endswith('/')
示例#13
0
def test_gatherling() -> None:
    with APP.app_context(): # type: ignore
        gatherling.scrape(5)
示例#14
0
def init(debug: bool = True, port: Optional[int] = None) -> None:
    """This method is only called when initializing the dev server.  uwsgi (prod) doesn't call this method"""
    APP.logger.setLevel(logging.INFO)  # pylint: disable=no-member,no-name-in-module
    APP.config[
        'SESSION_COOKIE_SECURE'] = False  # Allow cookies over HTTP when running locally.
    APP.run(host='0.0.0.0', debug=debug, port=port)