-
Notifications
You must be signed in to change notification settings - Fork 37
Sprint_4 #29
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
asajevelina-dot
wants to merge
3
commits into
yandex-praktikum:main
Choose a base branch
from
asajevelina-dot: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 #29
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,21 @@ | ||
| # qa_python | ||
| # Тесты для BooksCollector | ||
|
|
||
| ## Реализованные тесты | ||
|
|
||
| 1. **test_add_new_book_add_two_books** — проверка добавления двух книг | ||
| 2. **test_add_new_book_valid_name** — добавление книги с валидным названием | ||
| 3. **test_add_new_book_invalid_name** — проверка невалидных названий (параметризация: строка >40 символов, пустая строка) | ||
| 4. **test_add_new_book_duplicate** — дубликат книги не добавляется | ||
| 5. **test_set_book_genre** — установка жанра книге | ||
| 6. **test_set_book_genre_invalid_genre** — нельзя установить несуществующий жанр | ||
| 7. **test_get_book_genre** — получение жанра по названию книги | ||
| 8. **test_get_books_with_specific_genre** — получение списка книг определённого жанра | ||
| 9. **test_get_books_for_children_includes_children_books** — детские книги попадают в список для детей | ||
| 10. **test_get_books_for_children_excludes_age_restricted_books** — книги с возрастным рейтингом не попадают в список для детей | ||
| 11. **test_add_book_in_favorites** — добавление книги в избранное | ||
| 12. **test_delete_book_from_favorites** — удаление книги из избранного | ||
|
|
||
| ## Запуск тестов | ||
|
|
||
| ```bash | ||
| pytest -v tests.py |
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,24 +1,91 @@ | ||
| from main import BooksCollector | ||
| import pytest | ||
|
|
||
| # класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector | ||
| # обязательно указывать префикс Test | ||
| class TestBooksCollector: | ||
|
|
||
| # пример теста: | ||
| # обязательно указывать префикс test_ | ||
| # дальше идет название метода, который тестируем add_new_book_ | ||
| # затем, что тестируем add_two_books - добавление двух книг | ||
| # пример теста | ||
| def test_add_new_book_add_two_books(self): | ||
| # создаем экземпляр (объект) класса BooksCollector | ||
| collector = BooksCollector() | ||
|
|
||
| # добавляем две книги | ||
| collector.add_new_book('Гордость и предубеждение и зомби') | ||
| collector.add_new_book('Что делать, если ваш кот хочет вас убить') | ||
| assert len(collector.get_books_genre()) == 2 | ||
|
|
||
| # 1. Добавление книги с валидным названием | ||
| def test_add_new_book_valid_name(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Война и мир") | ||
| assert "Война и мир" in collector.get_books_genre() | ||
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
| # 2. Невалидные названия (параметризация) | ||
| @pytest.mark.parametrize("name", ["A"*41, ""]) | ||
| def test_add_new_book_invalid_name(self, name): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
| assert name not in collector.get_books_genre() | ||
|
|
||
| # 3. Дубликат не добавляется | ||
| def test_add_new_book_duplicate(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Дубликат") | ||
| collector.add_new_book("Дубликат") | ||
| assert len(collector.get_books_genre()) == 1 | ||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
| # 4. Установка жанра | ||
| def test_set_book_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Гарри Поттер") | ||
| collector.set_book_genre("Гарри Поттер", "Фантастика") | ||
| assert collector.get_book_genre("Гарри Поттер") == "Фантастика" | ||
|
|
||
| # 5. Нельзя установить несуществующий жанр | ||
| def test_set_book_genre_invalid_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Тест") | ||
| collector.set_book_genre("Тест", "Роман") | ||
| assert collector.get_book_genre("Тест") == "" | ||
|
|
||
| # 6. Получение жанра | ||
| def test_get_book_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Книга") | ||
| collector.set_book_genre("Книга", "Детективы") | ||
| assert collector.get_book_genre("Книга") == "Детективы" | ||
|
|
||
| # 7. Список книг по жанру | ||
| def test_get_books_with_specific_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Ужасная книга") | ||
| collector.set_book_genre("Ужасная книга", "Ужасы") | ||
| result = collector.get_books_with_specific_genre("Ужасы") | ||
| assert "Ужасная книга" in result | ||
|
|
||
| # 8а. Книги для детей: детские книги попадают в список | ||
| def test_get_books_for_children_includes_children_books(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Детская книга") | ||
| collector.set_book_genre("Детская книга", "Мультфильмы") | ||
| children_books = collector.get_books_for_children() | ||
| assert "Детская книга" in children_books | ||
|
|
||
| # 8б. Книги для детей: книги с возрастным рейтингом не попадают в список | ||
| def test_get_books_for_children_excludes_age_restricted_books(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Страшная книга") | ||
| collector.set_book_genre("Страшная книга", "Ужасы") | ||
| children_books = collector.get_books_for_children() | ||
| assert "Страшная книга" not in children_books | ||
|
|
||
| # 9. Добавление в избранное | ||
| def test_add_book_in_favorites(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Любимая книга") | ||
| collector.add_book_in_favorites("Любимая книга") | ||
| assert "Любимая книга" in collector.get_list_of_favorites_books() | ||
|
|
||
| # 10. Удаление из избранного | ||
| def test_delete_book_from_favorites(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book("Книга") | ||
| collector.add_book_in_favorites("Книга") | ||
| collector.delete_book_from_favorites("Книга") | ||
| assert "Книга" not in collector.get_list_of_favorites_books() | ||
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.
Нужно исправить: стоит соблюдать правило атомарности и не проверять позитивный и негативный аспекты метода в одном тесте. Стоит разделить