Create tests/test_models.py
Browse files- app/tests/test_models.py +26 -0
app/tests/test_models.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
from app.models import User, Ad, AdVersion
|
| 3 |
+
from app import db
|
| 4 |
+
|
| 5 |
+
@pytest.fixture
|
| 6 |
+
def test_user():
|
| 7 |
+
user = User(email="test@example.com")
|
| 8 |
+
user.set_password("password123")
|
| 9 |
+
return user
|
| 10 |
+
|
| 11 |
+
@pytest.fixture
|
| 12 |
+
def test_ad(test_user):
|
| 13 |
+
return Ad(content="Test ad content", user_id=test_user.id)
|
| 14 |
+
|
| 15 |
+
def test_user_creation(test_user):
|
| 16 |
+
assert test_user.email == "test@example.com"
|
| 17 |
+
assert test_user.check_password("password123")
|
| 18 |
+
|
| 19 |
+
def test_ad_creation(test_ad):
|
| 20 |
+
assert test_ad.content == "Test ad content"
|
| 21 |
+
assert test_ad.user_id is not None
|
| 22 |
+
|
| 23 |
+
def test_ad_version_creation(test_ad):
|
| 24 |
+
version = AdVersion(content="Updated ad content", ad_id=test_ad.id)
|
| 25 |
+
assert version.content == "Updated ad content"
|
| 26 |
+
assert version.ad_id == test_ad.id
|