Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
*.pyc
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# qa_python
# В проекте реализованы тесты для класса BooksCollector.

# Покрыты методы:

#

# \- add\_new\_book - обычный + длинное имя + параметризация

# \- set\_book\_genre - корректный / некорректный

# \- get\_book\_genre

# \- get\_books\_with\_specific\_genre

# \- get\_books\_genre

# \- get\_books\_for\_children

# \- add\_book\_in\_favorites

# \- delete\_book\_from\_favorites

# \- get\_list\_of\_favorites\_books

# Используется параметризация для проверки добавления книг.

Binary file removed __pycache__/main.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/test.cpython-38-pytest-7.1.2.pyc
Binary file not shown.
101 changes: 84 additions & 17 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,91 @@
import pytest
from main import BooksCollector

# класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector
# обязательно указывать префикс Test

@pytest.fixture
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно улучшить: лучше хранить в отдельном модуле

def collector():
return BooksCollector()


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, collector):
collector.add_new_book('Книга 1')
collector.add_new_book('Книга 2')

assert len(collector.books_genre) == 2

def test_add_new_book_name_more_40_symbols_not_added(self, collector):
long_name = 'А' * 41

collector.add_new_book(long_name)

assert len(collector.books_genre) == 0

def test_set_book_genre_success(self, collector):
collector.books_genre['Оно'] = ''

collector.set_book_genre('Оно', 'Ужасы')

assert collector.books_genre['Оно'] == 'Ужасы'

def test_get_book_genre(self, collector):
collector.books_genre['Оно'] = 'Ужасы'

result = collector.get_book_genre('Оно')

assert result == 'Ужасы'

def test_get_books_with_specific_genre(self, collector):
collector.books_genre = {
'Книга 1': 'Фантастика',
'Книга 2': 'Ужасы'
}

result = collector.get_books_with_specific_genre('Фантастика')

assert result == ['Книга 1']

def test_get_books_for_children(self, collector):
collector.books_genre = {
'Детская': 'Комедии',
'Страшная': 'Ужасы'
}

result = collector.get_books_for_children()

assert result == ['Детская']

def test_add_book_in_favorites(self, collector):
collector.books_genre['Оно'] = ''

collector.add_book_in_favorites('Оно')

assert collector.favorites == ['Оно']

def test_get_list_of_favorites_books(self, collector):
collector.favorites = ['Оно', 'Дюна']

result = collector.get_list_of_favorites_books()

assert result == ['Оно', 'Дюна']

def test_delete_book_from_favorites(self, collector):
collector.favorites = ['Оно']

collector.delete_book_from_favorites('Оно')

# добавляем две книги
collector.add_new_book('Гордость и предубеждение и зомби')
collector.add_new_book('Что делать, если ваш кот хочет вас убить')
assert collector.favorites == []

# проверяем, что добавилось именно две
# словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2
assert len(collector.get_books_rating()) == 2
@pytest.mark.parametrize(
'book_name',
[
'Книга',
'Очень интересная книга',
'Python для всех'
]
)
def test_add_new_book_parametrized(self, collector, book_name):
collector.add_new_book(book_name)

# напиши свои тесты ниже
# чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector()
assert book_name in collector.books_genre