def test_7_delete_book(self, create_book): delete_books = Books(self.server_url) BaseApi.add_simple_step(f'Delete book: {create_book}') status = delete_books.delete_book_and_get_status(str(create_book)) BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([StatusCheck(status)]).execute() assert test_results == True
def test_1_check_book_response_code(self): get_books = Books(self.server_url) BaseApi.add_simple_step( f'Get response for {ProjectConstants.BOOKS_ENDPOINT}') status, received_response = get_books.book_status_and_response() BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([StatusCheck(status)]).execute() assert test_results == True
def book_id_list(domain): book_id_list_fixture = BaseApi(domain) status, response_items = book_id_list_fixture.get_status_and_response( ProjectConstants.BOOKS_ENDPOINT) list_of_founded_ids = [] for dic in response_items: if dic.get("author") == ProjectConstants.TITLE_TO_FIND: list_of_founded_ids.append(dic.get("id")) return list_of_founded_ids
def test_2_check_shop_response_code_and_quantity(self): get_shops = Shops(self.server_url) BaseApi.add_simple_step(f'Get response for {ProjectConstants.SHOPS_ENDPOINT}') status, received_response = get_shops.shops_status_and_response() BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([ StatusCheck(status), LengthCompare(received_response, ProjectConstants.SHOPS_DEFAULT_AMOUNT) ]).execute() assert test_results == True
def test_4_check_book_id_in_response(self, create_book): get_books = Books(self.server_url) BaseApi.add_simple_step(f'Get response for book id = {create_book}') status, received_response = get_books.book_status_and_response( create_book) BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([ StatusCheck(status), CheckingIdInResponse(received_response, create_book) ]).execute() assert test_results == True
def test_3_check_the_book_author_presence_in_response(self, book_id_list): get_books = Books(self.server_url) BaseApi.add_simple_step( f'Get response for {ProjectConstants.BOOKS_ENDPOINT}') status, received_response = get_books.book_status_and_response() BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([ StatusCheck(status), CheckingBookAuthorPresenceInResponse(book_id_list) ]).execute() assert test_results == True
def test_8_json_schema_checking(self, create_book): get_books = Books(self.server_url) BaseApi.add_simple_step(f'Get books response for {create_book}') status, received_response = get_books.book_status_and_response( create_book) BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([ StatusCheck(status), SchemaCheck(response_for_schema=received_response, schema=ProjectConstants.SCHEMA) ]).execute() assert test_results == True
def create_book(domain): fake = Factory.create() title = fake.catch_phrase() author = fake.name() rating = fake.year() year_published = fake.year() data = { "title": title, "author": author, "rating": rating, "year_published": year_published } create_book_fixture = BaseApi(domain) status, response_items = create_book_fixture.post_and_get_status_and_response( ProjectConstants.BOOKS_ENDPOINT, data) id = response_items.get("id") return id
def test_7_after_deleting_duplicates_they_shouldnt_be_returned_by_server( self): books = Books(self.server_url) duplicates = books.get_list_of_books_duplicates() if duplicates: BaseApi.add_simple_step( f'Delete duplicates of books: {duplicates}') deleting_duplicates = books.delete_list_of_books_return_statuses( duplicates) get_deleted_books = books.get_list_of_books_return_statuses( duplicates) test_results_deleting = CheckingPerformer( [StatusCheck(deleting_duplicates)]).execute() test_result_get_deleted_books = CheckingPerformer( [StatusCheck(get_deleted_books, expected_status=404)]).execute() assert test_results_deleting is True assert test_result_get_deleted_books is True else: BaseApi.add_simple_step('No duplicates found') pytest.skip('No duplicates found')
def test_5_create_book(self): post_book = Books(self.server_url) BaseApi.add_simple_step( f'Generate request body for {post_book.books_endpoint}') book_to_post = post_book.create_book_data() BaseApi.add_simple_step( f'Post book to endpoint: {post_book.books_endpoint}') status, received_response = post_book.post_new_book(book_to_post) BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([ StatusCheck(status, 201), RequestResponseCompare([[received_response, book_to_post]]) ]).execute() assert test_results == True
def test_6_update_book(self, create_book): book = Books(self.server_url) BaseApi.add_simple_step( f'Generate request body for {book.books_endpoint} to update book') book_to_update = book.create_book_data() BaseApi.add_simple_step(f'Update book: {create_book}') status, received_response = book.update_book(str(create_book), book_to_update) BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([ StatusCheck(status), RequestResponseCompare([[received_response, book_to_update]]) ]).execute() assert test_results == True
def test_7_delete_books_duplicates(self): books = Books(self.server_url) duplicates = books.get_list_of_books_duplicates() if len(duplicates) > 0: BaseApi.add_simple_step( f'Delete duplicates of books: {duplicates}') for id in duplicates: status = books.delete_book_and_get_status(str(id)) BaseApi.add_simple_step(f'Performing tests') test_results = CheckingPerformer([StatusCheck(status) ]).execute() assert test_results == True for id in duplicates: status, received_response = books.book_status_and_response( str(id)) test_results = CheckingPerformer([StatusCheck(status, 404)]).execute() assert test_results == True else: BaseApi.add_simple_step(f'No duplicates found') assert True