-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint_4 #8
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
Antonidasss
wants to merge
2
commits 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 #8
Changes from all commits
Commits
Show all changes
2 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,32 @@ | ||
| # qa_python | ||
| # qa_python | ||
|
|
||
| ## Тесты | ||
|
|
||
| В проекте реализован набор автотестов на базе `pytest`, покрывающий функциональность класса `BooksCollector`. | ||
|
|
||
| ### Что проверяют тесты | ||
|
|
||
| - **Добавление книг** | ||
| - Книга добавляется в словарь только при корректной длине названия (1–40 символов). | ||
| - Одна и та же книга не может быть добавлена повторно. | ||
| - У только что добавленной книги жанр по умолчанию пустой. | ||
|
|
||
| - **Установка жанра** | ||
| - Жанр можно установить только для уже добавленной книги. | ||
| - Устанавливаются только жанры из предопределённого списка `genre`. | ||
| - При попытке установить недопустимый жанр значение жанра книги не изменяется. | ||
|
|
||
| - **Получение информации о книгах** | ||
| - Корректный возврат жанра по названию книги. | ||
| - Корректный возврат всего словаря `books_genre` с актуальными данными. | ||
| - Получение списков книг с указанным жанром. | ||
|
|
||
| - **Книги для детей** | ||
| - В список детских книг не попадают книги с жанрами из списка `genre_age_rating`. | ||
| - Книги без установленного жанра не учитываются в списке книг для детей. | ||
|
|
||
| - **Избранные книги** | ||
| - В избранное можно добавить только книгу, уже присутствующую в `books_genre`. | ||
| - Одна и та же книга не может быть добавлена в избранное повторно. | ||
| - Удаление книги из избранного возможно только при её наличии в списке. | ||
| - Корректный возврат текущего списка избранных книг. |
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,140 @@ | ||
| import pytest | ||
| from main import BooksCollector | ||
|
|
||
| # класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector | ||
| # обязательно указывать префикс Test | ||
| class TestBooksCollector: | ||
|
|
||
| # пример теста: | ||
| # обязательно указывать префикс test_ | ||
| # дальше идет название метода, который тестируем add_new_book_ | ||
| # затем, что тестируем add_two_books - добавление двух книг | ||
| def test_add_new_book_add_two_books(self): | ||
| # создаем экземпляр (объект) класса BooksCollector | ||
| collector = BooksCollector() | ||
| @pytest.fixture | ||
| def collector(): | ||
| return BooksCollector() | ||
|
|
||
| # добавляем две книги | ||
| collector.add_new_book('Гордость и предубеждение и зомби') | ||
| collector.add_new_book('Что делать, если ваш кот хочет вас убить') | ||
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
| def test_add_new_book_adds_book_without_genre(collector): | ||
| collector.add_new_book('Гарри Поттер') | ||
| assert collector.get_books_genre() == {'Гарри Поттер': ''} | ||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
|
|
||
| def test_add_new_book_adds_book_with_min_length_name(collector): | ||
| name = 'A' # длина 1 | ||
| collector.add_new_book(name) | ||
| assert name in collector.get_books_genre() | ||
|
|
||
|
|
||
| def test_add_new_book_adds_book_with_max_allowed_length_name(collector): | ||
| name = 'A' * 40 # длина 40 | ||
| collector.add_new_book(name) | ||
| assert name in collector.get_books_genre() | ||
|
|
||
|
|
||
| def test_add_new_book_not_added_if_name_too_long(collector): | ||
| long_name = 'A' * 41 | ||
| collector.add_new_book(long_name) | ||
| assert long_name not in collector.get_books_genre() | ||
|
|
||
|
|
||
| def test_add_new_book_not_added_twice(collector): | ||
| collector.add_new_book('Книга') | ||
| collector.add_new_book('Книга') | ||
| assert list(collector.get_books_genre().keys()).count('Книга') == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('genre', ['Фантастика', 'Комедии']) | ||
| def test_set_book_genre_sets_allowed_genre(collector, genre): | ||
| collector.add_new_book('Книга') | ||
| collector.set_book_genre('Книга', genre) | ||
| assert collector.get_book_genre('Книга') == genre | ||
|
|
||
|
|
||
| def test_set_book_genre_does_not_set_if_book_not_exist(collector): | ||
| collector.set_book_genre('Неизвестная книга', 'Фантастика') | ||
| assert collector.get_book_genre('Неизвестная книга') is None | ||
|
|
||
|
|
||
| def test_set_book_genre_does_not_set_if_genre_not_allowed(collector): | ||
| collector.add_new_book('Книга') | ||
| collector.set_book_genre('Книга', 'Роман') | ||
| assert collector.get_book_genre('Книга') == '' | ||
|
|
||
|
|
||
| def test_get_book_genre_returns_none_for_unknown_book(collector): | ||
| assert collector.get_book_genre('Неизвестная книга') is None | ||
|
|
||
|
|
||
| def test_get_books_with_specific_genre_returns_only_matching(collector): | ||
| collector.add_new_book('Книга 1') | ||
| collector.add_new_book('Книга 2') | ||
| collector.add_new_book('Книга 3') | ||
|
|
||
| collector.set_book_genre('Книга 1', 'Фантастика') | ||
| collector.set_book_genre('Книга 2', 'Ужасы') | ||
| collector.set_book_genre('Книга 3', 'Фантастика') | ||
|
|
||
| result = collector.get_books_with_specific_genre('Фантастика') | ||
| assert sorted(result) == ['Книга 1', 'Книга 3'] | ||
|
|
||
|
|
||
| def test_get_books_with_specific_genre_returns_empty_if_genre_not_allowed(collector): | ||
| collector.add_new_book('Книга 1') | ||
| collector.set_book_genre('Книга 1', 'Фантастика') | ||
| result = collector.get_books_with_specific_genre('Роман') | ||
| assert result == [] | ||
|
|
||
|
|
||
| def test_get_books_genre_returns_actual_dict(collector): | ||
| collector.add_new_book('Книга 1') | ||
| collector.set_book_genre('Книга 1', 'Фантастика') | ||
| assert collector.get_books_genre() == {'Книга 1': 'Фантастика'} | ||
|
|
||
|
|
||
| def test_get_books_for_children_excludes_age_restricted_genres(collector): | ||
| collector.add_new_book('Страшилки') | ||
| collector.add_new_book('Смешарики') | ||
| collector.add_new_book('Дело Пуаро') | ||
|
|
||
| collector.set_book_genre('Страшилки', 'Ужасы') | ||
| collector.set_book_genre('Смешарики', 'Мультфильмы') | ||
| collector.set_book_genre('Дело Пуаро', 'Детективы') | ||
|
|
||
| result = collector.get_books_for_children() | ||
| assert result == ['Смешарики'] | ||
|
|
||
|
|
||
| def test_get_books_for_children_ignores_books_without_genre(collector): | ||
| collector.add_new_book('Без жанра') | ||
| assert collector.get_books_for_children() == [] | ||
|
|
||
|
|
||
| def test_add_book_in_favorites_adds_only_existing_book(collector): | ||
| 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_does_not_add_if_book_not_in_collection(collector): | ||
| collector.add_book_in_favorites('Несуществующая') | ||
| assert collector.get_list_of_favorites_books() == [] | ||
|
|
||
|
|
||
| def test_add_book_in_favorites_not_added_twice(collector): | ||
| 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_removes_if_exists(collector): | ||
| collector.add_new_book('Книга') | ||
| collector.add_book_in_favorites('Книга') | ||
| collector.delete_book_from_favorites('Книга') | ||
| assert collector.get_list_of_favorites_books() == [] | ||
|
|
||
|
|
||
| def test_delete_book_from_favorites_does_nothing_if_not_in_favorites(collector): | ||
| collector.add_new_book('Книга') | ||
| collector.delete_book_from_favorites('Книга') | ||
| assert collector.get_list_of_favorites_books() == [] | ||
|
|
||
|
|
||
| def test_get_list_of_favorites_books_returns_current_list(collector): | ||
| collector.add_new_book('Книга 1') | ||
| collector.add_new_book('Книга 2') | ||
| collector.add_book_in_favorites('Книга 1') | ||
| assert collector.get_list_of_favorites_books() == ['Книга 1'] | ||
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.
Необходимо исправить: не хватает позитивных тестов на проверку границы имени книги