def when_get_reviews_should_work_only_when_editor(self, app): create_users() create_roles() result = TestClient(app.test_client())\ .with_auth(email=get_sandbox_role_email('editor'))\ .get('/reviews') assert result.status_code == 200 result = TestClient(app.test_client())\ .with_auth(email=get_sandbox_role_email('master'))\ .get('/reviews') assert result.status_code == 200
def test_get_articles_should_work_only_when_logged_in(self, app): # when auth_request = TestClient(app.test_client())\ .with_auth(email=get_sandbox_role_email('user')) result = auth_request.get('/articles') # then assert result.status_code == 401
def create_users(): logger.info('create_users') hashed_default_password = get_hashed_default_password() users_by_name = {} user_types = [role_type.value for role_type in RoleType] + ['master', 'user'] count = 0 for user_type in user_types: for role_index in range(USERS_BY_TYPE_COUNT): user_dict = { "email": get_sandbox_role_email(user_type, role_index), "firstName": pick_one(FIRST_NAMES, count), "lastName": pick_one(LAST_NAMES, count), } if user_type == 'reviewer': user_dict.update({ "academicWebsite": "https://fr.wikipedia.org/wiki/Christiane_Faure", "affiliation": pick_one(AFFILIATIONS, count), "expertise": "{}, {}".format(pick_one(EXPERTISE, count), pick_one(EXPERTISE, count + 1)), "orcidId": "0000-0003-3164-2391", "title": pick_one(TITLES, count) }) if user_type == 'editor': user_dict.update({ "affiliation": "Climate Feedback", "title": "Science Editor" }) user = User(**user_dict) user.password = hashed_default_password users_by_name['{} {}'.format(user_type, role_index)] = user count += 1 ApiHandler.save(*users_by_name.values()) for user_type in user_types: for role_index in range(USERS_BY_TYPE_COUNT): store_public_object_from_sandbox_assets( "thumbs", users_by_name['{} {}'.format(user_type, role_index)], "{}_{}".format(user_type, role_index)) logger.info('created {} users'.format(len(users_by_name))) return users_by_name
def when_get_reviews_should_return_a_list_of_reviews(self, app): deactivate_logger('info') create_users() create_roles() create_articles() create_evaluations() create_reviews() result = TestClient(app.test_client()) \ .with_auth(email=get_sandbox_role_email('editor')) \ .get('/reviews') assert result.status_code == 200 reviews = result.json assert len(reviews) == 3
def when_get_articles_should_return_a_list_of_articles(self, app): # given deactivate_logger('info') create_users() create_articles() auth_request = TestClient(app.test_client())\ .with_auth(email=get_sandbox_role_email('master')) # when result = auth_request.get('/articles') # then assert result.status_code == 200 articles = result.json assert len(articles) == 6