-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
106 additions
and
20 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,37 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from pydantic import root_validator | ||
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: Optional[UserId] | ||
|
||
#: The email address of the user. | ||
email: Optional[str] | ||
|
||
#: The display name of the user. | ||
name: Optional[str] | ||
|
||
@root_validator | ||
@classmethod | ||
def check_has_id_or_email(cls, values: Dict[Any, Any]) -> Dict[Any, Any]: | ||
""" | ||
:meta private: | ||
""" | ||
if not (values.get("id") or values.get("email")): | ||
raise ValueError("id or email is required") | ||
return values |
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,34 @@ | ||
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", name="Fake User") | ||
assert c.id == "usrXXXXXXXXXXXXX" | ||
assert c.email is None | ||
assert c.name == "Fake User" | ||
|
||
c = Collaborator(email="fake@example.com") | ||
assert c.id is None | ||
assert c.email == "fake@example.com" | ||
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