-
-
Notifications
You must be signed in to change notification settings - Fork 138
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 #287 from mesozoic/collaborator_model
Introduce "Collaborator" model
- Loading branch information
Showing
10 changed files
with
94 additions
and
24 deletions.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from .collaborator import Collaborator | ||
from .comment import Comment | ||
|
||
__all__ = [ | ||
"Collaborator", | ||
"Comment", | ||
] |
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,26 @@ | ||
from typing import Optional | ||
|
||
from typing_extensions import TypeAlias | ||
|
||
from ._base import AirtableModel | ||
|
||
UserId: TypeAlias = str | ||
|
||
|
||
class Collaborator(AirtableModel): | ||
""" | ||
Represents an Airtable user being passed from the API. | ||
This is only used in contexts involving other models (e.g. :class:`~pyairtable.models.Comment`). | ||
In contexts where API values are returned as ``dict``, we will return | ||
collaborator information as a ``dict`` as well. | ||
""" | ||
|
||
#: Airtable's unique ID for the user, in the format ``usrXXXXXXXXXXXXXX``. | ||
id: UserId | ||
|
||
#: The email address of the user. | ||
email: Optional[str] | ||
|
||
#: The display name of the user. | ||
name: Optional[str] |
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,29 @@ | ||
import pytest | ||
|
||
from pyairtable.models import Collaborator | ||
|
||
fake_user_data = { | ||
"id": "usr000000fakeuser", | ||
"email": "fake@example.com", | ||
"name": "Fake User", | ||
} | ||
|
||
|
||
def test_parse(): | ||
user = Collaborator.parse_obj(fake_user_data) | ||
assert user.id == fake_user_data["id"] | ||
assert user.email == fake_user_data["email"] | ||
assert user.name == fake_user_data["name"] | ||
|
||
|
||
def test_init(): | ||
c = Collaborator(id="usrXXXXXXXXXXXXX") | ||
assert c.id == "usrXXXXXXXXXXXXX" | ||
assert c.email is None | ||
assert c.name is None | ||
|
||
with pytest.raises(ValueError): | ||
Collaborator() | ||
|
||
with pytest.raises(ValueError): | ||
Collaborator(name="Fake User") |
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