Esempio n. 1
0
def given_petisco_flask_app_with_mongodb(petisco_yml_path_flask_app):
    Petisco.clear()
    petisco = Petisco.from_filename(
        f"{petisco_yml_path_flask_app}/petisco_with_mongo.yml")
    petisco.configure_events(petisco_yml_path_flask_app +
                             "/petisco.events.yml")
    yield petisco
    Petisco.clear()
    petisco.stop()
Esempio n. 2
0
def test_should_load_petisco_from_yml_and_schedule_tasks(
        petisco_yml_path_end2end):

    filename = f"{petisco_yml_path_end2end}/petisco.all.yml"

    petisco = Petisco.from_filename(filename)

    petisco._schedule_tasks()

    Petisco.clear()
Esempio n. 3
0
def test_should_stop_petisco_without_configured_task(petisco_yml_path_end2end):

    Petisco.clear()

    filename = f"{petisco_yml_path_end2end}/../flask_app/petisco.notasks.yml"

    petisco = Petisco.from_filename(filename)

    petisco.stop()
    Petisco.clear()
Esempio n. 4
0
def initialized_petisco():
    filename = (
        f"{os.path.dirname(os.path.abspath(__file__))}/end2end/flask_app/petisco.yml"
    )
    Petisco.clear()
    Petisco.from_filename(filename)

    yield

    Petisco.clear()
Esempio n. 5
0
def test_should_load_petisco_from_yml_and_check_logger_level(
        logging_level, logging_level_num, petisco_yml_path_end2end):

    Petisco.clear()
    os.environ["PETISCO_LOGGING_LEVEL"] = logging_level

    filename = f"{petisco_yml_path_end2end}/petisco.all.withlogging.yml"

    petisco = Petisco.from_filename(filename)

    assert hasattr(petisco.get_logger(), "logging_level")
    assert petisco.get_logger().logging_level == logging_level
    assert petisco.get_logger().logger.level == logging_level_num

    del os.environ["PETISCO_LOGGING_LEVEL"]
    Petisco.clear()
Esempio n. 6
0
def test_should_load_petisco_from_yml_with_specific_queue_config(
        petisco_yml_path_end2end):
    Petisco.clear()

    filename = f"{petisco_yml_path_end2end}/petisco.all.yml"
    filename_events = f"{petisco_yml_path_end2end}/petisco.events.specific.yml"

    petisco = Petisco.from_filename(filename)
    petisco.configure_events(filename_events)
    petisco._start()

    assert "config_events" in petisco.info
    assert "queues_specific_config" in petisco.info.get("config_events")

    petisco.stop()
    Petisco.clear()
Esempio n. 7
0
def test_should_load_petisco_from_yml_and_configure_events_from_yml_with_rabbitmq_message_broker(
        petisco_yml_path_end2end):
    Petisco.clear()

    filename = f"{petisco_yml_path_end2end}/petisco.all.yml"
    filename_events = f"{petisco_yml_path_end2end}/petisco.events.yml"

    petisco = Petisco.from_filename(filename)
    petisco.configure_events(filename_events)
    petisco._start()
    assert isinstance(Petisco.get_event_bus(), RabbitMqEventBus)

    assert "config_events" in petisco.info

    petisco.stop()
    Petisco.clear()
Esempio n. 8
0
def test_should_load_petisco_from_yml_and_configure_events_from_yml_with_not_implemented_message_broker(
        petisco_yml_path_end2end):
    Petisco.clear()

    filename = f"{petisco_yml_path_end2end}/petisco.all.yml"
    filename_events = f"{petisco_yml_path_end2end}/petisco.events.not_implemented.yml"

    petisco = Petisco.from_filename(filename)
    petisco.configure_events(filename_events)

    petisco._start()

    assert isinstance(Petisco.get_event_bus(), NotImplementedEventBus)

    petisco.stop()
    Petisco.clear()
Esempio n. 9
0
def test_should_load_petisco_from_yml_and_configure_events_from_yml_with_environ_rabbitmq_message_broker_not_implemented(
        petisco_yml_path_end2end):
    Petisco.clear()
    os.environ["PETISCO_EVENT_MESSAGE_BROKER"] = "notimplemented"

    filename = f"{petisco_yml_path_end2end}/petisco.all.yml"
    filename_events = f"{petisco_yml_path_end2end}/petisco.events.yml"

    petisco = Petisco.from_filename(filename)
    petisco.configure_events(filename_events)
    petisco._start()
    assert isinstance(Petisco.get_event_bus(), NotImplementedEventBus)

    del os.environ["PETISCO_EVENT_MESSAGE_BROKER"]

    petisco.stop()
    Petisco.clear()
Esempio n. 10
0
def test_should_load_petisco_from_yml(petisco_yml_path_end2end,
                                      given_petisco_version):

    filename = f"{petisco_yml_path_end2end}/petisco.all.yml"

    expected_petisco_info = {
        "app_name": "toy-app",
        "app_version": "1.0.0",
        "petisco_version": given_petisco_version,
        "environment": None,
        "event_publisher": {
            "name": "NotImplementedEventPublisher"
        },
        "event_subscriber": {
            "name": "NotImplementedEventSubscriber"
        },
        "tasks": {
            "recurring-task": {
                "type": "recurring",
                "run_in": 0.0,
                "interval": 10.0
            },
            "scheduled-task": {
                "type": "scheduled",
                "run_in": 10.0
            },
            "instant-task": {
                "type": "instant",
                "run_in": 0.0
            },
        },
    }

    petisco = Petisco.from_filename(filename)
    petisco.load_services_and_repositories()

    assert "elapsed_time" in petisco.info
    # assert "repositories" in petisco.info["elapsed_time"]
    # assert "services" in petisco.info["elapsed_time"]
    petisco.info.pop("elapsed_time")
    assert petisco.info == expected_petisco_info
    Petisco.clear()
Esempio n. 11
0
def given_petisco_flask_app(petisco_yml_path_flask_app):
    Petisco.clear()
    petisco = Petisco.from_filename(
        f"{petisco_yml_path_flask_app}/petisco.yml")
    petisco.configure_events(petisco_yml_path_flask_app +
                             "/petisco.events.yml")

    load_app_services()
    sql_database = SqliteDatabase(
        name="petisco-sql",
        connection=SqliteConnection.create("sqlite", "petisco-test.db"),
        model_filename=f"{petisco_yml_path_flask_app}/petisco.sql.models.yml",
    )
    persistence = Persistence()
    persistence.add(sql_database, skip_if_exist=True)
    persistence.create()
    load_repositories()

    yield petisco

    persistence.clear_data()

    Petisco.clear()
    petisco.stop()