-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test + fixtures get_current_active_user
- Loading branch information
1 parent
8c579ba
commit 0761b45
Showing
2 changed files
with
115 additions
and
2 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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
from app.models import user as api_m | ||
from app.models.database import User as db_user | ||
from app.models.file_db import create_file_table_class, update_schema | ||
from app.models.user import UserCreate, UserInDB | ||
from app.models.user import User, UserCreate, UserInDB | ||
from app.sql_db.crud import create_user, get_db, update_is_active, update_is_admin | ||
from app.sql_db.database import Base | ||
from app.sql_db.file_crud import create_update_table, insert_data | ||
|
@@ -197,6 +197,90 @@ def mock_user(): | |
return user | ||
|
||
|
||
@pytest.fixture | ||
def mock_user_is_active(): | ||
"""Fixture for mocking a user.""" | ||
user = User( | ||
id=1, | ||
email="[email protected]", | ||
password="test1", | ||
hashed_password="test1fake_hash", | ||
is_active=True, | ||
) | ||
return user | ||
|
||
|
||
@pytest.fixture | ||
def mock_user_is_not_active(): | ||
"""Fixture for mocking a user.""" | ||
user = User( | ||
id=1, | ||
email="[email protected]", | ||
password="test1", | ||
hashed_password="test1fake_hash", | ||
is_active=False, | ||
) | ||
return user | ||
|
||
|
||
@pytest.fixture | ||
def mock_user_is_active_is_admin(): | ||
"""Fixture for mocking a user.""" | ||
user = User( | ||
id=1, | ||
email="[email protected]", | ||
password="test1", | ||
hashed_password="test1fake_hash", | ||
is_active=True, | ||
is_admin=True, | ||
) | ||
return user | ||
|
||
|
||
@pytest.fixture | ||
def mock_user_is_not_active_is_admin(): | ||
"""Fixture for mocking a user.""" | ||
user = User( | ||
id=1, | ||
email="[email protected]", | ||
password="test1", | ||
hashed_password="test1fake_hash", | ||
is_active=False, | ||
is_admin=True, | ||
) | ||
return user | ||
|
||
|
||
@pytest.fixture | ||
def mock_user_is_not_active_is_not_admin(): | ||
"""Fixture for mocking a user.""" | ||
user = User( | ||
id=1, | ||
email="[email protected]", | ||
password="test1", | ||
hashed_password="test1fake_hash", | ||
is_active=False, | ||
is_admin=False, | ||
) | ||
return user | ||
|
||
|
||
@pytest.fixture | ||
def mock_get_current_user_active(mock_user_is_active): | ||
"""Fixture for mocking get_current_user to return the mock user.""" | ||
mock_function = MagicMock() | ||
mock_function.return_value = mock_user_is_active | ||
return mock_function | ||
|
||
|
||
@pytest.fixture | ||
def mock_get_current_user_not_active(mock_user_is_not_active): | ||
"""Fixture for mocking get_current_user to return the mock user.""" | ||
mock_function = MagicMock() | ||
mock_function.return_value = mock_user_is_not_active | ||
return mock_function | ||
|
||
|
||
@pytest.fixture | ||
def mock_get_user_by_email_success(mock_user): | ||
"""Fixture for mocking get_user_by_email to return the mock 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