-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c52b6b
commit 68da444
Showing
2 changed files
with
20 additions
and
9 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import pytest | ||
|
||
from tests.conftest import Post | ||
from tests.conftest import Base, Post | ||
|
||
BASE_FIELDS = ('id',) | ||
POST_MODEL_FIELDS = ('id', 'title', 'content', 'created', 'updated', 'likes', 'dislikes', 'author_id', 'author') | ||
POST_SAVE_DATA = {'title': 'Another New post title.', 'content': 'POST New post content.', 'author_id': 1} | ||
|
||
class BaseTest(Base): | ||
pass | ||
|
||
def test_model_fields() -> None: | ||
for field in POST_MODEL_FIELDS: | ||
assert hasattr(Post, field) | ||
|
||
@pytest.mark.parametrize('class_, class_fields', ( | ||
(Base, BASE_FIELDS), | ||
(Post, POST_MODEL_FIELDS), | ||
)) | ||
def test_model_fields(class_, class_fields) -> None: | ||
for field in class_fields: | ||
assert hasattr(class_, field) | ||
|
||
def test_model_repr() -> None: | ||
representation = str(Post(**POST_SAVE_DATA)) | ||
for attr_name in POST_MODEL_FIELDS[1:-1]: | ||
assert representation.find(attr_name) != -1 | ||
|
||
@pytest.mark.parametrize('instance, instance_fields', ( | ||
(BaseTest(), BASE_FIELDS), | ||
(Post(**POST_SAVE_DATA), POST_MODEL_FIELDS[1:-1]), | ||
)) | ||
def test_model_repr(instance, instance_fields) -> None: | ||
for attr_name in instance_fields: | ||
assert instance.__repr__().find(attr_name) != -1 |