Add project setup some models and a test
This commit is contained in:
27
test/test_models.py
Normal file
27
test/test_models.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# tests/conftest.py
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
from allmende_payment_system.models import Base, User
|
||||
|
||||
# Create an in-memory SQLite database
|
||||
@pytest.fixture
|
||||
def in_memory_db():
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
Base.metadata.create_all(bind=engine) # Create tables
|
||||
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
# Provide a session and the engine
|
||||
db = TestingSessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_create_user(in_memory_db):
|
||||
user = User(username="test", display_name="Test User")
|
||||
in_memory_db.add(user)
|
||||
in_memory_db.commit()
|
||||
|
||||
assert user.id is not None
|
||||
Reference in New Issue
Block a user