-
Notifications
You must be signed in to change notification settings - Fork 363
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
1 parent
8b42191
commit a33aef2
Showing
3 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
from datetime import datetime | ||
|
||
from backend.config.tools import ToolName | ||
from backend.crud import tool_auth as tool_auth_crud | ||
from backend.database_models.tool_auth import ToolAuth | ||
from backend.tests.unit.factories import get_factory | ||
|
||
def test_create_tool_auth(session, user): | ||
|
||
tool_auth_data = ToolAuth( | ||
user_id = user.id, | ||
tool_id = ToolName.Google_Drive, | ||
token_type = "Bearer", | ||
encrypted_access_token = bytes(b'foobar'), | ||
encrypted_refresh_token = bytes(b'foobar'), | ||
expires_at = datetime.strptime("12/31/2124 00:00:00", '%m/%d/%Y %H:%M:%S'), | ||
created_at = datetime.strptime("01/01/2000 00:00:00", '%m/%d/%Y %H:%M:%S'), | ||
updated_at = datetime.strptime("01/01/2010 00:00:00", '%m/%d/%Y %H:%M:%S') | ||
) | ||
|
||
tool_auth = tool_auth_crud.create_tool_auth( | ||
session, tool_auth_data | ||
) | ||
|
||
assert tool_auth.user_id == tool_auth_data.user_id | ||
assert tool_auth.tool_id == tool_auth_data.tool_id | ||
assert tool_auth.token_type == tool_auth_data.token_type | ||
assert tool_auth.encrypted_access_token == tool_auth_data.encrypted_access_token | ||
assert tool_auth.encrypted_refresh_token == tool_auth_data.encrypted_refresh_token | ||
assert tool_auth.expires_at == tool_auth_data.expires_at | ||
assert tool_auth.id == tool_auth_data.id | ||
assert tool_auth.created_at == tool_auth_data.created_at | ||
assert tool_auth.updated_at == tool_auth_data.updated_at | ||
|
||
def test_delete_tool_auth_by_tool_id(session, user): | ||
tool_auth = get_factory("ToolAuth", session).create( | ||
user_id = user.id, | ||
tool_id = ToolName.Google_Drive, | ||
token_type = "Bearer", | ||
encrypted_access_token = bytes(b'foobar'), | ||
encrypted_refresh_token = bytes(b'foobar'), | ||
expires_at = datetime.strptime("12/31/2124 00:00:00", '%m/%d/%Y %H:%M:%S'), | ||
created_at = datetime.strptime("01/01/2000 00:00:00", '%m/%d/%Y %H:%M:%S'), | ||
updated_at = datetime.strptime("01/01/2010 00:00:00", '%m/%d/%Y %H:%M:%S') | ||
) | ||
|
||
tool_auth_crud.delete_tool_auth( | ||
session, user.id, tool_auth.tool_id | ||
) | ||
|
||
tool_auth = tool_auth_crud.get_tool_auth( | ||
session, tool_auth.tool_id, user.id | ||
) | ||
assert tool_auth is None |
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,21 @@ | ||
import factory | ||
from datetime import datetime | ||
|
||
from backend.database_models.tool_auth import ToolAuth | ||
from backend.config.tools import ToolName | ||
|
||
from .base import BaseFactory | ||
|
||
|
||
class ToolAuthFactory(BaseFactory): | ||
class Meta: | ||
model = ToolAuth | ||
|
||
user_id = factory.Faker("uuid4") | ||
tool_id = ToolName.Google_Drive | ||
token_type = "Bearer" | ||
encrypted_access_token = bytes(b'foobar') | ||
encrypted_refresh_token = bytes(b'foobar') | ||
expires_at = datetime.strptime("12/31/2124 00:00:00", '%m/%d/%Y %H:%M:%S') | ||
created_at = datetime.strptime("01/01/2000 00:00:00", '%m/%d/%Y %H:%M:%S') | ||
updated_at = datetime.strptime("01/01/2010 00:00:00", '%m/%d/%Y %H:%M:%S') |