diff --git a/tests/conftest.py b/tests/conftest.py index 3bc9c2b6..4b1c9111 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,6 +38,19 @@ def app(request): ctx.pop() +@pytest.fixture(autouse=True) +def skip_audit_log(request): + """ + Conditionally skip tests marked with 'audit_log' based on the + AUDIT_LOG_FEATURE_TOGGLE config value. + """ + config = make_config() + if request.node.get_closest_marker("audit_log"): + use_audit_log = config.get("AUDIT_LOG_FEATURE_TOGGLE", False) + if not use_audit_log: + pytest.skip("audit log feature flag disabled") + + @pytest.fixture(scope="function") def no_debug_app(request): config = make_config(direct_config={"DEBUG": False}) diff --git a/tests/domain/test_audit_log.py b/tests/domain/test_audit_log.py index 3f324c76..e60e2202 100644 --- a/tests/domain/test_audit_log.py +++ b/tests/domain/test_audit_log.py @@ -29,6 +29,7 @@ def developer(): return UserFactory.create() +@pytest.mark.audit_log def test_paginate_audit_log(): user = UserFactory.create() for _ in range(100): @@ -38,6 +39,7 @@ def test_paginate_audit_log(): assert len(events) == 25 +@pytest.mark.audit_log def test_paginate_ws_audit_log(): portfolio = PortfolioFactory.create() application = ApplicationFactory.create(portfolio=portfolio) @@ -52,6 +54,7 @@ def test_paginate_ws_audit_log(): assert len(events) == 25 +@pytest.mark.audit_log def test_portfolio_audit_log_only_includes_current_portfolio_events(): owner = UserFactory.create() portfolio = PortfolioFactory.create(owner=owner) @@ -69,6 +72,7 @@ def test_portfolio_audit_log_only_includes_current_portfolio_events(): ) +@pytest.mark.audit_log def test_get_portfolio_events_includes_app_and_env_events(): owner = UserFactory.create() # add portfolio level events @@ -120,6 +124,7 @@ def test_get_application_events(): assert "portfolio" not in resource_types +@pytest.mark.audit_log def test_get_all_includes_ccpo_user_changes(): user = UserFactory.create() initial_audit_log = AuditLog.get_all_events() diff --git a/tests/domain/test_invitations.py b/tests/domain/test_invitations.py index 47cf27a5..24d0c166 100644 --- a/tests/domain/test_invitations.py +++ b/tests/domain/test_invitations.py @@ -148,6 +148,7 @@ def test_resend_invitation(session): assert second_invite.is_pending +@pytest.mark.audit_log def test_audit_event_for_accepted_invite(): portfolio = PortfolioFactory.create() user = UserFactory.create() diff --git a/tests/models/test_application.py b/tests/models/test_application.py index ef8630ca..133c22a5 100644 --- a/tests/models/test_application.py +++ b/tests/models/test_application.py @@ -1,3 +1,5 @@ +import pytest + from atst.domain.application_roles import ApplicationRoles from atst.models import ApplicationRoleStatus from atst.models import AuditEvent @@ -34,6 +36,7 @@ def test_application_members_excludes_deleted(session): assert app.members[0].id == member_role.id +@pytest.mark.audit_log def test_audit_event_for_application_deletion(session): app = ApplicationFactory.create() app.deleted = True diff --git a/tests/models/test_application_role.py b/tests/models/test_application_role.py index f4526f59..f80ee0ba 100644 --- a/tests/models/test_application_role.py +++ b/tests/models/test_application_role.py @@ -1,3 +1,5 @@ +import pytest + from atst.domain.permission_sets import PermissionSets from atst.domain.environment_roles import EnvironmentRoles from atst.models.audit_event import AuditEvent @@ -5,6 +7,7 @@ from atst.models.audit_event import AuditEvent from tests.factories import * +@pytest.mark.audit_log def test_has_application_role_history(session): owner = UserFactory.create() user = UserFactory.create() diff --git a/tests/models/test_environments.py b/tests/models/test_environments.py index 2c2453f6..d7e1c27d 100644 --- a/tests/models/test_environments.py +++ b/tests/models/test_environments.py @@ -32,6 +32,7 @@ def test_add_user_to_environment(): assert developer in dev_environment.users +@pytest.mark.audit_log def test_audit_event_for_environment_deletion(session): env = EnvironmentFactory.create(application=ApplicationFactory.create()) env.deleted = True diff --git a/tests/models/test_portfolio_role.py b/tests/models/test_portfolio_role.py index f5fb2bf4..e7d2a23d 100644 --- a/tests/models/test_portfolio_role.py +++ b/tests/models/test_portfolio_role.py @@ -12,6 +12,7 @@ from tests.factories import * from atst.domain.portfolio_roles import PortfolioRoles +@pytest.mark.audit_log def test_has_no_portfolio_role_history(session): owner = UserFactory.create() user = UserFactory.create() @@ -29,6 +30,7 @@ def test_has_no_portfolio_role_history(session): assert not create_event.changed_state +@pytest.mark.audit_log def test_has_portfolio_role_history(session): owner = UserFactory.create() user = UserFactory.create() @@ -56,6 +58,7 @@ def test_has_portfolio_role_history(session): assert set(new_state) == PortfolioRoles.DEFAULT_PORTFOLIO_PERMISSION_SETS +@pytest.mark.audit_log def test_has_portfolio_status_history(session): owner = UserFactory.create() user = UserFactory.create() @@ -82,6 +85,7 @@ def test_has_portfolio_status_history(session): assert changed_events[0].changed_state["status"][1] == "active" +@pytest.mark.audit_log def test_has_no_env_role_history(session): owner = UserFactory.create() user = UserFactory.create() @@ -104,6 +108,7 @@ def test_has_no_env_role_history(session): assert not create_event.changed_state +@pytest.mark.audit_log def test_has_env_role_history(session): user = UserFactory.create() application = ApplicationFactory.create() diff --git a/tests/test_access.py b/tests/test_access.py index c72ac36d..24d2d8a9 100644 --- a/tests/test_access.py +++ b/tests/test_access.py @@ -137,6 +137,7 @@ def post_url_assert_status(no_debug_client, user_session): # ccpo.activity_history +@pytest.mark.audit_log def test_atst_activity_history_access(get_url_assert_status): ccpo = user_with(PermissionSets.VIEW_AUDIT_LOG) rando = user_with() diff --git a/tests/test_filters.py b/tests/test_filters.py index f35bb659..79b65b98 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -18,12 +18,14 @@ def test_dollar_fomatter(input, expected): assert dollars(input) == expected +@pytest.mark.audit_log def test_render_audit_event_with_known_resource_type(): event = AuditEvent(resource_type="user") result = renderAuditEvent(event) assert "