-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created test directory to test models
- Loading branch information
1 parent
bbbb9e7
commit 0802c3d
Showing
3 changed files
with
52 additions
and
85 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
""" | ||
""" | ||
import os | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
from project import db | ||
from project.models.users import Users | ||
from sqlalchemy.engine.url import URL | ||
from dotenv import load_dotenv | ||
import pytest | ||
|
||
load_dotenv() | ||
|
||
DATABSE_NAME = os.getenv('POSTGRES_DB') | ||
DATABASE_USER = os.getenv('POSTGRES_USER') | ||
DATABASE_PASSWORD = os.getenv('POSTGRES_PASSWORD') | ||
DATABASE_HOST = os.getenv('POSTGRES_HOST') | ||
|
||
url = URL.create( | ||
drivername="postgresql", | ||
username=DATABASE_USER, | ||
host=DATABASE_HOST, | ||
database=DATABSE_NAME, | ||
password=DATABASE_PASSWORD | ||
) | ||
|
||
engine = create_engine(url) | ||
Session = sessionmaker(bind=engine) | ||
|
||
@pytest.fixture | ||
def db_session(): | ||
db.metadata.create_all(engine) | ||
session = Session() | ||
yield session | ||
session.rollback() | ||
session.close() | ||
|
||
@pytest.fixture | ||
def valid_user(): | ||
user = Users(uid="student", is_teacher=False, is_admin=False) | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from project.models.users import Users | ||
|
||
|
||
class TestModels: | ||
"""Test class for the database models""" | ||
|
||
def test_valid_user(self, db_session, valid_user): | ||
db_session.add(valid_user) | ||
db_session.commit() | ||
assert valid_user in db_session.query(Users).all() |