-
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
YouReMotion88
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,10 @@ | ||
| # qa_python | ||
| В этом проекте у меня получилось 12 тестов, каждый метод покрыт хотя бы одним тестом. | ||
| 1 и 2 тесты - проверяем допустимую длину названия книги, используя граничные значения | ||
| 3 и 4 тесты - проверяем, что жанр устанавливается верно. Используем параметризацию | ||
| 5 тест - проверяем корректность вывода жанра по книге. Используем параметризацию | ||
| 6 тест - проверяем корректность вывода списка книг по жанру | ||
| 7 тест - проверка вывода словаря | ||
| 8 и 9 тесты - проверяем получение книг подходящих и не подходящих детям. Используем параметризацию | ||
| 10 тест - проверяем корректность добавления книг в избранное | ||
| 11 тест - проверяем корректность удаления книг из избранного | ||
| 12 тест - проверяем корректность получения списка избранных книг |
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,182 @@ | ||
| 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 | ||
|
|
||
| # 1. Негативный тест на допустимую длину названия | ||
| def test_add_new_book_name_over_40_symbols_not_added(self): | ||
| collector = BooksCollector() | ||
| name = 's' * 41 | ||
| collector.add_new_book(name) | ||
| assert name not in collector.get_books_genre() | ||
|
|
||
| # 2. Позитивный тест на допустимую длину названия | ||
| def test_add_new_book_with_name_40_symbols_added(self): | ||
| collector = BooksCollector() | ||
| name = 's' * 40 | ||
| collector.add_new_book(name) | ||
| assert name in collector.get_books_genre() | ||
|
|
||
|
|
||
| # 3. Тест для проверки корректной установки жанра | ||
| @pytest.mark.parametrize( | ||
| 'genre', | ||
| [ | ||
| 'Фантастика', | ||
| 'Ужасы', | ||
| 'Детективы', | ||
| 'Мультфильмы', | ||
| 'Комедии' | ||
| ] | ||
| ) | ||
| def test_set_book_genre_with_valid_genre(self, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Кин-дза-дза') | ||
| collector.set_book_genre('Кин-дза-дза', genre) | ||
|
|
||
| assert collector.get_book_genre('Кин-дза-дза') == genre | ||
|
|
||
|
|
||
| # 4. Негативный тест с попыткой установить недопустимый жанр | ||
| @pytest.mark.parametrize( | ||
| 'genre', | ||
| [ | ||
| 'Эпос', | ||
| 'Научпоп', | ||
| '1984', | ||
| '' | ||
| ] | ||
| ) | ||
| def test_set_book_genre_with_invalid_genre(self, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Кин-дза-дза') | ||
| old_genre = collector.get_book_genre('Кин-дза-дза') | ||
| collector.set_book_genre('Кин-дза-дза', genre) | ||
|
|
||
| assert collector.get_book_genre('Кин-дза-дза') == old_genre | ||
|
|
||
|
|
||
| # 5. Проверка корректности вывода жанра книги по имени | ||
| @pytest.mark.parametrize( | ||
| 'genre', | ||
| [ | ||
| 'Фантастика', | ||
| 'Ужасы', | ||
| 'Детективы', | ||
| 'Мультфильмы', | ||
| 'Комедии' | ||
| ] | ||
| ) | ||
| def test_get_book_genre_returns_book_genre(self, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Кин-дза-дза') | ||
| collector.set_book_genre('Кин-дза-дза', genre) | ||
|
|
||
| assert collector.get_book_genre('Кин-дза-дза') == genre | ||
|
|
||
|
|
||
|
|
||
| # 6. Проверка вывода списка книг с определённым жанром | ||
| def test_get_books_with_specific_genre_returns_books_with_selected_genre(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('Девушка с татуировкой дракона', 'Детективы') | ||
|
|
||
| books = collector.get_books_with_specific_genre('Фантастика') | ||
| assert books == ['Кин-дза-дза'] | ||
|
|
||
|
|
||
| # 7. Проверка вывода словаря | ||
| def test_get_books_genre_returns_correct_dictionary(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book('Кин-дза-дза') | ||
| collector.add_new_book('Азазель') | ||
|
|
||
| collector.set_book_genre('Кин-дза-дза', 'Фантастика') | ||
| collector.set_book_genre('Азазель', 'Детективы') | ||
|
|
||
| expected_books_genre = { | ||
| 'Кин-дза-дза': 'Фантастика', | ||
| 'Азазель': 'Детективы' | ||
| } | ||
|
|
||
| assert collector.get_books_genre() == expected_books_genre | ||
|
|
||
| # 8. Проверяем что книги без возрастного рейтинга подходят детям | ||
| @pytest.mark.parametrize( | ||
| 'genre', | ||
| [ | ||
| 'Фантастика', | ||
| 'Мультфильмы', | ||
| 'Комедии' | ||
| ] | ||
| ) | ||
| def test_get_books_for_children_includes_allowed_genres(self, genre): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book('Кин-дза-дза') | ||
| collector.set_book_genre('Кин-дза-дза', genre) | ||
|
|
||
| books = collector.get_books_for_children() | ||
|
|
||
| assert 'Кин-дза-дза' in books | ||
|
|
||
| # 9. Проверяем что книги с возрастным рейтингом не подходят детям | ||
| @pytest.mark.parametrize( | ||
| 'genre', | ||
| [ | ||
| 'Ужасы', | ||
| 'Детективы' | ||
| ] | ||
| ) | ||
| def test_get_books_for_children_excludes_age_rating_genres(self, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Кин-дза-дза') | ||
| collector.set_book_genre('Кин-дза-дза', genre) | ||
|
|
||
| books = collector.get_books_for_children() | ||
|
|
||
| assert 'Кин-дза-дза' not in books | ||
|
|
||
|
|
||
| # 10. Проверка корректности добавления книги в избранное | ||
| def test_add_book_in_favorites_adds_book(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Кин-дза-дза') | ||
| collector.add_book_in_favorites('Кин-дза-дза') | ||
|
|
||
| assert 'Кин-дза-дза' in collector.get_list_of_favorites_books() | ||
|
|
||
|
|
||
| # 11. Проверка удаления из избранного | ||
| def test_delete_book_from_favorites_removes_book(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() | ||
|
|
||
| # 12. Проверка корректности получения списка избранных книг | ||
| def test_get_list_of_favorites_books_returns_favorites_list(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Кин-дза-дза') | ||
| collector.add_new_book('Оно') | ||
| collector.add_book_in_favorites('Кин-дза-дза') | ||
| collector.add_book_in_favorites('Оно') | ||
|
|
||
| # добавляем две книги | ||
| collector.add_new_book('Гордость и предубеждение и зомби') | ||
| collector.add_new_book('Что делать, если ваш кот хочет вас убить') | ||
| expected_favorites = ['Кин-дза-дза', 'Оно'] | ||
| assert collector.get_list_of_favorites_books() == expected_favorites | ||
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
|
|
||
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.
Можно улучшить: сначала проектируются позитивные тесты