Example #1
0
def test_flags_init_app():
    """Ensure that extension can be initialized."""
    app = Flask(__name__)

    with app.app_context():
        flags = Flags()
        flags.init_app(app)
    assert app.extensions['featureflags']
Example #2
0
def test_flags_init_app_no_key_dev():
    """Assert that the extension is setup with a KEY, but in non-production mode."""
    app = Flask(__name__)
    app.config['LD_SDK_KEY'] = None
    app.env = 'development'

    with app.app_context():
        flags = Flags()
        flags.init_app(app)
    assert app.extensions['featureflags']
Example #3
0
def test_flags_init_app_production():
    """Ensure that extension can be initialized."""
    app = Flask(__name__)
    app.env = 'production'
    app.config['LD_SDK_KEY'] = 'https://no.flag/avail'

    with app.app_context():
        flags = Flags()
        flags.init_app(app)
    assert app.extensions['featureflags']
Example #4
0
def test_flags_bool_no_key_prod():
    """Assert that prod with no key initializes, but does not setup the extension."""
    app = Flask(__name__)
    app.config['LD_SDK_KEY'] = None
    app.env = 'production'

    with app.app_context():
        flags = Flags()
        flags.init_app(app)
        on = flags.is_on('bool-flag')

    assert not on
Example #5
0
def test_flags_init_app_no_key_prod():
    """Assert that prod with no key initializes, but does not setup the extension."""
    app = Flask(__name__)
    app.config['LD_SDK_KEY'] = None
    app.env = 'production'

    with app.app_context():
        flags = Flags()
        flags.init_app(app)
        with pytest.raises(KeyError):
            client = app.extensions['featureflags']
            assert not client
Example #6
0
def test_flags_bool():
    """Assert that a boolean (True) is returned, when using the local Flag.json file."""
    app = Flask(__name__)
    app.env = 'development'
    app.config['LD_SDK_KEY'] = 'https://no.flag/avail'

    with app.app_context():
        flags = Flags()
        flags.init_app(app)
        flag_on = flags.is_on('bool-flag')

        assert flag_on
Example #7
0
def test_flag_bool_unique_user():
    """Assert that a unique user can retrieve a flag, when using the local Flag.json file."""
    app = Flask(__name__)
    app.env = 'development'
    app.config['LD_SDK_KEY'] = 'https://no.flag/avail'

    user = User(username='******',
                firstname='firstname',
                lastname='lastname',
                sub='sub',
                iss='iss')

    app_env = app.env
    try:
        with app.app_context():
            flags = Flags()
            flags.init_app(app)
            app.env = 'development'
            val = flags.value('bool-flag', user)
            flag_on = flags.is_on('bool-flag', user)

        assert val
        assert flag_on
    except:  # pylint: disable=bare-except; # noqa: B901, E722
        # for tests we don't care
        assert False
    finally:
        app.env = app_env
Example #8
0
def test_flags_init():
    """Ensure that extension can be initialized."""
    app = Flask(__name__)
    app.env = 'development'

    with app.app_context():
        flags = Flags(app)

    assert flags
    assert app.extensions['featureflags']