8000 feat: add project audit endpoint by Sineaggi · Pull Request #1308 · python-gitlab/python-gitlab · GitHub
[go: up one dir, main page]

Skip to content

feat: add project audit endpoint #1308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions gitlab/tests/objects/test_audit_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""
GitLab API:
https://docs.gitlab.com/ee/api/audit_events.html#project-audit-events
"""

import re

import pytest
import responses

from gitlab.v4.objects.audit_events import ProjectAudit

id = 5

audit_events_content = {
"id": 5,
"author_id": 1,
"entity_id": 7,
"entity_type": "Project",
"details": {
"change": "prevent merge request approval from reviewers",
"from": "",
"to": "true",
"author_name": "Administrator",
"target_id": 7,
"target_type": "Project",
"target_details": "twitter/typeahead-js",
"ip_address": "127.0.0.1",
"entity_path": "twitter/typeahead-js",
},
"created_at": "2020-05-26T22:55:04.230Z",
}

audit_events_url = re.compile(
r"http://localhost/api/v4/((groups|projects)/1/)audit_events"
)

audit_events_url_id = re.compile(
rf"http://localhost/api/v4/((groups|projects)/1/)audit_events/{id}"
)


@pytest.fixture
def resp_list_audit_events():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url=audit_events_url,
json=[audit_events_content],
content_type="application/json",
status=200,
)
yield rsps


@pytest.fixture
def resp_get_variable():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url=audit_events_url_id,
json=audit_events_content,
content_type="application/json",
status=200,
)
yield rsps


def test_list_project_audit_events(project, resp_list_audit_events):
audit_events = project.audit_events.list()
assert isinstance(audit_events, list)
assert isinstance(audit_events[0], ProjectAudit)
assert audit_events[0].id == id


def test_get_project_audit_events(project, resp_get_variable):
audit_event = project.audit_events.get(id)
assert isinstance(audit_event, ProjectAudit)
assert audit_event.id == id
23 changes: 23 additions & 0 deletions gitlab/v4/objects/audit_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
GitLab API:
https://docs.gitlab.com/ee/api/audit_events.html#project-audit-events
"""

from gitlab.base import * # noqa
from gitlab.mixins import * # noqa

__all__ = [
"ProjectAudit",
"ProjectAuditManager",
]


class ProjectAudit(RESTObject):
_id_attr = "id"


class ProjectAuditManager(RetrieveMixin, RESTManager):
_path = "/projects/%(project_id)s/audit_events"
_obj_cls = ProjectAudit
_from_parent_attrs = {"project_id": "id"}
_list_filters = ("created_after", "created_before")
2 changes: 2 additions & 0 deletions gitlab/v4/objects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .deployments import ProjectDeploymentManager
from .environments import ProjectEnvironmentManager
from .events import ProjectEventManager
from .audit_events import ProjectAuditManager
from .export_import import ProjectExportManager, ProjectImportManager
from .files import ProjectFileManager
from .hooks import ProjectHookManager
Expand Down Expand Up @@ -100,6 +101,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
("deployments", "ProjectDeploymentManager"),
("environments", "ProjectEnvironmentManager"),
("events", "ProjectEventManager"),
("audit_events", "ProjectAuditManager"),
("exports", "ProjectExportManager"),
("files", "ProjectFileManager"),
("forks", "ProjectForkManager"),
Expand Down
0