Example #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()
Example #2
0
def test_should_check_error_when_petisco_is_not_initialized():
    with pytest.raises(Exception) as excinfo:
        Petisco.get_instance()
        solutions_text = (
            f"\t Possible Solutions:\n"
            f"\t  * If you are testing and need any preconfigured Petisco, you can use the fixture given_any_petisco.\n"
            f"\t  * If you are testing and need specific preconfigured Petisco, you can create a fixture loading a petisco and then clearing.\n"
            f"\t  * If you are running a Petisco application, please review your loading process, petisco.yml is probably failing.\n"
        )
        assert solutions_text in str(excinfo.value)
Example #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()
Example #4
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()
Example #5
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()
Example #6
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()
Example #7
0
        def log_warning(message: str):
            from petisco import Petisco, DEBUG, LogMessage

            logger = Petisco.get_logger()
            log_message = LogMessage(operation="persistence",
                                     layer="infrastructure")
            logger.log(DEBUG, log_message.set_message(message))
        def _log_stop_exception(e: Exception):
            from petisco import LogMessage, ERROR, Petisco

            logger = Petisco.get_logger()
            log_message = LogMessage(layer="petisco",
                                     operation=f"RabbitMQEventSubscriber")
            message = f"Error stopping RabbitMQEventSubscriber: {repr(e.__class__)} {e} | {traceback.format_exc()}"
            logger.log(ERROR, log_message.set_message(message))
Example #9
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()
Example #10
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()
Example #11
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()
Example #12
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()
Example #13
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()
Example #14
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()
 def build():
     return TasksCountIncreaser(repository=Petisco.get_repository("tasks_count"))
Example #16
0
 def build():
     return UserCreator(repository=Repositories.get("user"),
                        bus=Petisco.get_event_bus())
def requeue_from_dead_letter(event: Event):
    publisher = Petisco.get_event_publisher()
    publisher.publish(event)
    return isSuccess
from taskmanager import petisco_setup, persistence_setup
from petisco import Petisco

petisco_setup()
persistence_setup()
app = Petisco.get_instance().get_app()
def scheduled_task():
    Petisco.get_logger().log(INFO, LogMessage().set_message("scheduled_task"))
def instant_task():
    Petisco.get_logger().log(INFO, LogMessage().set_message("instant_task"))
 def build():
     return TasksCountRetriever(
         repository=Petisco.get_repository("tasks_count"))
def petisco_setup():
    petisco = Petisco.from_filename(f"{ROOT_PATH}/petisco.yml")
    petisco.configure_events(f"{ROOT_PATH}/petisco.events.yml")
 def build():
     return EventStorer(repository=Petisco.get_repository("event"))
Example #24
0
def main():
    petisco_setup()
    persistence_setup()
    Petisco.get_instance().get_app()
    Petisco.get_instance().start()
def recurring_task():
    Petisco.get_logger().log(INFO, LogMessage().set_message("recurring_task"))
def get_events():
    use_case = EventsRetriever(
        repository=Petisco.get_repository("event"),
        publisher=Petisco.get_event_publisher(),
    )
    return use_case.execute()
from meiga import Result
from petisco import controller_handler, Petisco

from taskmanager.src.modules.events.application.retrieve.events_retriever import (
    EventsRetriever, )


def success_handler(result: Result):
    events = [event.to_dict() for event in result.value]
    return {"events": events}, 200


@controller_handler(logger=Petisco.get_logger(),
                    success_handler=success_handler)
def get_events():
    use_case = EventsRetriever(
        repository=Petisco.get_repository("event"),
        publisher=Petisco.get_event_publisher(),
    )
    return use_case.execute()
Example #28
0
 def build():
     return CreateTask(repository=Petisco.get_repository("task"),
                       bus=Petisco.get_event_bus())
Example #29
0
 def build():
     return TaskRemover(repository=Petisco.get_repository("task"),
                        bus=Petisco.get_event_bus())
Example #30
0
def petisco_client_flask_app(taskmanager_sql_database):
    app = Petisco.get_instance().get_app()
    with app.app.test_client() as c:
        yield c
    Petisco.get_instance().stop()