Beispiel #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('/')
Beispiel #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))
def setup_in_app_context() -> None:
    # pylint: disable=import-outside-toplevel
    from decksite import APP
    with APP.app_context():  # type: ignore
        setup()
Beispiel #5
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()
Beispiel #6
0
def test_goldfish() -> None:
    with APP.app_context():  # type: ignore
        mtggoldfish.scrape(1)
Beispiel #7
0
def test_manual_tappedout() -> None:
    with APP.app_context():  # type: ignore
        tappedout.scrape_url('https://tappedout.net/mtg-decks/60-island/')
 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('/')
Beispiel #9
0
def test_gatherling() -> None:
    with APP.app_context(): # type: ignore
        gatherling.scrape(5)