-
Notifications
You must be signed in to change notification settings - Fork 37
Sprint4 #26
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
Open
llorichT
wants to merge
4
commits into
yandex-praktikum:develop
Choose a base branch
from
llorichT:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sprint4 #26
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,86 +4,96 @@ | |
|
|
||
| class TestBooksCollector: | ||
|
|
||
| def test_initial_state(self): | ||
| def test_add_new_book(self): | ||
| collector = BooksCollector() | ||
| assert collector.get_books_genre() == {} and collector.get_list_of_favorites_books() == [] | ||
| collector.add_new_book('1984') | ||
|
|
||
| def test_add_new_book_correct_add_book_successful_add(self): | ||
| assert '1984' in collector.get_books_genre() | ||
|
|
||
| def test_add_same_book_twice(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| assert collector.get_book_genre('Азбука') == '' | ||
| collector.add_new_book('1984') | ||
| collector.add_new_book('1984') | ||
|
|
||
| assert len(collector.get_books_genre()) == 1 | ||
|
|
||
| @pytest.mark.parametrize("name, expected_count", [ | ||
| ('Азбука', 1), | ||
| ('', 0), | ||
| ('Азбука' * 10, 0) | ||
| @pytest.mark.parametrize('name', [ | ||
| '', | ||
| 'a' * 41 | ||
| ]) | ||
| def test_add_new_book_incorrect_add_book_unsuccessful_add(self, name, expected_count): | ||
| def test_add_book_invalid_name(self, name): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
| assert len(collector.get_books_genre()) == expected_count | ||
|
|
||
| def test_set_book_genre_correct_genre_success(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| collector.set_book_genre('Азбука', 'Ужасы') | ||
| assert collector.books_genre['Азбука'] == 'Ужасы' | ||
| assert len(collector.get_books_genre()) == 0 | ||
|
|
||
| def test_set_book_genre_incorrect_genre_unsuccess(self): | ||
| def test_set_book_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| collector.set_book_genre('Азбука', 'FFFFFF') | ||
| assert collector.books_genre['Азбука'] == '' | ||
| collector.add_new_book('1984') | ||
| collector.set_book_genre('1984', 'Фантастика') | ||
|
|
||
| def test_get_book_genre(self): | ||
| assert collector.get_book_genre('1984') == 'Фантастика' | ||
|
|
||
| def test_set_invalid_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| collector.set_book_genre('Азбука', 'Ужасы') | ||
| assert collector.get_book_genre('Азбука') == 'Ужасы' | ||
| collector.add_new_book('1984') | ||
| collector.set_book_genre('1984', 'Роман') | ||
|
|
||
| assert collector.get_book_genre('1984') == '' | ||
|
|
||
| def test_get_books_with_specific_genre(self): | ||
| collector = BooksCollector() | ||
| books = ['Азбука', 'Алгебра', 'Маленький принц'] | ||
| for book in books: | ||
| collector.add_new_book(book) | ||
| collector.set_book_genre(book, 'Ужасы') | ||
|
|
||
| collector.add_new_book('Ну погоди') | ||
| collector.set_book_genre('Ну погоди', 'Мультфильмы') | ||
| collector.add_new_book('1984') | ||
| collector.set_book_genre('1984', 'Фантастика') | ||
|
|
||
| assert collector.get_books_with_specific_genre('Ужасы') == books | ||
| result = collector.get_books_with_specific_genre('Фантастика') | ||
|
|
||
| def test_get_books_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| assert collector.get_books_genre() == {'Азбука': ''} | ||
| assert '1984' in result | ||
|
|
||
| def test_get_books_for_children(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Детская') | ||
| collector.add_new_book('Взрослая') | ||
| collector.set_book_genre('Детская', 'Фантастика') | ||
| collector.set_book_genre('Взрослая', 'Ужасы') | ||
| collector.add_new_book('1984') | ||
| collector.set_book_genre('1984', 'Фантастика') | ||
|
|
||
| collector.add_new_book('Оно') | ||
| collector.set_book_genre('Оно', 'Ужасы') | ||
|
|
||
| assert collector.get_books_for_children() == ['Детская'] | ||
| result = collector.get_books_for_children() | ||
|
|
||
| assert '1984' in result | ||
| assert 'Оно' not in result | ||
|
|
||
| def test_add_book_in_favorites(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| collector.add_book_in_favorites('Азбука') | ||
| assert collector.get_list_of_favorites_books() == ['Азбука'] | ||
| collector.add_new_book('1984') | ||
| collector.add_book_in_favorites('1984') | ||
|
|
||
| assert '1984' in collector.get_list_of_favorites_books() | ||
|
|
||
| def test_add_nonexistent_book_to_favorites(self): | ||
| collector = BooksCollector() | ||
| collector.add_book_in_favorites('1984') | ||
|
|
||
| assert len(collector.get_list_of_favorites_books()) == 0 | ||
|
|
||
| def test_delete_book_from_favorites(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| collector.add_book_in_favorites('Азбука') | ||
| collector.delete_book_from_favorites('Азбука') | ||
| assert collector.get_list_of_favorites_books() == [] | ||
| collector.add_new_book('1984') | ||
| collector.add_book_in_favorites('1984') | ||
| collector.delete_book_from_favorites('1984') | ||
|
|
||
| def test_get_list_of_favorites_books(self): | ||
| assert '1984' not in collector.get_list_of_favorites_books() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нужно исправить: отсутствуют тесты на проверку метода get_books_genre и get_book_genre. На каждый метод должен быть отдельный тест, вне зависимости, вызывается он в других тестах или нет |
||
|
|
||
| def test_get_books_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Азбука') | ||
| collector.add_new_book('Алгебра') | ||
| collector.add_book_in_favorites('Азбука') | ||
| collector.add_book_in_favorites('Алгебра') | ||
| assert collector.get_list_of_favorites_books() == ['Азбука', 'Алгебра'] | ||
| collector.add_new_book('1984') | ||
|
|
||
| assert collector.get_books_genre() == {'1984': ''} | ||
|
|
||
|
|
||
| def test_get_book_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('1984') | ||
| collector.set_book_genre('1984', 'Фантастика') | ||
|
|
||
| assert collector.get_book_genre('1984') == 'Фантастика' | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично: удачное применение параметризации, протестированы разные граничные значения для длины имени