-
Notifications
You must be signed in to change notification settings - Fork 21
sprint4 tests #17
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
Dasha11777
wants to merge
2
commits into
yandex-praktikum:main
Choose a base branch
from
Dasha11777:developDasha
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
sprint4 tests #17
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 |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
|
|
||
| # C extensions | ||
| *.so | ||
|
|
||
| # Distribution / packaging | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| share/python-wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
| MANIFEST | ||
|
|
||
| # PyInstaller | ||
| # Usually these files are written by a python script from a template | ||
| # before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
| *.manifest | ||
| *.spec | ||
|
|
||
| # Installer logs | ||
| pip-log.txt | ||
| pip-delete-this-directory.txt | ||
|
|
||
| # Unit test / coverage reports | ||
| htmlcov/ | ||
| .tox/ | ||
| .nox/ | ||
| .coverage | ||
| .coverage.* | ||
| .cache | ||
| nosetests.xml | ||
| coverage.xml | ||
| *.cover | ||
| .hypothesis/ | ||
| .pytest_cache/ | ||
|
|
||
| # Translations | ||
| *.mo | ||
| *.pot | ||
|
|
||
| # Django stuff: | ||
| *.log | ||
| local_settings.py | ||
| db.sqlite3 | ||
|
|
||
| # Flask stuff: | ||
| instance/ | ||
| .webassets-cache | ||
|
|
||
| # Scrapy stuff: | ||
| .scrapy | ||
|
|
||
| # Sphinx documentation | ||
| docs/_build/ | ||
|
|
||
| # PyBuilder | ||
| target/ | ||
|
|
||
| # Jupyter Notebook | ||
| .ipynb_checkpoints | ||
|
|
||
| # IPython | ||
| profile_default/ | ||
| ipython_config.py | ||
|
|
||
| # pyenv | ||
| .python-version | ||
|
|
||
| # celery beat schedule file | ||
| celerybeat-schedule | ||
|
|
||
| # SageMath parsed files | ||
| *.sage.py | ||
|
|
||
| # Environments | ||
| .env | ||
| .venv | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
|
|
||
| # Spyder project settings | ||
| .spyderproject | ||
| .spyproject | ||
|
|
||
| # Rope project settings | ||
| .ropeproject | ||
|
|
||
| # mkdocs documentation | ||
| /site | ||
|
|
||
| # mypy | ||
| .mypy_cache/ | ||
| .dmypy.json | ||
| dmypy.json | ||
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # VSCODE IDE | ||
| .vscode | ||
|
|
||
| #Pycharm IDE | ||
| .idea |
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,27 @@ | ||
| # qa_python | ||
| # qa_python | ||
| Разработан в рамках обучения на курсе ЯП "Инженер по тестированию: от новичка до автоматизатора". Суть проекта покрыть тестами приложение BooksCollector, которое позволяет установить жанр книг и добавить их в избранное. Автоматизировано юнит-тестирование с помощью фикстур и параметризации. | ||
|
|
||
| Запустить проект можно с помощью команды в терминале: pytest tests.py -v | ||
|
|
||
| Реализованы фикстуры: | ||
| 1. books_collection: возвращает объект класса BooksCollector | ||
| 2. comedy_and_horror_collection: возвращает коллекцию с двумя книгами (ужасы и комедии) | ||
| 3. adult_collection: возвращает коллекцию с одной книгой жанра "Ужасы" | ||
|
|
||
| Сценарии, покрытые тестами: | ||
| 1. test_add_new_book_add_two_books: проверка добавления двух книг | ||
| 2. test_add_new_book_already_added_book: негативная проверка на повторное добавление книги | ||
| 3. test_add_new_book_name_in_the_range: параметризованная проверка на добавление книги с валидным названием (3 варианта) | ||
| 4. test_add_new_book_name_out_of_range: параметризованная негативная проверка на добавление книги с невалидным названием (3 варианта) | ||
| 5. test_set_book_genre_to_existing_book: проверка на добавление жанра из genre для книги из books_genre | ||
| 6. test_set_book_genre_to_not_existing_book: негативная проверка на добавление жанра для несуществующей книги | ||
| 7. test_set_book_genre_to_not_existing_genre: негативная проверка на добавление жанра НЕ из genre для существующей книги | ||
| 8. test_get_book_genre_by_name: параметризованная проверка на вывод жанра книги по ее имени (2 варианта) | ||
| 9. test_get_books_with_specific_genre_by_genre: проверка на вывод книг по жанру | ||
| 10. test_get_books_with_specific_genre_for_not_existing_genre: негативная проверка на вывод книг по несуществующему жанру | ||
| 11. test_get_books_with_specific_genre_by_wrong_genre: негативная проверка на вывод книг по жанру НЕ из genre | ||
| 12. test_get_books_for_children: проверка на вывод детских книг | ||
| 13. test_add_book_in_favorites_added_in_favorites_book: проверка на добавление книги в избранное | ||
| 14. test_add_book_in_favorites_for_not_existing_book: негативная проверка на добавление в избранное несуществующей книги | ||
| 15. test_delete_book_from_favorites: проверка на удаление книги из избранного | ||
| 16. test_delete_book_from_favorites_for_not_favorites_book: негативная проверка на удаление из избранного книги НЕ добавленной в избранное |
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import pytest | ||
| from main import BooksCollector | ||
|
|
||
| @pytest.fixture | ||
| def books_collection() : | ||
| return BooksCollector() | ||
|
|
||
| @pytest.fixture | ||
| def comedy_and_horror_collection() : | ||
| collector = BooksCollector() | ||
| book_name_1 = 'Гордость и предубеждение и зомби' | ||
| book_genre_1 = 'Ужасы' | ||
| book_name_2 = 'Что делать, если ваш кот хочет вас убить' | ||
| book_genre_2 = 'Комедии' | ||
| collector.add_new_book(book_name_1) | ||
| collector.set_book_genre(book_name_1, book_genre_1) | ||
| collector.add_new_book(book_name_2) | ||
| collector.set_book_genre(book_name_2, book_genre_2) | ||
|
|
||
| return collector | ||
|
|
||
| @pytest.fixture | ||
| def adult_collection() : | ||
| collector = BooksCollector() | ||
| book_name_1 = 'Гордость и предубеждение и зомби' | ||
| book_genre_1 = 'Ужасы' | ||
| collector.add_new_book(book_name_1) | ||
| collector.set_book_genre(book_name_1, book_genre_1) | ||
|
|
||
| return collector |
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,149 @@ | ||
| 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 | ||
| collector = BooksCollector() | ||
| def test_add_new_book_add_two_books(self, books_collection): | ||
| book_name_1 = 'Гордость и предубеждение и зомби' | ||
| book_name_2 = 'Что делать, если ваш кот хочет вас убить' | ||
| books_collection.add_new_book(book_name_1) | ||
| books_collection.add_new_book(book_name_2) | ||
| assert books_collection.get_books_genre() == {book_name_1: '', book_name_2: ''} | ||
|
|
||
| # добавляем две книги | ||
| collector.add_new_book('Гордость и предубеждение и зомби') | ||
| collector.add_new_book('Что делать, если ваш кот хочет вас убить') | ||
| def test_add_new_book_already_added_book(self, books_collection): | ||
| book_name = 'Гордость и предубеждение' | ||
| books_collection.add_new_book(book_name) | ||
| books_collection.add_new_book(book_name) | ||
| assert len(books_collection.get_books_genre()) == 1 | ||
|
|
||
| # проверяем, что добавилось именно две | ||
| # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 | ||
| assert len(collector.get_books_rating()) == 2 | ||
| in_the_range_book_names =['К югу от границы', | ||
| 'Любовь как роза, красива, но шипы больны', | ||
| 'Я'] | ||
| @pytest.mark.parametrize('name', in_the_range_book_names) | ||
| def test_add_new_book_name_in_the_range(self, name, books_collection): | ||
| books_collection.add_new_book(name) | ||
| assert name in books_collection.get_books_genre() | ||
|
|
||
| # напиши свои тесты ниже | ||
| # чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() | ||
| out_of_range_book_names = ['', | ||
| 'Удивительное путешествие Нильса Хольгерсс', | ||
| 'Удивительное путешествие Нильса Хольгерссона с дикими гусями по Швеции'] | ||
|
|
||
| @pytest.mark.parametrize('name', out_of_range_book_names) | ||
| def test_add_new_book_name_out_of_range(self, name, books_collection): | ||
| books_collection.add_new_book(name) | ||
| assert name not in books_collection.get_books_genre() | ||
|
|
||
| def test_set_book_genre_to_existing_book(self, books_collection): | ||
| book_name = 'Гордость и предубеждение' | ||
| book_genre = 'Фантастика' | ||
| books_collection.add_new_book(book_name) | ||
| books_collection.set_book_genre(book_name, book_genre) | ||
| assert books_collection.get_books_genre() == {book_name: book_genre} | ||
|
|
||
| def test_set_book_genre_to_not_existing_book(self, books_collection): | ||
| book_name = 'Гордость и предубеждение' | ||
| book_genre = 'Фантастика' | ||
| books_collection.set_book_genre(book_name, book_genre) | ||
| assert len(books_collection.get_books_genre()) == 0 | ||
|
|
||
| def test_set_book_genre_to_not_existing_genre(self, books_collection): | ||
| book_name = 'Гордость и предубеждение' | ||
| book_genre = 'Трагикомедии' | ||
| books_collection.add_new_book(book_name) | ||
| books_collection.set_book_genre(book_name, book_genre) | ||
| assert books_collection.get_books_genre()[book_name] == '' | ||
|
|
||
| @pytest.mark.parametrize('name, genre', [('Гордость и предубеждение и зомби', 'Ужасы'), | ||
| ('Что делать, если ваш кот хочет вас убить', 'Комедии')]) | ||
| def test_get_book_genre_by_name(self, name, genre, books_collection): | ||
| books_collection.add_new_book(name) | ||
| books_collection.set_book_genre(name, genre) | ||
| assert books_collection.get_book_genre(name) == genre | ||
|
|
||
| def test_get_books_with_specific_genre_by_genre(self, comedy_and_horror_collection): | ||
| books = comedy_and_horror_collection.get_books_genre() | ||
| first_book_name = list(books.keys())[0] | ||
| first_book_genre = books[first_book_name] | ||
|
|
||
| assert comedy_and_horror_collection.get_books_with_specific_genre(first_book_genre) == [first_book_name] | ||
|
|
||
| def test_get_books_with_specific_genre_for_not_existing_genre(self, comedy_and_horror_collection): | ||
| assert comedy_and_horror_collection.get_books_with_specific_genre('Мультфильмы') == [] | ||
|
|
||
| def test_get_books_with_specific_genre_by_wrong_genre(self, comedy_and_horror_collection): | ||
| assert len(comedy_and_horror_collection.get_books_with_specific_genre('Трагикомедии')) == 0 | ||
|
|
||
| def test_get_books_for_children(self, adult_collection): | ||
| book_for_child = 'Гадкий Я' | ||
| book_genre_for_child = 'Мультфильмы' | ||
| adult_collection.add_new_book(book_for_child) | ||
| adult_collection.set_book_genre(book_for_child, book_genre_for_child) | ||
|
|
||
| assert len(adult_collection.get_books_for_children()) == 1 | ||
| assert adult_collection.get_books_for_children() == ['Гадкий Я'] | ||
|
|
||
| def test_add_book_in_favorites_added_in_favorites_book(self, comedy_and_horror_collection): | ||
| first_book_name = list(comedy_and_horror_collection.get_books_genre().keys())[0] | ||
|
|
||
| comedy_and_horror_collection.add_book_in_favorites(first_book_name) | ||
| assert first_book_name in comedy_and_horror_collection.get_list_of_favorites_books() | ||
| assert len(comedy_and_horror_collection.get_list_of_favorites_books()) == 1 | ||
|
|
||
| def test_add_book_in_favorites_for_not_existing_book(self, books_collection): | ||
| book_name_1 = 'Что делать, если ваш кот хочет вас убить' | ||
| book_genre_1 = 'Комедии' | ||
| books_collection.add_new_book(book_name_1) | ||
| books_collection.set_book_genre(book_name_1, book_genre_1) | ||
|
|
||
| books_collection.add_book_in_favorites('Симбиоз') | ||
| assert len(books_collection.get_list_of_favorites_books()) == 0 | ||
|
|
||
| def test_delete_book_from_favorites(self, books_collection): | ||
| book_name_1 = 'Что делать, если ваш кот хочет вас убить' | ||
| book_genre_1 = 'Комедии' | ||
| books_collection.add_new_book(book_name_1) | ||
| books_collection.set_book_genre(book_name_1, book_genre_1) | ||
| books_collection.add_book_in_favorites(book_name_1) | ||
| favorites_book_count_before = len(books_collection.get_list_of_favorites_books()) | ||
|
|
||
| books_collection.delete_book_from_favorites(book_name_1) | ||
| assert favorites_book_count_before == 1 | ||
| assert len(books_collection.get_list_of_favorites_books()) == 0 | ||
|
|
||
| def test_delete_book_from_favorites_for_not_favorites_book(self, comedy_and_horror_collection): | ||
| first_book_name = list(comedy_and_horror_collection.get_books_genre().keys())[0] | ||
| second_book_name = list(comedy_and_horror_collection.get_books_genre().keys())[1] | ||
|
|
||
| comedy_and_horror_collection.add_book_in_favorites(first_book_name) | ||
|
|
||
| comedy_and_horror_collection.delete_book_from_favorites(second_book_name) | ||
| assert len(comedy_and_horror_collection.get_list_of_favorites_books()) == 1 | ||
| assert comedy_and_horror_collection.get_list_of_favorites_books() == [first_book_name] | ||
|
|
||
| def test_get_books_genre_returns_books_dictionary(self, books_collection): | ||
| book_name_1 = 'Ревизор' | ||
| book_name_2 = 'Чисто английское убийство' | ||
| genre_1 = 'Комедии' | ||
| genre_2 = 'Детективы' | ||
|
|
||
| books_collection.add_new_book(book_name_1) | ||
| books_collection.add_new_book(book_name_2) | ||
| books_collection.set_book_genre(book_name_1, genre_1) | ||
| books_collection.set_book_genre(book_name_2, genre_2) | ||
|
|
||
| result = books_collection.get_books_genre() | ||
| assert result == {book_name_1: genre_1, book_name_2: genre_2} | ||
|
|
||
| def test_get_list_of_favorites_books_returns_favorites_list(self, books_collection): | ||
| book_name_1 = 'Мастер и Маргарита' | ||
| book_name_2 = 'Преступление и наказание' | ||
| book_name_3 = 'Идиот' | ||
|
|
||
| books_collection.add_new_book(book_name_1) | ||
| books_collection.add_new_book(book_name_2) | ||
| books_collection.add_new_book(book_name_3) | ||
| books_collection.add_book_in_favorites(book_name_1) | ||
| books_collection.add_book_in_favorites(book_name_3) | ||
|
|
||
| result = books_collection.get_list_of_favorites_books() | ||
| assert result == [book_name_1, book_name_3] | ||
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.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.