API - minor refactor and documentation update
This commit is contained in:
		@@ -45,7 +45,7 @@ def create_app():
 | 
			
		||||
    from .activities.records import records_blueprint  # noqa
 | 
			
		||||
    from .activities.sports import sports_blueprint  # noqa
 | 
			
		||||
    from .activities.stats import stats_blueprint  # noqa
 | 
			
		||||
    from .application.config import config_blueprint  # noqa
 | 
			
		||||
    from .application.app_config import config_blueprint  # noqa
 | 
			
		||||
 | 
			
		||||
    app.register_blueprint(users_blueprint, url_prefix='/api')
 | 
			
		||||
    app.register_blueprint(auth_blueprint, url_prefix='/api')
 | 
			
		||||
 
 | 
			
		||||
@@ -36,13 +36,22 @@ def app_config_registration_disabled():
 | 
			
		||||
    return config
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture
 | 
			
		||||
def app():
 | 
			
		||||
def get_app_config(app_type):
 | 
			
		||||
    if app_type == 'with_registration':
 | 
			
		||||
        return app_config_with_registration()
 | 
			
		||||
    elif app_type == 'no_registration':
 | 
			
		||||
        return app_config_registration_disabled()
 | 
			
		||||
    else:
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_app(app_type=None):
 | 
			
		||||
    app = create_app()
 | 
			
		||||
    with app.app_context():
 | 
			
		||||
        db.create_all()
 | 
			
		||||
        app_db_config = app_config_with_registration()
 | 
			
		||||
        update_app_config_from_database(app, app_db_config)
 | 
			
		||||
        app_db_config = get_app_config(app_type)
 | 
			
		||||
        if app_db_config:
 | 
			
		||||
            update_app_config_from_database(app, app_db_config)
 | 
			
		||||
        yield app
 | 
			
		||||
        db.session.remove()
 | 
			
		||||
        db.drop_all()
 | 
			
		||||
@@ -53,33 +62,19 @@ def app():
 | 
			
		||||
        return app
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture
 | 
			
		||||
def app():
 | 
			
		||||
    yield from get_app('with_registration')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture
 | 
			
		||||
def app_no_config():
 | 
			
		||||
    app = create_app()
 | 
			
		||||
    with app.app_context():
 | 
			
		||||
        db.create_all()
 | 
			
		||||
        yield app
 | 
			
		||||
        db.session.remove()
 | 
			
		||||
        db.drop_all()
 | 
			
		||||
        # close unused idle connections => avoid the following error:
 | 
			
		||||
        # FATAL: remaining connection slots are reserved for non-replication
 | 
			
		||||
        # superuser connections
 | 
			
		||||
        db.engine.dispose()
 | 
			
		||||
        return app
 | 
			
		||||
    yield from get_app()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture
 | 
			
		||||
def app_no_registration():
 | 
			
		||||
    app = create_app()
 | 
			
		||||
    with app.app_context():
 | 
			
		||||
        db.create_all()
 | 
			
		||||
        app_db_config = app_config_registration_disabled()
 | 
			
		||||
        update_app_config_from_database(app, app_db_config)
 | 
			
		||||
        yield app
 | 
			
		||||
        db.session.remove()
 | 
			
		||||
        db.drop_all()
 | 
			
		||||
        db.engine.dispose()
 | 
			
		||||
    return app
 | 
			
		||||
    yield from get_app('no_registration')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture()
 | 
			
		||||
 
 | 
			
		||||
@@ -50,9 +50,7 @@ def test_get_config_no_config(app_no_config, user_1_admin):
 | 
			
		||||
    assert 'Error on getting configuration.' in data['message']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_get_config_several_config(
 | 
			
		||||
    app, app_config, user_1_admin
 | 
			
		||||
):
 | 
			
		||||
def test_get_config_several_config(app, app_config, user_1_admin):
 | 
			
		||||
    client = app.test_client()
 | 
			
		||||
    resp_login = client.post(
 | 
			
		||||
        '/api/auth/login',
 | 
			
		||||
@@ -84,9 +82,7 @@ def test_update_config_as_admin(app, user_1_admin):
 | 
			
		||||
    response = client.patch(
 | 
			
		||||
        '/api/config',
 | 
			
		||||
        content_type='application/json',
 | 
			
		||||
        data=json.dumps(
 | 
			
		||||
            dict(registration=True, max_users=10)
 | 
			
		||||
        ),
 | 
			
		||||
        data=json.dumps(dict(registration=True, max_users=10)),
 | 
			
		||||
        headers=dict(
 | 
			
		||||
            Authorization='Bearer '
 | 
			
		||||
            + json.loads(resp_login.data.decode())['auth_token']
 | 
			
		||||
@@ -150,9 +146,7 @@ def test_update_config_not_admin(app, user_1):
 | 
			
		||||
    response = client.patch(
 | 
			
		||||
        '/api/config',
 | 
			
		||||
        content_type='application/json',
 | 
			
		||||
        data=json.dumps(
 | 
			
		||||
            dict(registration=True, max_users=10)
 | 
			
		||||
        ),
 | 
			
		||||
        data=json.dumps(dict(registration=True, max_users=10)),
 | 
			
		||||
        headers=dict(
 | 
			
		||||
            Authorization='Bearer '
 | 
			
		||||
            + json.loads(resp_login.data.decode())['auth_token']
 | 
			
		||||
@@ -199,9 +193,7 @@ def test_update_config_no_config(app_no_config, user_1_admin):
 | 
			
		||||
    response = client.patch(
 | 
			
		||||
        '/api/config',
 | 
			
		||||
        content_type='application/json',
 | 
			
		||||
        data=json.dumps(
 | 
			
		||||
            dict(registration=True, max_users=10)
 | 
			
		||||
        ),
 | 
			
		||||
        data=json.dumps(dict(registration=True, max_users=10)),
 | 
			
		||||
        headers=dict(
 | 
			
		||||
            Authorization='Bearer '
 | 
			
		||||
            + json.loads(resp_login.data.decode())['auth_token']
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
"""empty message
 | 
			
		||||
"""add application config in database
 | 
			
		||||
 | 
			
		||||
Revision ID: 8a0aad4c838c
 | 
			
		||||
Revises: 1345afe3b11d
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user