Skip to content

Commit befbf02

Browse files
committed
refactor data fixtures
1 parent c98f762 commit befbf02

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

tests/fixtures/fakedata/__init__.py

Whitespace-only changes.

tests/fixtures/fakedata/posts.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
from schemas import post
4+
from schemas import user
5+
from schemas import vote
6+
from db.orm import models
7+
8+
@pytest.fixture
9+
def fake_posts() -> list[post.PostCreate]:
10+
return [
11+
post.PostCreate(title='1st title', content='1st content'),
12+
post.PostCreate(title='2st title', content='1st content'),
13+
post.PostCreate(title='3st title', content='1st content'),
14+
]
15+
16+
@pytest.fixture
17+
def fake_post_models_db(fake_posts, add_user_db) -> list[models.Post]:
18+
return [models.Post(**_post.model_dump(), owner_id=add_user_db.id)
19+
for _post in fake_posts]
20+
21+
@pytest.fixture
22+
def add_fake_posts_db(session, fake_post_models_db) -> list[models.Post]:
23+
session.add_all(fake_post_models_db)
24+
session.commit()
25+
return session.query(models.Post).all()

tests/fixtures/fakedata/users.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
3+
from schemas import post
4+
from schemas import user
5+
from schemas import vote
6+
from db.orm import models
7+
8+
@pytest.fixture
9+
def fake_emails_dict() -> list[dict[str, str]]:
10+
return [
11+
{'email': 'testuser@gmail.com',},
12+
{'email': 'cat@gmail.com',},
13+
{'email': 'dog@gmail.com',},
14+
]
15+
16+
@pytest.fixture
17+
def fake_usernames_dict() -> list[dict[str, str]]:
18+
return [
19+
{'username': 'testuser@gmail.com',},
20+
{'username': 'cat@gmail.com',},
21+
{'username': 'dog@gmail.com',},
22+
]
23+
24+
@pytest.fixture
25+
def fake_passwords_dict() -> list[dict[str, str]]:
26+
return [
27+
{'password': 'password',},
28+
{'password': 'meow',},
29+
{'password': 'wof',},
30+
]
31+
32+
@pytest.fixture
33+
def fake_users_creation_dict(
34+
fake_emails_dict,
35+
fake_passwords_dict
36+
) -> list[dict[str, str]]:
37+
return [email | password for email, password in zip(fake_emails_dict, fake_passwords_dict)]
38+
39+
@pytest.fixture
40+
def fake_users_login_dict(
41+
fake_usernames_dict,
42+
fake_passwords_dict
43+
) -> list[dict[str, str]]:
44+
return [email | password for email, password in zip(fake_usernames_dict, fake_passwords_dict)]

0 commit comments

Comments
 (0)