Skip to content

Commit

Permalink
Add audit log to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mesozoic committed Jan 21, 2024
1 parent 1c54a2c commit bc419d2
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 26 deletions.
8 changes: 8 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ API: pyairtable.models
:inherited-members: AirtableModel


API: pyairtable.models.audit
********************************

.. automodule:: pyairtable.models.audit
:members:
:inherited-members: AirtableModel


API: pyairtable.models.schema
********************************

Expand Down
29 changes: 29 additions & 0 deletions docs/source/enterprise.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. include:: _substitutions.rst
.. include:: _warn_latest.rst

Enterprise Features
==============================


pyAirtable exposes a number of classes and methods for interacting with enterprise organizations.
The following methods are only available on an `Enterprise plan <https://airtable.com/pricing>`__.
If you call one of them against a base that is not part of an enterprise workspace, Airtable will
return a 404 error, and pyAirtable will add a reminder to the exception to check your billing plan.

.. automethod:: pyairtable.Api.enterprise
:noindex:

.. automethod:: pyairtable.Base.collaborators
:noindex:

.. automethod:: pyairtable.Base.shares
:noindex:

.. automethod:: pyairtable.Workspace.collaborators
:noindex:

.. automethod:: pyairtable.Enterprise.info
:noindex:

.. automethod:: pyairtable.Enterprise.iterate_audit_log
:noindex:
5 changes: 3 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ pyAirtable
getting-started
tables
orm
webhooks
metadata
migrations
webhooks
enterprise
api


.. toctree::
:caption: More
:hidden:

migrations
about
changelog
contributing
Expand Down
24 changes: 0 additions & 24 deletions docs/source/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,6 @@ You'll find more detail in the API reference for :mod:`pyairtable.models.schema`
:noindex:


Enterprise information
-----------------------------

pyAirtable exposes a number of classes and methods for interacting with enterprise organizations.
The following methods are only available on an `Enterprise plan <https://airtable.com/pricing>`__.
If you call one of them against a base that is not part of an enterprise workspace, Airtable will
return a 404 error, and pyAirtable will add a reminder to the exception to check your billing plan.

.. automethod:: pyairtable.Api.enterprise
:noindex:

.. automethod:: pyairtable.Base.collaborators
:noindex:

.. automethod:: pyairtable.Base.shares
:noindex:

.. automethod:: pyairtable.Workspace.collaborators
:noindex:

.. automethod:: pyairtable.Enterprise.info
:noindex:


Modifying existing schema
-----------------------------

Expand Down
3 changes: 3 additions & 0 deletions docs/source/webhooks.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.. include:: _substitutions.rst
.. include:: _warn_latest.rst

Webhooks
==============================

Expand Down
14 changes: 14 additions & 0 deletions pyairtable/models/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@


class AuditLogResponse(AirtableModel):
"""
Represents a page of audit log events.
See `Audit log events <https://airtable.com/developers/web/api/audit-log-events>`__
for more information on how to interpret this data structure.
"""

events: List["AuditLogEvent"]
pagination: Optional["AuditLogResponse.Pagination"] = None

Expand All @@ -15,6 +22,13 @@ class Pagination(AirtableModel):


class AuditLogEvent(AirtableModel):
"""
Represents a single audit log event.
See `Audit log events <https://airtable.com/developers/web/api/audit-log-events>`__
for more information on how to interpret this data structure.
"""

id: str
timestamp: str
action: str
Expand Down
24 changes: 24 additions & 0 deletions tests/test_api_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def test_group(enterprise, enterprise_mocks):
],
)
def test_audit_log(enterprise, fncall, expected_size):
"""
Test that we iterate through multiple pages of the audit log. correctly
"""
events = [
event
for page in enterprise.iterate_audit_log(*fncall.args, **fncall.kwargs)
Expand All @@ -144,6 +147,23 @@ def test_audit_log(enterprise, fncall, expected_size):
assert len(events) == expected_size


def test_audit_log__no_loop(enterprise, requests_mock):
"""
Test that an empty page of events does not cause an infinite loop.
"""
requests_mock.get(
enterprise.api.build_url(
f"meta/enterpriseAccounts/{enterprise.id}/auditLogEvents"
),
json={
"events": [],
"pagination": {"previous": "dummy"},
},
)
events = [event for page in enterprise.iterate_audit_log() for event in page.events]
assert len(events) == 0


@pytest.mark.parametrize(
"fncall,sortorder,offset_field",
[
Expand All @@ -159,6 +179,10 @@ def test_audit_log__sortorder(
sortorder,
offset_field,
):
"""
Test that we calculate sortorder and offset_field correctly
dpeending on whether we're ascending or descending.
"""
with patch.object(api, "iterate_requests", wraps=api.iterate_requests) as m:
list(enterprise.iterate_audit_log(*fncall.args, **fncall.kwargs))

Expand Down

0 comments on commit bc419d2

Please sign in to comment.