Esempio n. 1
0
def test_delete_one_book():
    """This test check API delete method"""

    """Create a book"""
    new_book = add_book({'title': 'Deleted book', 'author': 'Deleted author'})
    book_id = new_book['id']

    """Get list of books"""
    all_books = get_all_books()
    list_number = len(all_books)

    """Check if created book was added to book list correctly.If it wasn't print error exception"""
    if new_book in all_books:
        # Delete created book
        delete_book(book_id)
        all_books = get_all_books()
        updated_list_number = len(all_books)

        assert new_book not in all_books, "The book wasn't deleted.Incorrect work of DELETE method!"
        assert (list_number - 1) == updated_list_number
        # Get book info by book id.
        book_info = get_book(new_book)
        assert len(book_info) == 0, "Book info wasn't deleted.Incorrect work of DELETE method!"

    else:
        assert 1 == 0, "The book wasn't created correctly. Check add_book method!!!"
Esempio n. 2
0
def test_delete_book():
    # Create new book
    new_book = add_book({
        'title': 'Book to be deleted',
        'author': 'Test Author'
    })
    book_id = new_book['id']

    # Get list of books
    all_books = get_all_books()

    # Check adding new book to book list.
    if new_book in all_books:
        # If book was added to list :1.Get number of books in list.
        number_of_books = len(all_books)

        # 2.Delete created book.
        delete_book(book_id)

        # 3.Check if the book was deleted and the list of books was reduced by 1 element
        all_books = get_all_books()
        updated_number_of_books = len(all_books)
        assert new_book not in all_books
        assert number_of_books > updated_number_of_books

    else:
        print(
            'Test Error!!!The book was not created at the beginning of the test case'
        )
Esempio n. 3
0
def test_sorting(sort):
    """This test is checking get_book_list method after passing sort parameter"""


    """Create some books with different titles"""
    new_book1 = add_book({'title': '1', 'author': 'Someone'})
    new_book2 = add_book({'title': 'B', 'author': 'Someone'})
    new_book3 = add_book({'title': '2', 'author': 'Someone'})
    new_book4 = add_book({'title': 'A', 'author': 'Someone'})
    new_book5 = add_book({'title': u'д', 'author': 'Someone'})
    new_book6 = add_book({'title': u'Nǐ hǎo!', 'author': 'Someone'})
    new_book7 = add_book({'title': u'г', 'author': 'Someone'})

    """Get list of books,pass to get_all_books sort parameter"""

    params = {'sort': sort}
    book_list = get_all_books(params=params)

    """Get indexes of created books in the list"""
    b1_index, b2_index, b3_index, b4_index, b5_index, b6_index, b7_index = book_list.index(new_book1),\
                                                                           book_list.index(new_book2),\
                                                                           book_list.index(new_book3),\
                                                                           book_list.index(new_book4),\
                                                                           book_list.index(new_book5),\
                                                                           book_list.index(new_book6),\
                                                                           book_list.index(new_book7)

    sort_type = sort
    if sort_type == '':
        assert b1_index < b2_index < b3_index < b4_index < b5_index < b6_index < b7_index, "Error in default sort!"
    else:
        assert b1_index < b3_index < b4_index < b2_index, "Error in sort by title !"
        assert b6_index < b7_index < b5_index, "Error in sort by title !"
        assert b1_index < b3_index < b4_index < b2_index < b6_index < b7_index < b5_index, "Error in sort by title!"
Esempio n. 4
0
def test_create_1_book():
    """This function check if created book was added to book list"""

    book = {'title': '1 Created book', 'author': 'One author'}
    new_book = add_book(book)

    all_books = get_all_books()

    assert new_book in all_books
    assert len(all_books) >= 1
Esempio n. 5
0
def test_book_list():
    """In this test we create some books and after that check if they will appear in book list """

    new_book = add_book({'title': 'Silent Hill', 'author': 'Heranuka'})
    another_new_book = add_book({'title': 'Silent Hill 2', 'author': "Heranuka po Royal'u"})

    book_list = get_all_books()

    assert new_book in book_list
    assert another_new_book in book_list
    assert len(book_list) >= 2
Esempio n. 6
0
def test_create_new_book(title, author):
    """ Check 'create book' method with different values of
        Title and Author.
    """

    book = {'title': title, 'author': author}
    new_book = add_book(book)

    all_books = get_all_books()

    assert new_book in all_books
Esempio n. 7
0
def test_create_some_books():
    """This function verify that all of created books was added to book list"""

    book1 = {'title': 'First created book', 'author': 'First author'}
    new_book1 = add_book(book1)

    book2 = {'title': 'Second created book', 'author': 'Second author'}
    new_book2 = add_book(book2)

    all_books = get_all_books()

    assert new_book1 and new_book2 in all_books
    assert len(all_books) >= 2
