Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
.pytest_cache
.DS_Store
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# qa_python
# qa_python
# Список реализованных тестов:
# 1. test_add_new_book_add_two_books - проверка добавления двух книг
# 2. test_add_new_book_invalid_name_lenght - проверка неправильного названия
# 3. test_set_book_genre_add_one_genre - проверка присвоения жанра к названию книги
# 4. test_get_book_genre_positive - проверка возвращения жанра по названию книги
# 5. test_get_books_with_specific_genre_positive - проверка вывода списка названий по определенному жанру
# 6. test_get_books_genre_positive - проверка вывода словаря
# 7. test_get_books_for_children_positive - проверка возвращения книги по соответствущим для детей жанрам
# 8. test_get_books_for_children_negative - проверка недобавления книги в словарь несоответствующего для детей жанра
# 9. test_add_book_in_favorites_positive - проверка добавления в словарь избранную книгу
# 10. test_delete_book_from_favorites_positive - проверка удаления книги из избранного
# 11. test_get_list_of_favorites_books_positive - проверка вывода списка в избранном
69 changes: 69 additions & 0 deletions test_book_collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import pytest

from main import BooksCollector

class TestBooksCollector:

def test_add_new_book_add_two_books(self):
collector = BooksCollector()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно лучше: создание объекта BooksCollector можно вынести в фикстуры. Фикстуры следует хранить в файле conftest

collector.add_new_book('Гордость и предубеждение и зомби')
collector.add_new_book('Что делать, если ваш кот хочет вас убить')
assert len(collector.get_books_genre()) == 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно лучше: проверка соответствия конкретных значений будет более достоверной, чем проверка количества элементов.


@pytest.mark.parametrize('name', ['', 'a'*41])
def test_add_new_book_invalid_name_lenght(self, name):
collector = BooksCollector()
collector.add_new_book(name)
assert name not in collector.books_genre

def test_set_book_genre_add_one_genre(self):
collector = BooksCollector()
collector.add_new_book('Голова профессора Доуэля')
collector.set_book_genre('Голова профессора Доуэля', 'Фантастика')
assert collector.books_genre['Голова профессора Доуэля'] == 'Фантастика'

def test_get_book_genre_positive(self):
collector = BooksCollector()
collector.add_new_book('Оно')
collector.books_genre['Оно'] = 'Ужасы'
assert collector.get_book_genre('Оно') == 'Ужасы'

def test_get_books_with_specific_genre_positive(self):
collector = BooksCollector()
collector.books_genre.update({'Убийство на улице Морг': 'Детективы', 'Рассказы о Шерлоке Холмсе': 'Детективы'})
result = collector.get_books_with_specific_genre('Детективы')
assert result == ['Убийство на улице Морг', 'Рассказы о Шерлоке Холмсе']

def test_get_books_genre_positive(self):
collector = BooksCollector()
collector.books_genre = {'Оно': 'Ужасы'}
assert collector.get_books_genre() == {'Оно': 'Ужасы'}

def test_get_books_for_children_positive(self):
collector = BooksCollector()
collector.books_genre = {'Голова профессора Доуэля': 'Фантастика'}
result = collector.get_books_for_children()
assert 'Голова профессора Доуэля' in result

def test_get_books_for_children_negative(self):
collector = BooksCollector()
collector.books_genre = {'Оно': 'Ужасы'}
result = collector.get_books_for_children()
assert 'Оно' not in result

def test_add_book_in_favorites_positive(self):
collector = BooksCollector()
collector.add_new_book('Трое в лодке, не считая собаки')
collector.add_book_in_favorites('Трое в лодке, не считая собаки')
assert 'Трое в лодке, не считая собаки' in collector.favorites

def test_delete_book_from_favorites_positive(self):
collector = BooksCollector()
collector.favorites = ['Убийство на улице Морг']
collector.delete_book_from_favorites('Убийство на улице Морг')
assert 'Убийство на улице Морг' not in collector.favorites

def test_get_list_of_favorites_books_positive(self):
collector = BooksCollector()
collector.favorites = ['Гордость и предубеждение и зомби', 'Что делать, если ваш кот хочет вас убить']
assert collector.get_list_of_favorites_books() == ['Гордость и предубеждение и зомби', 'Что делать, если ваш кот хочет вас убить']
24 changes: 0 additions & 24 deletions tests.py

This file was deleted.