-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint_4 #6
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
base: main
Are you sure you want to change the base?
Sprint_4 #6
Changes from all commits
add42f3
0b841af
c7cf98b
a4a26fa
31a08f6
70580a9
f17f0aa
b946b74
12d7731
24c8db1
ed2751e
4513959
418235c
4583289
9c18f57
b2f364c
9388abc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,98 @@ | ||
| from main import BooksCollector | ||
|
|
||
| # класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector | ||
| # обязательно указывать префикс Test | ||
| import pytest | ||
| 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 | ||
|
|
||
| def test_add_new_book_add_two__equal_books_failed(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Джейн Эйр') | ||
| collector.add_new_book('Джейн Эйр') | ||
| assert len(collector.get_books_genre()) == 1 | ||
|
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_add_new_book_len_more_than_40_failed(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Сказка о царе Салтане, о сыне его славном и могучем богатыре князе Гвидоне Салтановиче и о прекрасной Царевне Лебеди') | ||
| assert len(collector.get_books_genre()) == 0 | ||
|
|
||
| def test_add_book_in_favorites_sucсess(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Преступление и наказание') | ||
| collector.add_book_in_favorites('Преступление и наказание') | ||
| assert len(collector.get_list_of_favorites_books()) == 1 | ||
|
|
||
| def test_add_book_in_favorites_two_equal_books_failed(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Виола Тараканова') | ||
| collector.add_book_in_favorites('Виола Тараканова') | ||
| collector.add_book_in_favorites('Виола Тараканова') | ||
| assert len(collector.get_list_of_favorites_books()) == 1 | ||
|
|
||
| def test_delete_book_from_favorites_success(self): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Сказка о золотой рыбке') | ||
| collector.add_book_in_favorites('Сказка о золотой рыбке') | ||
| collector.delete_book_from_favorites('Сказка о золотой рыбке') | ||
| assert len(collector.get_list_of_favorites_books()) == 0 | ||
|
|
||
| @pytest.mark.parametrize('genre', ['Фантастика', 'Ужасы', 'Детективы', 'Мультфильмы', 'Комедии']) | ||
| def test_set_book_genre_in_list_success(self, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Бегущий по лезвию') | ||
| collector.set_book_genre('Бегущий по лезвию', genre) | ||
| assert collector.get_book_genre('Бегущий по лезвию') == genre | ||
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
| @pytest.mark.parametrize('genre_not_inlist', ['Триллер', 'Мелодрама']) | ||
| def test_set_book_genre_not_inlist_failed(self, genre_not_inlist): | ||
| collector = BooksCollector() | ||
| collector.add_new_book('Поющие в терновнике') | ||
| collector.set_book_genre('Поющие в терновнике', genre_not_inlist) | ||
| assert collector.get_book_genre('Поющие в терновнике') != genre_not_inlist | ||
|
|
||
| @pytest.mark.parametrize('name,genre', [ | ||
| ['Заживо в темноте', 'Ужасы'], | ||
| ['Золотой теленок', 'Комедии'], | ||
| ['Восточный экспресс', 'Детективы'] | ||
| ] | ||
| ) | ||
| def test_get_book_genre_by_name_success(self, name, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
| collector.set_book_genre(name, genre) | ||
| assert collector.get_book_genre(name) == genre | ||
|
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. Нужно исправить: |
||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
| @pytest.mark.parametrize('name,genre', [ | ||
| ['Заживо в темноте', 'Ужасы'], | ||
| ['Восточный экспресс', 'Детективы'] | ||
| ] | ||
| ) | ||
| def test_get_books_with_specific_genre_success(self, name, genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
| collector.set_book_genre(name, genre) | ||
| books_with_specific_genre = collector.get_books_with_specific_genre(genre) | ||
| assert name in books_with_specific_genre | ||
|
|
||
| @pytest.mark.parametrize('name,genre,specific_genre', [ | ||
| ['Заживо в темноте', 'Ужасы', True], | ||
| ['Восточный экспресс', 'Детективы', True], | ||
| ['Золотой ключик','Мультфильм', False] | ||
| ] | ||
| ) | ||
| def test_get_books_for_children_success(self, name, genre, specific_genre): | ||
| collector = BooksCollector() | ||
| collector.add_new_book(name) | ||
| collector.set_book_genre(name, genre) | ||
| books_with_specific_genre = collector.get_books_with_specific_genre(specific_genre) | ||
| books_for_children = collector.get_books_for_children() | ||
| assert len(books_for_children) != books_with_specific_genre | ||
|
|
||
| def test_get_list_of_favorites_books_success(self): | ||
|
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_list_of_favorites_books(), либо здесь проверяй вид списка |
||
| collector = BooksCollector() | ||
| collector.add_new_book('Золотой ключик') | ||
| collector.add_book_in_favorites('Золотой ключик') | ||
| assert len(collector.get_list_of_favorites_books()) == 1 | ||
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.
Можно улучшить: общее для всех тестов предусловие можно вынести в фикстуру