-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint_4 #9
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
DmitryZyabikov
wants to merge
1
commit into
main
Choose a base branch
from
develop
base: main
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
Sprint_4 #9
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,15 @@ | ||
| # qa_python | ||
| 1. test_add_new_book_add_two_books – пример из шаблона, добавляет две книги и проверяет, что их две. | ||
| 2. test_add_new_book_valid_name_book_added – проверяем, что правильное название добавляется и жанр пустой. | ||
| 3. test_add_new_book_invalid_length_not_added – с помощью параметризации проверяем, что пустая строка и слишком длинное название (>40) не добавляются. | ||
| 4. test_add_new_book_duplicate_still_one – убеждаемся, что добавить одну и ту же книгу дважды нельзя. | ||
| 5. test_set_book_genre_valid_genre_set – задаём существующую книгу допустимый жанр и проверяем, что он установился. | ||
| 6. test_set_book_genre_invalid_genre_unchanged – параметризуем недопустимые жанры и смотрим, что жанр не меняется. | ||
| 7. test_set_book_genre_book_not_exists_no_change – пытаемся задать жанр книге, которой нет в списке, и проверяем, что словарь не изменился. | ||
| 8. test_get_book_genre_existing_returns_genre_and_missing_returns_none – получаем жанр у существующей книги и проверяем, что возвращается правильное значение; у отсутствующей книги должно быть None. | ||
| 9. test_get_books_with_specific_genre_matches_and_no_matches – добавляем несколько книг с разными жанрами и смотрим, что функция возвращает только те, что нужны. | ||
| 10. test_get_books_genre_returns_dict – проверяем, что возвращается весь словарь books_genre. | ||
| 11. test_get_books_for_children_returns_only_without_rating – добавляем книги с жанрами, у некоторых есть возрастной рейтинг (Ужасы, Детективы), а у некоторых нет, и проверяем, что возвращаются только те, что без рейтинга. | ||
| 12. test_add_book_in_favorites_added – добавляем книгу в избранное и проверяем, что она там есть. | ||
| 13. test_add_book_in_favorites_duplicate_still_one – пытаемся добавить одну и ту же книгу дважды в избранное, убеждаемся, что она там только один раз. | ||
| 14. test_delete_book_from_favorites_removed – добавляем в избранное, потом удаляем и проверяем, что список пуст. | ||
| 15. test_get_list_of_favorites_books_returns_ordered_list – добавляем две книги в избранное и проверяем, что список возвращается правильно. |
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from main import BooksCollector | ||
| import pytest | ||
|
|
||
| # класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector | ||
| # обязательно указывать префикс Test | ||
|
|
@@ -18,7 +19,107 @@ def test_add_new_book_add_two_books(self): | |
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
| assert len(collector.get_books_genre()) == 2 | ||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
|
|
||
| def test_add_new_book_valid_name_book_added(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Властелин колец') | ||
| assert len(collector.get_books_genre()) == 1 | ||
| assert collector.get_books_genre().get('Властелин колец') == '' | ||
|
|
||
| @pytest.mark.parametrize('name', ['', 'a' * 41]) | ||
| def test_add_new_book_invalid_length_not_added(self, name): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
| assert len(collector.get_books_genre()) == 0 | ||
|
|
||
| def test_add_new_book_duplicate_still_one(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('1984') | ||
| collector.add_new_book('1984') | ||
| assert len(collector.get_books_genre()) == 1 | ||
|
|
||
| def test_set_book_genre_valid_genre_set(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Хоббит') | ||
| collector.set_book_genre('Хоббит', 'Фантастика') | ||
| assert collector.get_book_genre('Хоббит') == 'Фантастика' | ||
|
|
||
| @pytest.mark.parametrize('genre', ['Неизвестный', '']) | ||
| def test_set_book_genre_invalid_genre_unchanged(self, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга') | ||
| collector.set_book_genre('Книга', genre) | ||
| assert collector.get_book_genre('Книга') == '' | ||
|
|
||
| def test_set_book_genre_book_not_exists_no_change(self): | ||
| collector = BooksCollector() | ||
| collector.set_book_genre('Неизвестная книга', 'Фантастика') | ||
| assert collector.get_books_genre() == {} | ||
|
|
||
| def test_get_book_genre_existing_returns_genre_and_missing_returns_none(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга') | ||
| collector.set_book_genre('Книга', 'Детективы') | ||
| assert collector.get_book_genre('Книга') == 'Детективы' | ||
| assert collector.get_book_genre('Отсутствует') is None | ||
|
|
||
| def test_get_books_with_specific_genre_matches_and_no_matches(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга А') | ||
| collector.add_new_book('Книга Б') | ||
| collector.add_new_book('Книга В') | ||
| collector.set_book_genre('Книга А', 'Комедии') | ||
| collector.set_book_genre('Книга Б', 'Комедии') | ||
| # Книга В без жанра | ||
| assert collector.get_books_with_specific_genre('Комедии') == ['Книга А', 'Книга Б'] | ||
| assert collector.get_books_with_specific_genre('Фантастика') == [] | ||
|
|
||
| def test_get_books_genre_returns_dict(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга1') | ||
| collector.add_new_book('Книга2') | ||
| expected = {'Книга1': '', 'Книга2': ''} | ||
| assert collector.get_books_genre() == expected | ||
|
|
||
| def test_get_books_for_children_returns_only_without_rating(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Сказка') | ||
| collector.add_new_book('Ужастик') | ||
| collector.add_new_book('Детектив') | ||
| collector.set_book_genre('Сказка', 'Мультфильмы') | ||
| collector.set_book_genre('Ужастик', 'Ужасы') | ||
| collector.set_book_genre('Детектив', 'Детективы') | ||
| # Мультфильмы нет возрастного рейтинга, остальные есть | ||
| assert collector.get_books_for_children() == ['Сказка'] | ||
|
|
||
| def test_add_book_in_favorites_added(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга') | ||
| collector.add_book_in_favorites('Книга') | ||
|
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. Можно лучше: не хватает теста на добавление в избранное книги которая не добавлена в коллекцию |
||
| assert collector.get_list_of_favorites_books() == ['Книга'] | ||
|
|
||
| def test_add_book_in_favorites_duplicate_still_one(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга') | ||
| collector.add_book_in_favorites('Книга') | ||
| collector.add_book_in_favorites('Книга') | ||
| assert collector.get_list_of_favorites_books() == ['Книга'] | ||
|
|
||
| def test_delete_book_from_favorites_removed(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга') | ||
| collector.add_book_in_favorites('Книга') | ||
| collector.delete_book_from_favorites('Книга') | ||
| assert collector.get_list_of_favorites_books() == [] | ||
|
|
||
| def test_get_list_of_favorites_books_returns_ordered_list(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Книга1') | ||
| collector.add_new_book('Книга2') | ||
| collector.add_book_in_favorites('Книга1') | ||
| collector.add_book_in_favorites('Книга2') | ||
| assert collector.get_list_of_favorites_books() == ['Книга1', 'Книга2'] | ||
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.
Можно лучше: не хватает позитивных тестов с проверкой границ имени книги