Beispiel #1
0
def test_create_app_dict():
    app = create_app(TEST_CONFIG_B=789)
    assert not app.testing
    expected = dict(
        TEST_CONFIG_A="abc",
        TEST_CONFIG_B=789,
    )
    assert expected.items() <= app.config.items()
Beispiel #2
0
def app():
    config_path = Path(SAMPLE_DIR, "config.py")
    database_uri = "sqlite:///:memory:"
    app = create_app(config_path=config_path,
                     SQLALCHEMY_DATABASE_URI=database_uri)
    with app.app_context():
        define_tables()
    yield app
Beispiel #3
0
def test_no_error_in_create_app():
    """Assert an error does not occur in create_app() when tables are not defined"""
    config_path = Path(SAMPLE_DIR, "config.py")
    kwargs = dict(
        SQLALCHEMY_DATABASE_URI="sqlite:///:memory:",
        ACONDBS_OWNERS_GITHUB_LOGINS="octocat,dojocat",
    )
    app = create_app(config_path, **kwargs)  # noqa: F841
Beispiel #4
0
def app():
    database_uri ="sqlite:///:memory:"
    csvdir = os.path.join(SAMPLE_DIR, 'csv')
    app = create_app(SQLALCHEMY_DATABASE_URI=database_uri)
    with app.app_context():
        define_tables()
        import_tables_from_csv_files(csvdir)
    yield app
Beispiel #5
0
def test_create_app_config_file_and_dict(config_path):
    app = create_app(config_path, TEST_CONFIG_B=789)
    assert not app.testing
    expected = dict(
        TEST_CONFIG_A="abc",
        TEST_CONFIG_B=789,
        TEST_CONFIG_C=False,
    )
    assert expected.items() <= app.config.items()
Beispiel #6
0
def create_db_with_csv_files():
    """create a test DB, load data from CSV files"""
    config_path = Path(SAMPLE_DIR, "config.py")
    csvdir = Path(SAMPLE_DIR, "csv")
    app = create_app(config_path=config_path)
    with app.app_context():
        define_tables()
        import_tables_from_csv_files(csvdir)
    yield
    database_path = Path(SAMPLE_DIR, "product.sqlite3")
    database_path.unlink()
Beispiel #7
0
def test_add_owners_to_db_as_admins(kwargs, expected, tmpdir_factory):
    config_path = Path(SAMPLE_DIR, "config.py")

    # use a file because, with memory, a DB will be recreated in the
    # second create_app().
    tmpdir = str(tmpdir_factory.mktemp("models"))
    tmp_database_path = Path(tmpdir, "product.sqlite3")
    kwargs.update(
        dict(SQLALCHEMY_DATABASE_URI=f"sqlite:///{tmp_database_path}"))

    # define tables and add a admin
    app_ = create_app(config_path, **kwargs)
    with app_.app_context():
        define_tables()

        octocat = AccountAdmin(git_hub_login="******")
        sa.session.add(octocat)
        sa.session.commit()

    app = create_app(config_path, **kwargs)
    with app.app_context():
        assert expected == {e.git_hub_login for e in AccountAdmin.query.all()}
Beispiel #8
0
def app_empty():
    database_uri = "sqlite:///:memory:"
    y = create_app(
        SQLALCHEMY_DATABASE_URI=database_uri,
        GITHUB_AUTH_AUTHORIZE_URL="https://github.com/login/oauth/authorize",
        GITHUB_AUTH_TOKEN_URL="https://github.com/login/oauth/access_token",
        GITHUB_AUTH_CLIENT_ID="client_id_0123456789",
        GITHUB_AUTH_CLIENT_SECRET="client_secret_abcdefghijklmnupqrstuvwxyz",
        GITHUB_AUTH_REDIRECT_URI="http://localhost:8080/signin",
    )
    with y.app_context():
        define_tables()
    yield y
Beispiel #9
0
def test_template(number, data):
    app = create_app(
        SQLALCHEMY_DATABASE_URI="sqlite:///:memory:",
        ACONDBS_GRAPHIQL=True,
        ACONDBS_GRAPHIQL_TEMPLATE_NO=number,
    )
    with app.app_context():
        define_tables()

    client = app.test_client()

    response = client.get("/graphql", headers={"Accept": "text/html"})
    assert 200 == response.status_code
    assert data in response.data.decode("utf-8")
Beispiel #10
0
def app(database_uri):
    """a test Flask application

    The `app` is an instance of `Flask`. Its API is described in the
    Flask documentation at
    https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask

    The `app` is initialized for the SQLAlchemy DB with URI at
    `database_uri`.

    Yields
    ------
    Flask

    """
    config_path = os.path.join(SAMPLE_DIR, 'config.py')
    app = create_app(config_path=config_path,
                     SQLALCHEMY_DATABASE_URI=database_uri)
    yield app
Beispiel #11
0
def app_with_empty_db():
    database_uri = "sqlite:///:memory:"
    app = create_app(SQLALCHEMY_DATABASE_URI=database_uri)
    yield app
Beispiel #12
0
def app_empty():
    database_uri = "sqlite:///:memory:"
    y = create_app(SQLALCHEMY_DATABASE_URI=database_uri)
    with y.app_context():
        define_tables()
    yield y