def test_replace_isbn_not_authorized(self, bookstore, create_test_user, create_test_books): user = create_test_user(teardown=True) create_test_books(user_id=user.user_id, teardown=True) with Deauthorizer(bookstore): resp = bookstore.replace_isbn(userId=user.user_id, isbn=NEW_ISBNS[0]) assert resp.status_code == HTTPStatus.UNAUTHORIZED assert MessageResponse(**resp.json()) == MessageResponse(code='1200', message='User not authorized!')
def test_login_bad_format(self, account, create_test_user, username_generator, password_generator): username = username_generator() password = password_generator() create_test_user(username=username, password=password, teardown=True) resp = account.login(userName=username, what=password) assert resp.status_code == HTTPStatus.BAD_REQUEST assert MessageResponse(**resp.json()) == MessageResponse(code='1200', message='UserName and Password required.')
def test_create_existing_user(self, account, create_test_user, username_generator, password_generator): username = username_generator() password = password_generator() create_test_user(username=username, password=password, teardown=True) resp = account.create_user(userName=username, password=password) assert resp.status_code == HTTPStatus.NOT_ACCEPTABLE assert MessageResponse(**resp.json()) == MessageResponse(code='1204', message='User exists!')
def test_delete_nonexistent_book(self, bookstore, create_test_user): user = create_test_user(teardown=True) resp = bookstore.delete_book(isbn=INVALID_ISBNS[0], userId=user.user_id) assert resp.status_code == HTTPStatus.NOT_FOUND assert MessageResponse(**resp.json()) == MessageResponse( code='1207', message='Book not found!')
def test_get_user_not_authorized(self, account, create_test_user): user = create_test_user(teardown=True) with Deauthorizer(account): resp = account.get_user(userId=user.user_id) assert resp.status_code == HTTPStatus.UNAUTHORIZED assert MessageResponse(**resp.json()) == MessageResponse( code='1200', message='User not authorized!')
def test_get_other_user(self, account, create_test_user, user_id_generator): create_test_user(teardown=True) resp = account.get_user(userId=user_id_generator()) assert resp.status_code == HTTPStatus.UNAUTHORIZED assert MessageResponse(**resp.json()) == MessageResponse( code='1207', message='User not found!')
def test_create_books_not_authorized(self, bookstore, create_test_user): user = create_test_user(teardown=True) collection_of_isbns = [{'isbn': isbn} for isbn in EXISTING_ISBNS] with Deauthorizer(bookstore): resp = bookstore.create_books( userId=user.user_id, collectionOfIsbns=collection_of_isbns) assert resp.status_code == HTTPStatus.UNAUTHORIZED assert MessageResponse(**resp.json()) == MessageResponse( code='1200', message='User not authorized!')
def test_delete_book_not_authorized(self, bookstore, create_test_user, create_test_books): user = create_test_user(teardown=True) isbn_resp = create_test_books(user_id=user.user_id, teardown=True) with Deauthorizer(bookstore): resp = bookstore.delete_book(isbn=isbn_resp.isbn, userId=user.user_id) assert resp.status_code == HTTPStatus.UNAUTHORIZED assert MessageResponse(**resp.json()) == MessageResponse( code='1200', message='User not authorized!')
def test_create_new_user_with_weak_password(self, account, username_generator): resp = account.create_user(userName=username_generator(), password=BAD_PASSWORD) assert resp.status_code == HTTPStatus.BAD_REQUEST assert MessageResponse(**resp.json()) == MessageResponse( code='1300', message='Passwords must have at least one non alphanumeric character, ' 'one digit (\'0\'-\'9\'), one uppercase (\'A\'-\'Z\'), ' 'one lowercase (\'a\'-\'z\'), ' 'one special character ' 'and Password must be eight characters or longer.' )
def test_create_books_with_bad_format(self, bookstore, create_test_user): user = create_test_user(teardown=True) collection_of_isbns = [{'isbn': isbn} for isbn in EXISTING_ISBNS] resp = bookstore.create_books(userId=user.user_id, what=collection_of_isbns) assert resp.status_code == HTTPStatus.BAD_REQUEST assert MessageResponse( code='1200', message='UserID and Collection of ISBNs required.')
def test_replace_isbn_with_bad_format(self, bookstore, create_test_user, create_test_books): user = create_test_user(teardown=True) create_test_books(user_id=user.user_id, teardown=True) resp = bookstore.replace_isbn(userId=user.user_id, what=NEW_ISBNS[0]) assert resp.status_code == HTTPStatus.BAD_REQUEST assert MessageResponse(**resp.json()) == MessageResponse(code='1200', message='UserId and ISBN required.')
def test_delete_nonexistent_user(self, account, create_test_user): create_test_user(teardown=True) resp = account.delete_user(userId='invalid_user_id') assert resp.status_code == HTTPStatus.OK assert MessageResponse(**resp.json()) == MessageResponse(code='1207', message='User Id not correct!')
def test_create_new_user_with_bad_format(self, account, username_generator, password_generator): resp = account.create_user(userName=username_generator(), what=password_generator()) assert resp.status_code == HTTPStatus.BAD_REQUEST assert MessageResponse(**resp.json()) == MessageResponse(code='1200', message='UserName and Password required.')
def test_get_nonexistent_book(self, bookstore): resp = bookstore.get_book(isbn=INVALID_ISBNS[0]) assert resp.status_code == HTTPStatus.NOT_FOUND assert MessageResponse(**resp.json()) == MessageResponse( code='1207', message='Book not found!')
def test_login_bad_password(self, account, create_test_user, username_generator, password_generator): username = username_generator() create_test_user(username=username, password=password_generator(), teardown=True) resp = account.login(userName=username, password=BAD_PASSWORD) assert resp.status_code == HTTPStatus.NOT_FOUND assert MessageResponse(**resp.json()) == MessageResponse(code='1207', message='User not found!')
def test_delete_book_with_bad_format(self, bookstore, create_test_user): user = create_test_user(teardown=True) resp = bookstore.delete_book(isbn=INVALID_ISBNS[0], what=user.user_id) assert resp.status_code == HTTPStatus.BAD_REQUEST assert MessageResponse(**resp.json()) == MessageResponse( code='1200', message='UserID and ISBN required.')