Unauthorized Access and Retrieve Post Tests
The tests in this section verify that:- Unauthorized users cannot retrieve posts.
- Requests for non-existing posts return a 404 status code.
- Authorized users can successfully retrieve an existing post with matching attributes.
Create Post Tests
This section tests the post creation functionality using parameterization. It verifies that:- The correct HTTP status code (201) is returned.
- The post content matches the input.
- The owner ID of the post is correctly assigned.
Default Published Value Test
In the PostBase model, the “published” field defaults to True. This test confirms that when the “published” field is omitted, the system sets it to True by default.
Unauthorized Post Creation Test
This test confirms that only authorized users can create posts. Any attempt by an unauthorized user to access the post route will result in a 401 status code.Pydantic Schemas for Posts and Users
The following Pydantic schemas define the structure for posts and users used in the tests. Notice that the “published” attribute in the PostBase model defaults to True.Conclusion
At this stage, all tests related to post creation have been implemented and verified, including:- Validating unauthorized access attempts.
- Handling requests for non-existent posts.
- Confirming the correct creation of posts.
- Ensuring default values are set appropriately when omitted.
Note: Additional console warnings regarding external library deprecations, such as the
@coroutine decorator warning from aiofiles, do not affect the test outcomes.