-
Notifications
You must be signed in to change notification settings - Fork 0
new_commit #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
GibtTanya
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
new_commit #9
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,49 @@ | ||
| # qa_python | ||
| # qa_python | ||
| ------------add_new_book----------- | ||
|
|
||
| test_add_new_book_book_added - проверяет, что книга добавляется | ||
| test_add_new_book_duplicate_not_added - проверяет, что книга не добавляется дважды | ||
| test_add_new_book_length_outside0and40_not_added - проверяет граничные значения за пределами диапазона 0-41 | ||
| test_add_new_book_length_inside0and40_added - проверяет граничные значения в пределах диапазона 0-41 | ||
|
|
||
| ------------set_book_genre----------- | ||
|
|
||
| test_set_book_genre_valid_genre_and_name_add_successully - параметризованный тест, проверяющий, что все разрешенные жанры книг успешно устанавливаются к соответствующим книгам | ||
| test_set_book_genre_invalid_genre_not_added - проверяет, что отсутствующий в списке жанров жанр не устанавилвается к книге. | ||
| test_set_book_genre_add_genre_book_not_in_collection_book_is_none - проверяет, что при добавлении жанра к несуществующей книге в коллекции, книга в коллекцию не добавляется | ||
|
|
||
| ------------get_book_genre----------- | ||
|
|
||
| test_get_book_genre_book_with_genre_correct_genre - проверяет,что кооректный жанр успешно получен у книги с жанром. | ||
| test_get_book_genre_book_without_genre_empty_string - проверяет, что у книги без жанра метод возвращает пустую строку, т.к. по умолчанию у книги вместо жанра пустая строка. | ||
|
|
||
| ------------get_books_with_specific_genre----------- | ||
|
|
||
| test_get_books_with_specific_genre_valid_genre_correct_list - проверяет, что метод возвращает корректный списк книг по указанному жанру | ||
| test_get_books_with_specific_genre_empty_collection_empty_list - проверяет, что метод возвращает пустую коллекцию, если указать отсутствующий в списке жанров жанр. | ||
| test_get_books_with_specific_genre_valid_genre_not_included_empty_list - проверяет, что метод возвращает пустую коллекцию, если указать допустимый жанр, который не прикреплен ни к одной книге в коллекции. | ||
|
|
||
| ------------get_books_genre----------- | ||
|
|
||
| test_get_books_genre_no_added_books_empty_collection - проверяет, что метод возвращает пустую коллекцию, если в нее ничего не добавлено | ||
| test_get_books_genre_collection_with_book_correct_collection - проверяет, что метод возврашает коллекцию с корректной книгой, если она в нее добавлялась | ||
|
|
||
| ------------get_books_for_children----------- | ||
|
|
||
| test_get_books_for_children_collection_with_books_for_children_correct_list - проверяет, что метод возвращает корректный список книг для детей, даже если в коллекции, есть книги, которые не подходят по возрасту. | ||
|
|
||
| ------------add_book_in_favorites----------- | ||
|
|
||
| test_add_book_in_favorites_book_from_current_collection_successfully_added - проверяет, что книга из коллекции успешно добавляется в избранное | ||
| test_add_book_in_favorites_book_already_in_favorites_not_duplicated - проверяет, что книга не добавляется в избранное дважды | ||
| test_add_book_in_favorites_book_not_in_collection_not_added - проверяет, что книга не добавляется в избранное, если ее нет в коллекции | ||
|
|
||
| ------------delete_book_from_favorites----------- | ||
|
|
||
| test_delete_book_from_favorites_book_in_favorites_deleted - проверяет, что книга успешно удаляется из избранного | ||
| test_delete_book_from_favorites_book_not_in_favorites_list_did_not_changed - проверяет, что список не ломается, при удалении из избранного книги, которой там нет. | ||
|
|
||
| ------------get_list_of_favorites_books----------- | ||
|
|
||
| test_get_list_of_favorites_books_empty_list - проверяет, что изначально список избранного пуст | ||
| test_get_list_of_favorites_books_not_empty_favorites_correct_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,24 +1,201 @@ | ||
| from main import BooksCollector | ||
| import pytest | ||
|
|
||
| # класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector | ||
| # обязательно указывать префикс Test | ||
| class TestBooksCollector: | ||
| # ------------add_new_book----------- | ||
| def test_add_new_book_book_added(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
|
|
||
| assert len(collector.get_books_genre()) == 1 | ||
|
|
||
| # пример теста: | ||
| # обязательно указывать префикс test_ | ||
| # дальше идет название метода, который тестируем add_new_book_ | ||
| # затем, что тестируем add_two_books - добавление двух книг | ||
| def test_add_new_book_add_two_books(self): | ||
| # создаем экземпляр (объект) класса BooksCollector | ||
| def test_add_new_book_duplicate_not_added(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
| collector.add_new_book('Дюна') | ||
|
|
||
| assert len(collector.get_books_genre()) == 1 | ||
|
|
||
| @pytest.mark.parametrize('name', ['', 'а' * 41,'а' * 100 ]) | ||
| def test_add_new_book_length_outside0and40_not_added(self, name): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
|
|
||
| assert len(collector.get_books_genre()) == 0 | ||
|
|
||
| @pytest.mark.parametrize('name', ['а', 'аа', 'а' * 20, 'а' * 39, 'а' * 40 ]) | ||
| def test_add_new_book_length_inside0and40_added(self, name): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
|
|
||
| assert name in collector.get_books_genre() | ||
|
|
||
| # ------------set_book_genre----------- | ||
|
|
||
| @pytest.mark.parametrize('name, genre', [['Дюна', 'Фантастика'], ['Гарри Поттер', 'Детективы'], ['Эйс Вентура', 'Комедии'],['Мгла', 'Ужасы'], ['Тачки', 'Мультфильмы']]) | ||
| def test_set_book_genre_valid_genre_and_name_add_successully(self, name, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
| collector.set_book_genre(name, genre) | ||
|
|
||
| assert collector.get_book_genre(name) == genre | ||
|
|
||
| def test_set_book_genre_invalid_genre_not_added(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
| collector.set_book_genre("Дюна", 'Приколы') | ||
|
|
||
| assert collector.get_book_genre("Дюна") == '' | ||
|
|
||
| def test_set_book_genre_add_genre_book_not_in_collection_book_is_none(self): | ||
| collector = BooksCollector() | ||
| collector.set_book_genre("Гарри Поттер", 'Фантастика') | ||
| books_collection = collector.get_books_genre() | ||
|
|
||
| assert books_collection.get('Гарри Поттер') is None | ||
|
|
||
| # добавляем две книги | ||
| collector.add_new_book('Гордость и предубеждение и зомби') | ||
| collector.add_new_book('Что делать, если ваш кот хочет вас убить') | ||
| # ------------get_book_genre----------- | ||
|
|
||
| def test_get_book_genre_book_with_genre_correct_genre(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
| collector.set_book_genre('Дюна', 'Фантастика') | ||
|
|
||
| assert collector.get_book_genre('Дюна') == 'Фантастика' | ||
|
|
||
| def test_get_book_genre_book_without_genre_empty_string(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
|
|
||
| assert collector.get_book_genre('Дюна') == '' | ||
|
|
||
| # ------------get_books_with_specific_genre----------- | ||
|
|
||
| def test_get_books_with_specific_genre_valid_genre_correct_list(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_with_specific_genre("Фантастика") == ['Дюна', 'Гарри Поттер'] | ||
|
|
||
| def test_get_books_with_specific_genre_empty_collection_empty_list(self): | ||
| collector = BooksCollector() | ||
|
|
||
| assert len(collector.get_books_with_specific_genre('Детектив')) == 0 | ||
|
|
||
| def test_get_books_with_specific_genre_invalid_genre_empty_list(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 len(collector.get_books_with_specific_genre('Приколы')) == 0 | ||
|
|
||
| def test_get_books_with_specific_genre_valid_genre_not_included_empty_list(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_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
| assert len(collector.get_books_with_specific_genre('Мультфильмы')) == 0 | ||
|
|
||
| # ------------get_books_genre----------- | ||
|
|
||
| def test_get_books_genre_no_added_books_empty_collection(self): | ||
| collector = BooksCollector() | ||
|
|
||
| assert collector.get_books_genre() == {} | ||
|
|
||
| def test_get_books_genre_collection_with_book_correct_collection(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
|
|
||
| assert collector.get_books_genre() == {'Дюна': ''} | ||
|
|
||
| # ------------get_books_for_children----------- | ||
|
|
||
| def test_get_books_for_children_collection_with_books_for_children_correct_list(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('Эйс Вентура', 'Комедии') | ||
| collection = collector.get_books_for_children() | ||
|
|
||
| assert collection == ['Дюна', 'Эйс Вентура'] | ||
|
|
||
| # ------------add_book_in_favorites----------- | ||
|
|
||
| def test_add_book_in_favorites_book_from_current_collection_successfully_added(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
| collector.add_book_in_favorites('Дюна') | ||
| favorites = collector.get_list_of_favorites_books() | ||
|
|
||
| assert favorites == ['Дюна'] | ||
|
|
||
| def test_add_book_in_favorites_book_already_in_favorites_not_duplicated(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
| collector.add_book_in_favorites('Дюна') | ||
| collector.add_book_in_favorites('Дюна') | ||
| favorites = collector.get_list_of_favorites_books() | ||
|
|
||
| assert favorites == ['Дюна'] | ||
|
|
||
| def test_add_book_in_favorites_book_not_in_collection_not_added(self): | ||
| collector = BooksCollector() | ||
| collector.add_book_in_favorites('Дюна') | ||
| favorites = collector.get_list_of_favorites_books() | ||
|
|
||
| assert 'Дюна' not in favorites | ||
|
|
||
| # ------------delete_book_from_favorites----------- | ||
|
|
||
| def test_delete_book_from_favorites_book_in_favorites_deleted(self): | ||
| collector = BooksCollector() | ||
| collector.add_book_in_favorites('Дюна') | ||
| collector.delete_book_from_favorites('Дюна') | ||
| favorites = collector.get_list_of_favorites_books() | ||
|
|
||
| assert favorites == [] | ||
|
|
||
| def test_delete_book_from_favorites_book_not_in_favorites_list_did_not_changed(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
| collector.add_book_in_favorites('Дюна') | ||
| collector.delete_book_from_favorites('Гарри Поттер') | ||
| favorites = collector.get_list_of_favorites_books() | ||
|
|
||
| assert favorites == ['Дюна'] | ||
|
|
||
| # ------------get_list_of_favorites_books----------- | ||
|
|
||
| def test_get_list_of_favorites_books_empty_list(self): | ||
| collector = BooksCollector() | ||
|
|
||
| assert collector.get_list_of_favorites_books() == [] | ||
|
|
||
|
|
||
| def test_get_list_of_favorites_books_not_empty_favorites_correct_list(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Дюна') | ||
| collector.add_book_in_favorites('Дюна') | ||
| favorites = collector.get_list_of_favorites_books() | ||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
| assert favorites == ['Дюна'] | ||
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.
Можно улучшить: по количеству символов так же хорошая параметризация