コード例 #1
0
def test_no_use_key():
    cfg = get_config()
    cfg.database = {
        'database': conn['database_name'],
        'server': conn['host'],
        'username': conn['username'],
        'password': conn['password']
    }
    with pytest.raises(DatabaseConnectionError):
        api = PotionApplication(cfg)
コード例 #2
0
def test_dummy_postgres_connection_fails():
    cfg = get_config()
    cfg.database = {
        'use':'postgres',
        'database': conn['database_name'],
        'server': conn['host'],
        'username': conn['username'],
        'password': conn['password']
    }
    with pytest.raises(DatabaseConnectionError):
        api = PotionApplication(cfg)
コード例 #3
0
def test_default_log(make_client):
    cfg = get_config()
    cfg.logging = {}
    logger = _get_logger(cfg)

    # start falcon API
    api = PotionApplication(cfg)
    assert api.logging_level == 'WARNING'

    # since level is 'warning', should NOT show startup INFO log
    assert logger.is_empty()

    _error_logged_to_db(make_client, api, logger)
    delete_all()
コード例 #4
0
def test_log_level_info(make_client):
    cfg = get_config()
    cfg.logging = {'level': 'INFO'}

    logger = _get_logger(cfg)

    # start falcon API
    api = PotionApplication(cfg)
    assert api.logging_level == 'INFO'

    # since level is 'info', should show startup INFO log
    assert not logger.is_empty()
    all_logs = query_to_dict(logger.get_all())

    assert type(all_logs) == dict
    assert all_logs['msg'] == 'STARTUP: Logging configured successfully'
    assert all_logs['level'] == 'INFO'

    _error_logged_to_db(make_client, api, logger)
    delete_all()
コード例 #5
0
from datetime import datetime, timedelta
from pathlib import Path

import jwt

from tests.helpers.temp_application import get_config

key = Path(get_config().authentication['key']).read_text().strip()

token = {
    'sub': '1234567890',
    'name': 'Jane Doe',
    'admin': True,
    'iat': 631152000,  # 01/01/1990 @ 12:00am (UTC)
    'exp': 631324800,  # 01/03/1990 @ 12:00am (UTC)
    'nbf': 631238400  # 01/02/1990 @ 12:00am (UTC)
}
'''
creates token to use in the Authorization header

optional parameter 'adjust_times'
if True:
    will change the timestamps in the payload to match
    when the test is being run (valid timestamps)
if False:
    will not change timestamps, so all will be invalid.
'''


def create_token(payload, adjust_times=True, prefix='Bearer'):
    now = datetime.utcnow()
コード例 #6
0
def create_custom_auth_setup_api(auth_value):
    cfg = get_config()
    cfg.authentication = auth_value
    return PotionApplication(cfg)
コード例 #7
0
def test_no_db_in_config():
    cfg = get_config()
    del cfg.database

    with pytest.raises(DatabaseConnectionError):
        api = PotionApplication(cfg)
コード例 #8
0
def test_empty_db_in_config():
    cfg = get_config()
    cfg.database = {}

    with pytest.raises(DatabaseConnectionError):
        api = PotionApplication(cfg)
コード例 #9
0
def test_unsupported_db_type():
    cfg = get_config()
    cfg.database = {'use':'sqlserver'}

    with pytest.raises(DatabaseConnectionError):
        api = PotionApplication(cfg)