-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from Asana/jv-asana-fix-audit-log-events
Fix get_audit_log_events
- Loading branch information
Showing
3 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
|
||
from .gen.audit_log_api import _AuditLogAPI | ||
from ..page_iterator import AuditLogAPIIterator | ||
|
||
|
||
class AuditLogAPI(_AuditLogAPI): | ||
"""AuditLogAPI resource""" | ||
pass | ||
|
||
def get_audit_log_events(self, workspace_gid, params={}, **options): | ||
"""Override get_audit_log_events to handle non-empty next_page parameter""" | ||
path = "/workspaces/{workspace_gid}/audit_log_events".replace( | ||
"{workspace_gid}", workspace_gid) | ||
options = self.client._merge_options(options) | ||
if options['iterator_type'] == 'items': | ||
return AuditLogAPIIterator(self.client, path, params, options).items() | ||
if options['iterator_type'] is None: | ||
return self.client.get(path, params, **options) | ||
raise Exception('Unknown value for "iterator_type" option: {}'.format( | ||
str(options['iterator_type']))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
from .helpers import * | ||
|
||
|
||
class TestClientAuditLogAPI(ClientTestCase): | ||
|
||
def test_get_audit_log_events(self): | ||
res = { | ||
"data": [ | ||
{ | ||
"actor": { | ||
"actor_type": "user", | ||
"email": "[email protected]", | ||
"gid": "1111", | ||
"name": "Greg Sanchez" | ||
}, | ||
"context": { | ||
"api_authentication_method": "cookie", | ||
"client_ip_address": "1.1.1.1", | ||
"context_type": "web", | ||
"oauth_app_name": "string", | ||
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" | ||
}, | ||
"created_at": "2021-01-01T00:00:00.000Z", | ||
"details": {}, | ||
"event_category": "deletion", | ||
"event_type": "task_deleted", | ||
"gid": "12345", | ||
"resource": { | ||
"email": "string", | ||
"gid": "1111", | ||
"name": "Example Task", | ||
"resource_subtype": "milestone", | ||
"resource_type": "task" | ||
} | ||
} | ||
], | ||
"next_page": { | ||
"offset": "a", | ||
"path": "/workspaces/1337/audit_log_events?offset=a", | ||
"uri": "https://app.asana.com/api/1.0/workspaces/1337/audit_log_events?offset=a" | ||
} | ||
} | ||
responses.add(GET, 'http://app/workspaces/1337/audit_log_events?', | ||
status=200, body=json.dumps(res), match_querystring=True) | ||
self.assertEqual( | ||
self.client.audit_log_api.get_audit_log_events("1337"), res['data']) | ||
|
||
def test_get_audit_log_events_iterator(self): | ||
res1 = { | ||
"data": [ | ||
{ | ||
"actor": { | ||
"actor_type": "user", | ||
"email": "[email protected]", | ||
"gid": "1111", | ||
"name": "Greg Sanchez" | ||
}, | ||
"context": { | ||
"api_authentication_method": "cookie", | ||
"client_ip_address": "1.1.1.1", | ||
"context_type": "web", | ||
"oauth_app_name": "string", | ||
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" | ||
}, | ||
"created_at": "2021-01-01T00:00:00.000Z", | ||
"details": {}, | ||
"event_category": "deletion", | ||
"event_type": "task_deleted", | ||
"gid": "12345", | ||
"resource": { | ||
"email": "string", | ||
"gid": "1111", | ||
"name": "Example Task", | ||
"resource_subtype": "milestone", | ||
"resource_type": "task" | ||
} | ||
} | ||
], | ||
"next_page": { | ||
"offset": "a", | ||
"path": "/workspaces/1337/audit_log_events?limit=1&offset=a", | ||
"uri": "https://app.asana.com/api/1.0/workspaces/1337/audit_log_events?limit=1&offset=a" | ||
} | ||
} | ||
res2 = { | ||
"data": [ | ||
{ | ||
"actor": { | ||
"actor_type": "user", | ||
"email": "[email protected]", | ||
"gid": "1234", | ||
"name": "Tim Bizarro" | ||
}, | ||
"context": { | ||
"api_authentication_method": "cookie", | ||
"client_ip_address": "1.1.1.1", | ||
"context_type": "web", | ||
"oauth_app_name": "string", | ||
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" | ||
}, | ||
"created_at": "2021-01-01T00:00:00.000Z", | ||
"details": {}, | ||
"event_category": "deletion", | ||
"event_type": "task_deleted", | ||
"gid": "12345", | ||
"resource": { | ||
"email": "string", | ||
"gid": "1111", | ||
"name": "Example Task", | ||
"resource_subtype": "milestone", | ||
"resource_type": "task" | ||
} | ||
} | ||
], | ||
"next_page": { | ||
"offset": "b", | ||
"path": "/workspaces/1337/audit_log_events?limit=1&offset=b", | ||
"uri": "https://app.asana.com/api/1.0/workspaces/1337/audit_log_events?limit=1&offset=b" | ||
} | ||
} | ||
res3 = { | ||
"data": [], | ||
"next_page": { | ||
"offset": "c", | ||
"path": "/workspaces/1337/audit_log_events?limit=1&offset=c", | ||
"uri": "https://app.asana.com/api/1.0/workspaces/1337/audit_log_events?limit=1&offset=c" | ||
} | ||
} | ||
res4 = { | ||
"data": [], | ||
"next_page": { | ||
"offset": "d", | ||
"path": "/workspaces/1337/audit_log_events?limit=1&offset=d", | ||
"uri": "https://app.asana.com/api/1.0/workspaces/1337/audit_log_events?limit=1&offset=d" | ||
} | ||
} | ||
responses.add(GET, 'http://app/workspaces/1337/audit_log_events?limit=1', | ||
status=200, body=json.dumps(res1), match_querystring=True) | ||
responses.add(GET, 'http://app/workspaces/1337/audit_log_events?limit=1&offset=a', | ||
status=200, body=json.dumps(res2), match_querystring=True) | ||
responses.add(GET, 'http://app/workspaces/1337/audit_log_events?limit=1&offset=b', | ||
status=200, body=json.dumps(res3), match_querystring=True) | ||
responses.add(GET, 'http://app/workspaces/1337/audit_log_events?limit=1&offset=c', | ||
status=200, body=json.dumps(res4), match_querystring=True) | ||
# Set iterator_type to 'items' to return an iterator | ||
iterator = self.client.audit_log_api.get_audit_log_events( | ||
"1337", page_size=1, iterator_type='items' | ||
) | ||
# Iterator should stop on third call | ||
self.assertEqual(next(iterator), res1['data'][0]) | ||
self.assertEqual(next(iterator), res2['data'][0]) | ||
self.assertRaises(StopIteration, next, (iterator)) |