Skip to content

Commit

Permalink
created test directory to test models
Browse files Browse the repository at this point in the history
  • Loading branch information
AronBuzogany committed Feb 23, 2024
1 parent bbbb9e7 commit 0802c3d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 85 deletions.
85 changes: 0 additions & 85 deletions backend/project/models/model_test.py

This file was deleted.

42 changes: 42 additions & 0 deletions backend/tests/models/conftest.py
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
10 changes: 10 additions & 0 deletions backend/tests/models/users_test.py
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()

0 comments on commit 0802c3d

Please sign in to comment.