def setup_class(cls): super(TestSearchItems, cls).setup_class() Item.delete().execute() for name in NAMES: test_utils.add_item( name=name, description='random description', category='', ) pass
def test_get_favorites2__success(self): user = add_user(USER1, PASS1) user2 = add_user(USER2, PASS2) item = add_item() item2 = add_item() item3 = add_item() add_favorite(user, item) add_favorite(user2, item2) add_favorite(user, item3) resp = open_with_auth(self.app, API_ENDPOINT.format('favorites/'), 'GET', user.email, PASS1, None, None) assert resp.status_code == OK expected_result = EXPECTED_RESULTS['get_favorites2__success'] assert_valid_response(resp.data, expected_result)
def test_delete_only_one_favorites__success(self): user = add_user(USER1, PASS1) item = add_item() item2 = add_item() item3 = add_item() favorite = add_favorite(user, item) add_favorite(user, item2) add_favorite(user, item3) user_path = 'favorites/{}'.format(str(favorite.uuid)) resp = open_with_auth(self.app, API_ENDPOINT.format(user_path), 'DELETE', user.email, PASS1, None, None) assert resp.status_code == OK assert Favorite.select().count() == 2
def test_delete_favorites__fail(self): user = add_user(USER1, PASS1) item = add_item() favorite = add_favorite(user, item) user_path = 'favorites/{}'.format(str(favorite.uuid)) resp = open_with_auth(self.app, API_ENDPOINT.format(user_path), 'DELETE', user.email, PASS2, None, None) assert resp.status_code == UNAUTHORIZED
def test_post_favorites__success(self): user = add_user(USER1, PASS1) item = add_item() favorite = json_favorite(str(item.uuid)) data = format_jsonapi_request('favorite', favorite) resp = open_with_auth(self.app, API_ENDPOINT.format('favorites/'), 'POST', user.email, PASS1, 'application/json', json.dumps(data)) assert resp.status_code == CREATED assert Favorite.select().count() == 1
def test_delete_alien_favorites__fail(self): user1 = add_user(USER1, PASS1) user2 = add_user(USER2, PASS2) item = add_item() favorite = add_favorite(user2, item) user_path = 'favorites/{}'.format(str(favorite.uuid)) resp = open_with_auth(self.app, API_ENDPOINT.format(user_path), 'DELETE', user1.email, PASS1, None, None) assert resp.status_code == NOT_FOUND assert Favorite.select().count() == 1