|
| 1 | +""" |
| 2 | +GitLab API: |
| 3 | +https://docs.gitlab.com/ee/api/audit_events.html#project-audit-events |
| 4 | +""" |
| 5 | + |
| 6 | +import re |
| 7 | + |
| 8 | +import pytest |
| 9 | +import responses |
| 10 | + |
| 11 | +from gitlab.v4.objects.audit_events import ProjectAudit |
| 12 | + |
| 13 | +id = 5 |
| 14 | + |
| 15 | +audit_events_content = { |
| 16 | + "id": 5, |
| 17 | + "author_id": 1, |
| 18 | + "entity_id": 7, |
| 19 | + "entity_type": "Project", |
| 20 | + "details": { |
| 21 | + "change": "prevent merge request approval from reviewers", |
| 22 | + "from": "", |
| 23 | + "to": "true", |
| 24 | + "author_name": "Administrator", |
| 25 | + "target_id": 7, |
| 26 | + "target_type": "Project", |
| 27 | + "target_details": "twitter/typeahead-js", |
| 28 | + "ip_address": "127.0.0.1", |
| 29 | + "entity_path": "twitter/typeahead-js", |
| 30 | + }, |
| 31 | + "created_at": "2020-05-26T22:55:04.230Z", |
| 32 | +} |
| 33 | + |
| 34 | +audit_events_url = re.compile( |
| 35 | + r"http://localhost/api/v4/((groups|projects)/1/)audit_events" |
| 36 | +) |
| 37 | + |
| 38 | +audit_events_url_id = re.compile( |
| 39 | + rf"http://localhost/api/v4/((groups|projects)/1/)audit_events/{id}" |
| 40 | +) |
| 41 | + |
| 42 | + |
| 43 | +@pytest.fixture |
| 44 | +def resp_list_audit_events(): |
| 45 | + with responses.RequestsMock() as rsps: |
| 46 | + rsps.add( |
| 47 | + method=responses.GET, |
| 48 | + url=audit_events_url, |
| 49 | + json=[audit_events_content], |
| 50 | + content_type="application/json", |
| 51 | + status=200, |
| 52 | + ) |
| 53 | + yield rsps |
| 54 | + |
| 55 | + |
| 56 | +@pytest.fixture |
| 57 | +def resp_get_variable(): |
| 58 | + with responses.RequestsMock() as rsps: |
| 59 | + rsps.add( |
| 60 | + method=responses.GET, |
| 61 | + url=audit_events_url_id, |
| 62 | + json=audit_events_content, |
| 63 | + content_type="application/json", |
| 64 | + status=200, |
| 65 | + ) |
| 66 | + yield rsps |
| 67 | + |
| 68 | + |
| 69 | +def test_list_project_audit_events(project, resp_list_audit_events): |
| 70 | + audit_events = project.audit_events.list() |
| 71 | + assert isinstance(audit_events, list) |
| 72 | + assert isinstance(audit_events[0], ProjectAudit) |
| 73 | + assert audit_events[0].id == id |
| 74 | + |
| 75 | + |
| 76 | +def test_get_project_audit_events(project, resp_get_variable): |
| 77 | + audit_event = project.audit_events.get(id) |
| 78 | + assert isinstance(audit_event, ProjectAudit) |
| 79 | + assert audit_event.id == id |
0 commit comments