-
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
aporguneva
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 #8
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
Binary file not shown.
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 |
|---|---|---|
|
|
@@ -4,21 +4,171 @@ | |
| # обязательно указывать префикс Test | ||
| class TestBooksCollector: | ||
|
|
||
| # пример теста: | ||
| # обязательно указывать префикс test_ | ||
| # дальше идет название метода, который тестируем add_new_book_ | ||
| # затем, что тестируем add_two_books - добавление двух книг | ||
| def test_add_new_book_add_two_books(self): | ||
| # создаем экземпляр (объект) класса BooksCollector | ||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
|
|
||
|
|
||
| #Мои тесты | ||
| #Метод add_new_book | ||
| #Добавление книги в словарь | ||
| def test_add_new_book_add_one_book(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| #Провереям, что книга добавилась в словарь | ||
| assert "Колобок" in collector.get_books_genre() | ||
|
|
||
| #Название книги не превышает 40 символов | ||
| def test_add_new_book_name_too_long(self): | ||
| collector = BooksCollector() | ||
|
|
||
| # добавляем две книги | ||
| collector.add_new_book('Гордость и предубеждение и зомби') | ||
| collector.add_new_book('Что делать, если ваш кот хочет вас убить') | ||
| long_name = "A" * 41 | ||
| collector.add_new_book(long_name) | ||
| #Провереям, что книга не добавилась | ||
| assert long_name not in collector.get_books_genre() | ||
|
|
||
| #Добавляем одну и ту же книгу дважды | ||
| def test_add_new_book_duplicate(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.add_new_book("Колобок") | ||
| #Провереям, что книга добавилась только один раз | ||
| assert len(collector.get_books_genre()) == 1 | ||
|
|
||
|
|
||
| #Метод set_book_genre | ||
| #Устанавливаем существующтй жанр cуществующей книге | ||
| def test_set_book_genre_valid(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.set_book_genre("Колобок", "Фантастика") | ||
| #Проверяем название и жанр в словаре | ||
| assert collector.books_genre["Колобок"] == "Фантастика" | ||
|
|
||
| #Устанавливаем НЕ существующий жанр cуществующей книге | ||
| def test_set_book_genre_invalid(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.set_book_genre("Колобок", "Неизвестно") | ||
| #Проверяем, что жанр не установился | ||
| assert collector.books_genre["Колобок"] == "" | ||
|
|
||
| #Устанавливаем существующий жанр НЕ существующий книге | ||
| def test_set_book_genre_name_unknown(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.set_book_genre("Неизвестная", "Фантастика") | ||
| #Проверяем, что книга не появилась в словаре | ||
| assert "Неизвестная" not in collector.books_genre | ||
|
|
||
|
|
||
| #Метод get_book_genre | ||
| #Получаем жанр существующей книги | ||
| def test_get_book_genre_returns_genre(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.set_book_genre("Колобок", "Фантастика") | ||
| #Проверяем, что get_book_genre выводит верный жанр | ||
| assert collector.get_book_genre("Колобок") == "Фантастика" | ||
|
|
||
| #Метод get_books_with_specific_genre | ||
| #Вывод книг с определенным жанром | ||
| def test_get_books_with_specific_genre(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.set_book_genre("Колобок", "Фантастика") | ||
| collector.add_new_book("Буратино") | ||
| collector.set_book_genre("Буратино", "Фантастика") | ||
|
|
||
| books = collector.get_books_with_specific_genre("Фантастика") | ||
| assert set(books) == {"Колобок", "Буратино"} | ||
|
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. можно улучшить: метод нужен, чтобы выбирать нужные книги, а в тесте возвращаются все |
||
|
|
||
| #Метод get_books_genre | ||
| #Вывод текущего словаря | ||
| def test_get_books_genre_correct(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.set_book_genre("Колобок", "Комедии") | ||
| collector.add_new_book("Буратино") | ||
| collector.set_book_genre("Буратино", "Фантастика") | ||
| books_genre = collector.get_books_genre() | ||
|
|
||
| assert books_genre == {"Колобок": "Комедии", | ||
| "Буратино": "Фантастика"} | ||
|
|
||
|
|
||
|
|
||
| #Метод get_books_for_children | ||
| def test_get_books_for_children(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.set_book_genre("Колобок", "Комедии") | ||
| collector.add_new_book("Буратино") | ||
| collector.set_book_genre("Буратино", "Ужасы") | ||
|
|
||
| assert collector.get_books_for_children() == ["Колобок"] | ||
|
|
||
|
|
||
| #Метод add_book_in_favorites | ||
| #Добавляем книгу в избранное | ||
| def test_add_book_in_favorites_added(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.add_book_in_favorites("Колобок") | ||
| assert "Колобок" in collector.favorites | ||
|
|
||
| #Добавляем НЕ существующую книгу в избранное | ||
| def test_add_book_in_favorites_name_unknown(self): | ||
| collector = BooksCollector() | ||
| collector.add_book_in_favorites("Неизвестно") | ||
| assert "Неизвестно" not in collector.favorites | ||
|
|
||
| #Добавляем одну и ту же книгу в избранное дважды | ||
| def test_add_book_in_favorites_name_duplicate(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.add_book_in_favorites("Колобок") | ||
| collector.add_book_in_favorites("Колобок") | ||
| assert collector.favorites.count("Колобок") == 1 | ||
|
|
||
| #Метод delete_book_from_favorites | ||
| #Удаляем книгу из избранного | ||
| def test_delete_book_from_favorites_deleted(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.add_book_in_favorites("Колобок") | ||
| collector.delete_book_from_favorites("Колобок") | ||
| assert "Колобок" not in collector.favorites | ||
|
|
||
| #Метод get_list_of_favorites_books | ||
| #Получаем список избранных книг | ||
| def test_get_list_of_favorites_books(self): | ||
| collector = BooksCollector() | ||
|
|
||
| collector.add_new_book("Колобок") | ||
| collector.add_book_in_favorites("Колобок") | ||
| assert collector.get_list_of_favorites_books() == ["Колобок"] | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь 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.
Можно улучшить: общее для всех тестов предусловие можно вынести в фикстуру