-
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.
Merge pull request #12 from sinasezza/sinasezza
ref, test: some files refactored and test inits for user added.
- Loading branch information
Showing
9 changed files
with
148 additions
and
44 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
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,33 @@ | ||
from fastapi.security import OAuth2PasswordBearer | ||
from passlib.context import CryptContext | ||
|
||
from chatApp.config.config import get_settings | ||
|
||
settings = get_settings() | ||
|
||
# Password hashing context | ||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") | ||
|
||
# OAuth2 scheme | ||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/token") | ||
|
||
|
||
def verify_password(plain_password: str, hashed_password: str) -> bool: | ||
""" | ||
Verify if the provided password matches the stored hashed password. | ||
:param plain_password: The plain text password. | ||
:param hashed_password: The hashed password stored in the database. | ||
:return: True if passwords match, otherwise False. | ||
""" | ||
return pwd_context.verify(plain_password, hashed_password) | ||
|
||
|
||
def get_password_hash(password: str) -> str: | ||
""" | ||
Hash the given password using the password hashing context. | ||
:param password: The plain text password to hash. | ||
:return: The hashed password. | ||
""" | ||
return pwd_context.hash(password) |
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,2 +1,3 @@ | ||
[pytest] | ||
asyncio_mode = auto | ||
addopts = -p no:warnings -vv |
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,64 @@ | ||
import pytest | ||
|
||
from chatApp.config import database | ||
from chatApp.config.database import mongo_db | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
async def db(): | ||
# Initialize the test database | ||
global mongo_db | ||
print(f"mongodb is {mongo_db}") | ||
mongo_db = await database.init_mongo_db(test_db=True) | ||
yield mongo_db | ||
# Clean up the test database | ||
await database.shutdown_mongo_db() | ||
|
||
|
||
@pytest.fixture | ||
async def users_collection(db): | ||
return db.users_collection | ||
|
||
|
||
@pytest.fixture | ||
async def messages_collection(db): | ||
return db.messages_collection | ||
|
||
|
||
@pytest.fixture | ||
async def public_rooms_collection(db): | ||
return db.public_rooms_collection | ||
|
||
|
||
@pytest.fixture | ||
async def private_rooms_collection(db): | ||
return db.private_rooms_collection | ||
|
||
|
||
@pytest.fixture | ||
async def test_user(): | ||
return { | ||
"username": "test_user", | ||
"email": "test@test.com", | ||
"password": "test_password", | ||
} | ||
|
||
|
||
@pytest.fixture | ||
async def test_room(): | ||
return {"name": "test_room"} | ||
|
||
|
||
@pytest.fixture | ||
async def test_message(): | ||
return {"sender": "test_user", "text": "test_message"} | ||
|
||
|
||
@pytest.fixture | ||
async def test_private_room(): | ||
return {"name": "test_private_room", "users": ["test_user"]} | ||
|
||
|
||
@pytest.fixture | ||
async def test_public_room(): | ||
return {"name": "test_public_room"} |
Empty file.