Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: more tests for the Management Service #3

Merged
merged 1 commit into from
May 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions backend/tests/services/test_management_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import date
from werkzeug.exceptions import BadRequest

from backend.tests.conftest import BaseTestCase
from backend.tests.mocks.author_mock import author_create_mock, author_create_without_name_mock
from backend.tests.mocks.mock_utils import get_mock_with_custom_args
Expand All @@ -17,18 +19,21 @@

class TestCreateBook(BaseTestCase):
def test_should_create_book_and_its_author(self):
self.assertEqual(len(management_service.get_authors()), 0)

book = management_service.create_book(book_mock)

self.assertEqual(len(management_service.get_authors()), 1)

self.assertEqual(book.get("title"), book_mock.get("title"))
self.assertEqual(book.get("pages"), book_mock.get("pages"))

def test_should_create_book_and_find_a_created_author(self):
def test_should_throw_when_author_is_inexistent(self):
self.assertEqual(len(management_service.get_authors()), 0)

with self.assertRaises(BadRequest):
book_with_inexistent_author_mock = get_book_with_authors([{"existentAuthorId": 1}])
management_service.create_book(book_with_inexistent_author_mock)

def test_should_create_book_and_find_a_created_author(self):
author = management_service.create_author(author_mock)

self.assertIsNotNone(author.get("id"))
Expand Down
Loading