This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for event log API (#135)
- Loading branch information
Showing
6 changed files
with
208 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
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
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,49 @@ | ||
import datetime | ||
|
||
from closeio.contrib.testing_stub import CloseIOStub | ||
|
||
|
||
class TestCloseIOStub: | ||
def test_record_and_retrieve_event_logs(self): | ||
client = CloseIOStub() | ||
|
||
task1 = client.create_task(lead_id='x1', assigned_to='y1', text='z1') | ||
client.delete_task(task_id=task1['id']) | ||
|
||
assert list(client.get_event_logs()) == [] | ||
|
||
with client.record_logs(): | ||
task2 = client.create_task(lead_id='x2', assigned_to='y2', text='z2') | ||
client.delete_task(task_id=task2['id']) | ||
pause = datetime.datetime.utcnow().isoformat() | ||
task3 = client.create_task(lead_id='x3', assigned_to='y3', text='z3') | ||
client.delete_task(task_id=task3['id']) | ||
|
||
logs = list(client.get_event_logs()) | ||
assert len(logs) == 4 | ||
assert logs[0]['action'] == 'deleted' | ||
assert logs[0]['object_id'] == task3['id'] | ||
assert logs[1]['action'] == 'created' | ||
assert logs[1]['object_id'] == task3['id'] | ||
assert logs[2]['action'] == 'deleted' | ||
assert logs[2]['object_id'] == task2['id'] | ||
assert logs[3]['action'] == 'created' | ||
assert logs[3]['object_id'] == task2['id'] | ||
|
||
logs = list(client.get_event_logs(action='created')) | ||
assert len(logs) == 2 | ||
|
||
logs = list(client.get_event_logs(action='deleted')) | ||
assert len(logs) == 2 | ||
|
||
logs = list(client.get_event_logs(object_type='task.lead')) | ||
assert len(logs) == 4 | ||
assert logs[0]['object_id'] == task3['id'] | ||
assert logs[1]['object_id'] == task3['id'] | ||
assert logs[2]['object_id'] == task2['id'] | ||
assert logs[3]['object_id'] == task2['id'] | ||
|
||
logs = list(client.get_event_logs(object_type='task.lead', date_updated__gt=pause)) | ||
assert len(logs) == 2 | ||
assert logs[0]['object_id'] == task3['id'] | ||
assert logs[1]['object_id'] == task3['id'] |
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,16 @@ | ||
from closeio.utils import paginate_via_cursor | ||
|
||
|
||
def test_paginate_via_cursor(): | ||
responses = { | ||
'': {'cursor_next': '11111', 'data': [{'id': 1}, {'id': 2}]}, | ||
'11111': {'cursor_next': '22222', 'data': [{'id': 3}, {'id': 4}]}, | ||
'22222': {'cursor_next': '', 'data': [{'id': 5}, {'id': 6}]} | ||
} | ||
|
||
def test_function(**kwargs): | ||
cursor = kwargs.get('_cursor') | ||
return responses[cursor] | ||
|
||
response = paginate_via_cursor(test_function) | ||
assert list(response) == [{'id': 1}, {'id': 2}, {'id': 3}, {'id': 4}, {'id': 5}, {'id': 6}] |