Exemplo n.º 1
0
def test_install_feature_flags(app, caplog):
    Feature.query.delete()

    declared_and_installed = Feature(
        name=TestingFeatureToggle.AUTO_DESTROY_AIRCRAFT_ON_WINDOW_OPENING.name,
        description=TestingFeatureToggle.
        AUTO_DESTROY_AIRCRAFT_ON_WINDOW_OPENING.value,
        isActive=False,
    )
    not_declared_but_installed = Feature(
        name="ENABLE_TAKEOFF",
        isActive=False,
        description="Veillez à bien laisser ce feature flag désactivé")

    db.session.add(declared_and_installed)
    db.session.add(not_declared_but_installed)
    db.session.commit()

    install_feature_flags()

    # already installed keeps isActive value
    assert not Feature.query.filter_by(
        name=declared_and_installed.name).one().isActive

    # new installed with isActive=True
    assert Feature.query.filter_by(
        name=TestingFeatureToggle.ENABLE_LOOPING_INOPINE.name).one().isActive

    # new installed with isActive=False
    assert not Feature.query.filter_by(
        name=TestingFeatureToggle.ENABLE_LANDING.name).one().isActive

    assert caplog.messages == [
        "The following feature flags are present in database but not present in code: {'ENABLE_TAKEOFF'}"
    ]
Exemplo n.º 2
0
def clean_all_database(*args, **kwargs):
    """Order of deletions matters because of foreign key constraints"""
    if settings.ENV not in ("development", "testing"):
        raise ValueError(f"You cannot do this on this environment: '{settings.ENV}'")
    LocalProviderEvent.query.delete()
    ActivationCode.query.delete()
    AllocineVenueProviderPriceRule.query.delete()
    AllocineVenueProvider.query.delete()
    VenueProvider.query.delete()
    PaymentStatus.query.delete()
    Payment.query.delete()
    PaymentMessage.query.delete()
    CustomReimbursementRule.query.delete()
    Booking.query.delete()
    IndividualBooking.query.delete()
    Stock.query.delete()
    Favorite.query.delete()
    Mediation.query.delete()
    OfferCriterion.query.delete()
    Criterion.query.delete()
    Offer.query.delete()
    Product.query.delete()
    BankInformation.query.delete()
    Venue.query.delete()
    UserOfferer.query.delete()
    ApiKey.query.delete()
    Offerer.query.delete()
    Deposit.query.delete()
    BeneficiaryImportStatus.query.delete()
    BeneficiaryImport.query.delete()
    BeneficiaryFraudCheck.query.delete()
    BeneficiaryFraudResult.query.delete()
    BeneficiaryFraudReview.query.delete()
    Token.query.delete()
    OfferValidationConfig.query.delete()
    User.query.delete()
    UserSession.query.delete()
    Email.query.delete()
    LocalProviderEvent.query.delete()
    Provider.query.delete()
    AllocinePivot.query.delete()
    VenueType.query.delete()
    VenueLabel.query.delete()
    EducationalBooking.query.delete()
    EducationalDeposit.query.delete()
    EducationalInstitution.query.delete()
    EducationalYear.query.delete()
    EducationalRedactor.query.delete()

    # Dans le cadre du projet EAC, notre partenaire Adage requête notre api sur le endpoint get_pre_bookings.
    # Ils récupèrent les pré-réservations EAC liées à un utilisateur EAC et stockent les ids en base.
    # Dans la phase de développement, ils se connectent sur notre environnement testing et récupèrent des données issues donc de nos sandbox.
    # Nous avons besoin que les ids soient fixes. Pour ce faire, il faut que la séquence d'ids sur les EducationalBookings recommence à 1 à chaque
    # nouvelle génération de la sandbox sur testing. C'est la raison de la commande ci-dessous.
    # A noter qu'en local la question ne se pose pas car l'instance de base de données est détruite puis reconstruite. L'id recommence donc nécessairement à 1
    db.session.execute("SELECT setval('educational_booking_id_seq', 1, FALSE)")

    db.session.commit()
    install_feature_flags()
    install_local_providers()
Exemplo n.º 3
0
def _db(app):
    """
    Provide the transactional fixtures with access to the database via a Flask-SQLAlchemy
    database connection.
    """
    mock_db = db
    mock_db.init_app(app)
    install_database_extensions()
    run_migrations()
    install_feature_flags()

    install_local_providers()
    clean_all_database()

    return mock_db
Exemplo n.º 4
0
def app_fixture():
    from pcapi import flask_app

    app = flask_app.app

    # FIXME: some tests fail without this, for example:
    #   - pytest tests/admin/custom_views/offer_view_test.py
    #   - pytest tests/core/fraud/test_api.py
    # Leave an XXX note about why we need that.
    app.teardown_request_funcs[None].remove(flask_app.remove_db_session)

    with app.app_context():
        app.config["TESTING"] = True

        install_all_routes(app)

        app.register_blueprint(test_blueprint, url_prefix="/test-blueprint")

        install_database_extensions()
        run_migrations()
        install_feature_flags()
        install_local_providers()

        yield app
Exemplo n.º 5
0
def install_data():
    install_feature_flags()
    logger.info("Feature flags installed")