forked from dci-python-backend-assignments/tdd-class-social
-
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.
Final changes - Issue dci-python-backend-assignments#18 -Elina +Wasi
- Loading branch information
“elinamat”
committed
Jul 7, 2022
1 parent
37639a0
commit 6e8b5f5
Showing
4 changed files
with
80 additions
and
16 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
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,16 +1,40 @@ | ||
import datetime | ||
from unittest.mock import patch, Mock | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from class_social.main import app | ||
|
||
|
||
@pytest.fixture | ||
def http_test_client(): | ||
return TestClient(app) | ||
|
||
post_user = { | ||
"id": '1234', | ||
"name": 'Wasi', | ||
"username": 'wasi', | ||
"password": 'somepass', | ||
"email": 'wasi@mathias', | ||
"created_on": "2023-03-27T00:00:00.000+00:00", | ||
"is_active": True, | ||
"address": 'some address 123' | ||
} | ||
# {"w1","wasi", "123456w","[email protected]","2023-03-27T00:00:00.000+00:00",True,"Wasi","someaddress 123","wasi.co","con1","about me about me"}, # TODO a user dictionary here OR remove it completely!! | ||
|
||
|
||
valid_post = { | ||
"title": 'Our First Post', | ||
"body": 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam' \ | ||
' nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, s' \ | ||
'ed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd g' \ | ||
'ubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, ' \ | ||
'sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo' \ | ||
' duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', | ||
"creator": post_user, # TODO a user dictionary here OR remove it completely!! | ||
"creation_date": '2023-03-27T00:00:00.000+00:00', | ||
"type_of_post": 'some type' | ||
} | ||
|
||
valid_post_list = [{ | ||
'title': 'Some_title', | ||
'body': 'text_content', | ||
|
@@ -42,3 +66,15 @@ def test_given_a_nonexistent_creator_role_system_must_return_404_ok(http_test_cl | |
controller_mock.get_posts_by_creator_role = Mock(return_value=None) | ||
response = http_test_client.get('/posts/creator/anything') | ||
assert response.status_code == 404 | ||
|
||
|
||
def test_given_invalid_new_post_format_422(http_test_client): | ||
response = http_test_client.post('/posts', json={}) | ||
assert response.status_code == 422 | ||
|
||
|
||
def test_given_valid_new_post_entry_the_system_must_submit_the_post_and_return_200_ok(http_test_client): | ||
with patch('class_social.posts.post_controller') as controller_mock: | ||
controller_mock.post_a_post = Mock(return_value=None) | ||
response = http_test_client.post('/posts', json=valid_post) | ||
assert response.status_code == 200 |