def test_count_repository_actions_with_wildcard_disabled(initialized_db):
    with fake_elasticsearch(allow_wildcard=False):
        logs_model = es_model()

        # Log some actions.
        logs_model.log_action("push_repo",
                              namespace_name="devtable",
                              repository_name="simple",
                              ip="1.2.3.4")

        logs_model.log_action("pull_repo",
                              namespace_name="devtable",
                              repository_name="simple",
                              ip="1.2.3.4")
        logs_model.log_action("pull_repo",
                              namespace_name="devtable",
                              repository_name="simple",
                              ip="1.2.3.4")

        # Log some actions to a different repo.
        logs_model.log_action("pull_repo",
                              namespace_name="devtable",
                              repository_name="complex",
                              ip="1.2.3.4")
        logs_model.log_action("pull_repo",
                              namespace_name="devtable",
                              repository_name="complex",
                              ip="1.2.3.4")

        # Count the actions.
        day = date.today()
        simple_repo = model.repository.get_repository("devtable", "simple")

        count = logs_model.count_repository_actions(simple_repo, day)
        assert count == 3

        complex_repo = model.repository.get_repository("devtable", "complex")
        count = logs_model.count_repository_actions(complex_repo, day)
        assert count == 2

        # Try counting actions for a few days in the future to ensure it doesn't raise an error.
        count = logs_model.count_repository_actions(simple_repo,
                                                    day + timedelta(days=5))
        assert count == 0
Exemple #2
0
def fake_es():
    with fake_elasticsearch():
        yield