-
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
base: main
Are you sure you want to change the base?
Sprint_4 #8
Changes from all commits
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 +1,50 @@ | ||
| # qa_python | ||
| # qa_python | ||
|
|
||
| #@pytest.fixture | ||
| #создает экземпляр класса BooksCollector для использования в тестах | ||
|
|
||
| #test_add_new_book_add_two_books | ||
| #проверяет (add_new_book) | ||
| #проверяет функцию добавления книги в коллекцию | ||
|
|
||
|
|
||
| #test_set_book_genre_assign | ||
| #проверяет (set_book_genre) | ||
| #проверяет присвоение книге жанра из списка self.genre | ||
|
|
||
|
|
||
| #test_get_book_genre_existing_book | ||
| #проверяет (get_book_genre) | ||
| #проверяет что жанр выбранной книги выводится в соответствии с присвоенным жанром этой книги | ||
|
|
||
|
|
||
| #@pytest.mark.parametrize | ||
| #задает параметры нескольких сценариев для проведения теста test_get_books_with_specific_genre | ||
|
|
||
| #test_get_books_with_specific_genre_show_books_selected_genre | ||
| #проверяет (get_books_with_specific_genre) | ||
| #проверяет фильтрацию книг по определенным жанрам | ||
|
|
||
| #test_get_books_genre_returns_dictionary_sum_3 | ||
| #проверяет (get_books_genre) | ||
| #проверяет что get_books_genre возвращает словарь с правильным заданным количеством значений | ||
|
|
||
| #test_get_books_for_children_filters_out_age_rating_genres | ||
| #проверяет (get_books_for_children) | ||
| #проверяет фильтрацию книг по жанру для отсеивания книг с возрастным ограничением | ||
|
|
||
| #test_add_book_in_favorites_added_to_favorites_list_sum_1 | ||
| #проверяет (add_book_in_favorites) | ||
| #проверяет добавление книги в список self.favorites | ||
|
|
||
| #test_add_book_in_favorites_book_duplicate_no_append_copy_sum_1 | ||
| #проверяет (add_book_in_favorites) | ||
| #проверяет что в список не добавляется книга второй раз (дубликат) | ||
|
|
||
| #test_delete_book_from_favorites_book_removed_from_list | ||
| #проверяет (delete_book_from_favorites) | ||
| #проверяет удаление книги из списка self.favorites | ||
|
|
||
| #test_get_list_of_favorites_books_returns_list_with_two_books | ||
| #проверяет (get_list_of_favorites_books) | ||
| #проверяет корректность данных при запросе хранящихся в списке self.favorites |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,130 @@ | ||
| from main import BooksCollector | ||
| import pytest | ||
|
|
||
| # класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector | ||
| # обязательно указывать префикс Test | ||
| class TestBooksCollector: | ||
|
|
||
| # пример теста: | ||
| # обязательно указывать префикс test_ | ||
| # дальше идет название метода, который тестируем add_new_book_ | ||
| # затем, что тестируем add_two_books - добавление двух книг | ||
| def test_add_new_book_add_two_books(self): | ||
| # создаем экземпляр (объект) класса BooksCollector | ||
| collector = BooksCollector() | ||
| class TestBooksCollector: | ||
|
|
||
| # добавляем две книги | ||
| @pytest.fixture | ||
| def collector_with_books(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. Нужно исправить: фикстуры нужны для хранения логики предусловий, а не создания и возвращения данных. Нужные для конкретного еста данные ты можешь задать прямо в нем, напрямую обращаясь к словарю или списку |
||
| return BooksCollector() | ||
|
|
||
| # исправленный пример теста: | ||
|
|
||
| def test_add_new_book_add_two_books(self, collector_with_books): | ||
|
|
||
| collector = collector_with_books | ||
|
|
||
| collector.add_new_book('Гордость и предубеждение и зомби') | ||
| collector.add_new_book('Что делать, если ваш кот хочет вас убить') | ||
| assert len(collector.get_books_genre()) == 2 | ||
|
|
||
|
|
||
| def test_set_book_genre_assign(self, collector_with_books): | ||
| collector = collector_with_books | ||
|
|
||
| name = 'Книга 1' | ||
| collector.add_new_book(name) | ||
| collector.set_book_genre(name, 'Фантастика') | ||
| assert collector.get_book_genre(name) == 'Фантастика' | ||
|
|
||
|
|
||
| def test_get_book_genre_existing_book(self, collector_with_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. Нужно исправить: тест аналогичен тесту set_book_genre. Попробуй установить значение жанра иначе, или иначе получить его для сравнения. Используй доступ к словарю |
||
| collector = collector_with_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_book_genre, но этот метод отсутствует в тесте. Тест подойдет для set метода, названия должны соответствовать сути |
||
| name = 'Книга 2' | ||
|
|
||
| collector.books_genre = {name: 'Комедии'} | ||
| result = collector.get_book_genre(name) | ||
| assert result == 'Комедии' | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("genre, expected_books", [ | ||
| ('Фантастика', ['Книга 1']), | ||
| ('Ужасы', []), | ||
| ('Комедии', ['Книга 3']) | ||
| ]) | ||
|
|
||
| def test_get_books_with_specific_genre_show_books_selected_genre(self, genre, expected_books, collector_with_books): | ||
| collector = collector_with_books | ||
|
|
||
| collector.add_new_book('Книга 1') | ||
| collector.add_new_book('Книга 3') | ||
| collector.set_book_genre('Книга 1', 'Фантастика') | ||
| collector.set_book_genre('Книга 3', 'Комедии') | ||
|
|
||
| result = collector.get_books_with_specific_genre(genre) | ||
| assert result == expected_books | ||
|
|
||
|
|
||
| def test_get_books_genre_returns_dictionary_sum_3(self, collector_with_books): | ||
| collector = collector_with_books | ||
|
|
||
| collector.books_genre = {'Книга 1': '', 'Книга 2': '', 'Книга 3': ''} | ||
|
|
||
| result = collector.get_books_genre() | ||
| assert isinstance(result, dict) | ||
| assert len(result) == 3 | ||
|
|
||
|
|
||
|
|
||
| def test_get_books_for_children_filters_out_age_rating_genres(self, collector_with_books): | ||
| collector = collector_with_books | ||
|
|
||
| books_with_genres = { | ||
| 'Книга 1': 'Мультфильмы', | ||
| 'Книга 2': 'Комедии', | ||
| 'Книга 3': 'Детективы' | ||
| } | ||
| for name, genre in books_with_genres.items(): | ||
| collector.add_new_book(name) | ||
| collector.set_book_genre(name, genre) | ||
|
|
||
| result = collector.get_books_for_children() | ||
| assert result == ['Книга 1', 'Книга 2'] | ||
|
|
||
|
|
||
|
|
||
| def test_add_book_in_favorites_added_to_favorites_list_sum_1(self, collector_with_books): | ||
| collector = collector_with_books | ||
|
|
||
| book_name = 'Книга 1' | ||
| collector.add_new_book(book_name) | ||
| collector.add_book_in_favorites(book_name) | ||
| favorites = collector.get_list_of_favorites_books() | ||
| assert favorites == [book_name] | ||
|
|
||
|
|
||
| def test_add_book_in_favorites_book_duplicate_no_append_copy_sum_1(self, collector_with_books): | ||
| collector = collector_with_books | ||
|
|
||
| name = 'Книга 2' | ||
| collector.add_new_book(name) | ||
| collector.add_book_in_favorites(name) | ||
| collector.add_book_in_favorites(name) | ||
|
|
||
| favorites = collector.get_list_of_favorites_books() | ||
| assert favorites == [name] | ||
|
|
||
|
|
||
| def test_delete_book_from_favorites_book_removed_from_list(self, collector_with_books): | ||
| collector = collector_with_books | ||
|
|
||
| name = 'Книга 3' | ||
| collector.add_new_book(name) | ||
| collector.add_book_in_favorites(name) | ||
| collector.delete_book_from_favorites(name) | ||
| favorites = collector.get_list_of_favorites_books() | ||
| assert favorites == [] | ||
|
|
||
|
|
||
| def test_get_list_of_favorites_books_returns_list_with_two_books(self, collector_with_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. Нужно исправить: по сути тест не отличается от добавление в избранное. Проверь методы независимо |
||
| collector = collector_with_books | ||
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
| books = ['Книга 1', 'Книга 2'] | ||
| for book in books: | ||
| collector.add_new_book(book) | ||
| collector.add_book_in_favorites(book) | ||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
| favorites = collector.get_list_of_favorites_books() | ||
| assert isinstance(favorites, list) | ||
| assert favorites == collector.favorites | ||
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.
В тесте есть ошибка. Если ты оставляешь этот тест, ее нужно исправить