Esempio n. 8
0
def test_sort_identical_title():
    """This test is checking API behavior when there are some identical title in the list
    and the list need to be sorted"""

    """Create some books with identical title"""
    new_book = add_book({'title': 'Identical title', 'author': 'Some author'})
    new_book2 = add_book({'title': 'Identical title', 'author': 'Some author'})

    """Get sorted list bo books"""
    params = {'sort': 'by_title'}
    book_list = get_all_books(params=params)

    assert book_list.index(new_book) < book_list.index(new_book2), 'Incorrect sorting if there are ' \
                                                                   'some identical titles!'
Esempio n. 9
0
def test_delete_one_of_two_books():
    """In this test we create two books with the same title and author.After that  delete one of them and
    will check that delete method work correctly"""

    """Create some books with identical authors and titles"""
    first_book = add_book({'title': 'Foundation', 'author': 'Isaac Asimov'})
    first_book_id = first_book['id']
    second_book = add_book({'title': 'Foundation', 'author': 'Isaac Asimov'})
    second_book_id = second_book['id']

    """Get list of books"""
    all_books = get_all_books()

    """Check if created books were added to book list correctly.If they weren't print error exception"""
    if first_book and second_book in all_books:
        # Delete first created book
        delete_book(first_book_id)
        all_books = get_all_books()

        #Check that was deleted only one book of two that were created.
        assert first_book not in all_books, "The book wasn't deleted.Incorrect work of DELETE method!"
        assert second_book in all_books, "Two books were deleted instead of one!Incorrect work of DELETE method! "

        # Get book info by book id.
        first_book_info = get_book(first_book_id)
        second_book_info = get_book(second_book_id)

        #Check that info of first book was deleted and info of second one wasn't spoiled
        assert len(first_book_info) == 0, "Book info wasn't deleted.Incorrect work of DELETE method!"
        assert len(second_book_info) > 0, "Two books were deleted instead of one!Incorrect work of DELETE method! "
        assert second_book['author'] == 'Isaac Asimov'
        assert second_book['title'] == 'Foundation'
        assert second_book['id'].count('-') == 4

    else:
        assert 1 == 0, "The books weren't created correctly. Check add_book method!!!"
Esempio n. 10
0
def test_limits(limit):
    """This test is checking get_book_list method after passing limit parameter"""

    """Create one more book than indicated in the limit """
    if int(limit) > 0:
        for l in range(int(limit)+1):
            new_book = add_book({'title': 'The Dark Tower ' + str(l), 'author': 'Stephen King'})

        """Get list of books with limit parameter"""
        params = {'limit': limit}
        book_list = get_all_books(params=params)

        """Check if numbers of books in the list corresponds to the limit"""
        assert len(book_list) == int(limit), "Wrong limit parameter's working!"

    else:
        assert 1 > 2, "Wrong value of limit!In positive scenario limit have to be more than 0"
Esempio n. 11
0
def test_sorting_with_limits(sort, limit):
    """Comprehensive verification of sorting and limits"""

    """Create some books(number == limit) """
    new_book = add_book({'title': ' ', 'author': ' '})
    last_created_book = 1 #Костыль
    for l in range(int(limit) - 1):
         last_created_book = add_book({'title': ' ' + str(l), 'author': 'Stephen King'})

    params = {'limit': limit, 'sort': sort}
    book_list = get_all_books(params)

    if last_created_book in book_list:
        assert len(book_list) == int(limit)
        assert book_list.index(new_book) < book_list.index(last_created_book)

    else:
        assert len(book_list) == int(limit)
Esempio n. 12
0
def test_get_list_of_books():
    """ Check that 'get books' method returns correct list of books. """

    # Create two books, just to make sure books will be correctly
    # added to the list:
    add_book({'title': '', 'author': ''})
    add_book({'title': '1', 'author': '2'})

    # Get list of all books:
    all_books = get_all_books()

    # Check that every book in the list has all required attributes:
    for book in all_books:
        assert 'title' in book
        assert 'author' in book
        assert validate_uuid4(book['id'])

    # Make sure that the list has at least 2 books:
    assert len(all_books) >= 2
Esempio n. 13
0
def test_books_with_similar_author():
    """This test check API behavior after creating more than one book with identical author """

    """Create some books with identical author"""
    first_book = add_book({'title': 'Title 1', 'author': 'The same author'})
    first_book_id = first_book['id']
    second_book = add_book({'title': 'Title 2', 'author': 'The same author'})
    second_book_id = second_book['id']

    """Get list of books"""
    all_books = get_all_books()

    assert first_book in all_books
    assert second_book in all_books

    """Get info of created books"""
    first_book_info = get_book(first_book_id)
    second_book_info = get_book(second_book_id)

    assert first_book_info != second_book_info
    assert first_book_id != second_book_id
    assert first_book['title'] == 'Title 1'
    assert second_book['title'] == 'Title 2'