def test_verification_process_best_case(monkeypatch): monkeypatch.setenv("STAGE", "dev") monkeypatch.setenv("MOTO", "1") monkeypatch.setenv("CORS_ALLOW_ORIGIN", "http://*****:*****@test.de' submission.status = 'confirmed' session.add(submission) session.commit() items = item_handler.get_all_items(session) assert len(items) == 1 # Junior detectives accepting item jr1 = review_handler.create_review(junior_detective1, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 1 jr2 = review_handler.create_review(junior_detective2, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 2 jr3 = review_handler.create_review(junior_detective3, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 3 jr4 = review_handler.create_review(junior_detective4, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 4 with pytest.raises(Exception): review_handler.create_review(junior_detective5, item, session) # Senior detectives accepting item sr1 = review_handler.create_review(senior_detective1, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 1 sr2 = review_handler.create_review(senior_detective2, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 2 sr3 = review_handler.create_review(senior_detective3, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 3 sr4 = review_handler.create_review(senior_detective4, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 4 with pytest.raises(Exception): review_handler.create_review(senior_detective5, item, session) pairs = review_pair_handler.get_review_pairs_by_item(item.id, session) assert len(pairs) == 4 # Detectives reviewing item reviews = [jr1, jr2, jr3, jr4, sr1, sr2, sr3, sr4] for review in reviews: event = event_creator.get_review_event( review, item.id, "in progress", review.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 event = event_creator.get_review_event( review, item.id, "closed", review.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 # reload object instead of refreshing the session item = item_handler.get_item_by_id(item.id, session) item = item_handler.update_item_warning_tags(item, session) assert item.status == 'closed' assert item.in_progress_reviews_level_1 == 0 assert item.in_progress_reviews_level_2 == 0 assert item.open_reviews_level_1 == 0 assert item.open_reviews_level_2 == 0 assert item.open_reviews == 0 assert item.close_timestamp is not None assert item.warning_tags_calculated == True assert item.result_score == 1 item_dict = item.to_dict(with_warnings=True) assert 'warning_tags' in item_dict assert len(item_dict['warning_tags']) > 0 assert 'text' in item_dict['warning_tags'][0] assert 'icon' in item_dict['warning_tags'][0] assert item_dict['result_score'] == 0 session.expire_all()
def test_verification_process_worst_case(monkeypatch): monkeypatch.setenv("CORS_ALLOW_ORIGIN", "http://localhost:4200") with Session() as session: session = setup_scenarios.create_levels_junior_and_senior_detectives( session) session = setup_scenarios.create_questions(session) junior_detective1 = user_handler.get_user_by_id("1", session) junior_detective2 = user_handler.get_user_by_id("2", session) junior_detective3 = user_handler.get_user_by_id("3", session) junior_detective4 = user_handler.get_user_by_id("4", session) junior_detective5 = user_handler.get_user_by_id("5", session) senior_detective1 = user_handler.get_user_by_id("11", session) senior_detective2 = user_handler.get_user_by_id("12", session) senior_detective3 = user_handler.get_user_by_id("13", session) senior_detective4 = user_handler.get_user_by_id("14", session) senior_detective5 = user_handler.get_user_by_id("15", session) users = user_handler.get_all_users(session) assert len(users) == 10 # Creating an item item = Item() item.content = "This item needs to be checked" item.status = 'open' item.item_type_id = "Type1" item = item_handler.create_item(item, session) items = item_handler.get_all_items(session) assert len(items) == 1 # Junior detectives accepting item jr1 = review_handler.create_review(junior_detective1, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 1 jr2 = review_handler.create_review(junior_detective2, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 2 jr3 = review_handler.create_review(junior_detective3, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 3 jr4 = review_handler.create_review(junior_detective4, item, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 4 with pytest.raises(Exception): review_handler.create_review(junior_detective5, item, session) # Senior detectives accepting item sr1 = review_handler.create_review(senior_detective1, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 1 sr2 = review_handler.create_review(senior_detective2, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 2 sr3 = review_handler.create_review(senior_detective3, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 3 sr4 = review_handler.create_review(senior_detective4, item, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 4 with pytest.raises(Exception): review_handler.create_review(senior_detective5, item, session) pairs = review_pair_handler.get_review_pairs_by_item(item.id, session) assert len(pairs) == 4 # Detective without review in progress trying to get question junior_reviews = [jr1, jr2, jr3, jr4] senior_reviews = [sr1, sr2, sr3, sr4] for review in junior_reviews: event = event_creator.get_review_event( review, item.id, "in progress", review.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 event = event_creator.get_review_event( review, item.id, "closed", review.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 for review in senior_reviews: event = event_creator.get_review_event( review, item.id, "in progress", review.user_id, 4) response = update_review(event, None) assert response['statusCode'] == 200 event = event_creator.get_review_event( review, item.id, "closed", review.user_id, 4) response = update_review(event, None) assert response['statusCode'] == 200 # reload object instead of refreshing the session item = item_handler.get_item_by_id(item.id, session) assert item.status == 'open' assert item.in_progress_reviews_level_1 == 0 assert item.in_progress_reviews_level_2 == 0 assert item.open_reviews_level_1 == 4 assert item.open_reviews_level_2 == 4 assert item.open_reviews == 4 session.expire_all()
def test_verification_process_best_case(monkeypatch): monkeypatch.setenv("STAGE", "dev") monkeypatch.setenv("DBNAME", "Test") conn = boto3.client("ses", region_name="eu-central-1") conn.verify_email_identity(EmailAddress="*****@*****.**") session = get_db_session(True, None) session = setup_scenarios.create_levels_junior_and_senior_detectives( session) session = setup_scenarios.create_questions(session) junior_detective1 = user_handler.get_user_by_id("1", True, session) junior_detective2 = user_handler.get_user_by_id("2", True, session) junior_detective3 = user_handler.get_user_by_id("3", True, session) junior_detective4 = user_handler.get_user_by_id("4", True, session) junior_detective5 = user_handler.get_user_by_id("5", True, session) senior_detective1 = user_handler.get_user_by_id("11", True, session) senior_detective2 = user_handler.get_user_by_id("12", True, session) senior_detective3 = user_handler.get_user_by_id("13", True, session) senior_detective4 = user_handler.get_user_by_id("14", True, session) senior_detective5 = user_handler.get_user_by_id("15", True, session) users = user_handler.get_all_users(True, session) assert len(users) == 10 # Creating an item item = Item() item.content = "This item needs to be checked" item.item_type_id = "Type1" item = item_handler.create_item(item, True, session) assert item.in_progress_reviews_level_1 == 0 assert item.open_reviews_level_1 == 4 assert item.status == 'unconfirmed' item.status = 'open' session.merge(item) submission = Submission() submission.id = 'Submission 1' submission.item_id = item.id submission.mail = '*****@*****.**' submission.status = 'confirmed' session.add(submission) session.commit() items = item_handler.get_all_items(True, session) assert len(items) == 1 # Junior detectives accepting item jr1 = review_handler.create_review(junior_detective1, item, True, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 1 jr2 = review_handler.create_review(junior_detective2, item, True, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 2 jr3 = review_handler.create_review(junior_detective3, item, True, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 3 jr4 = review_handler.create_review(junior_detective4, item, True, session) assert item.open_reviews_level_1 == 4 assert item.in_progress_reviews_level_1 == 4 with pytest.raises(Exception): review_handler.create_review(junior_detective5, item, True, session) # Senior detectives accepting item sr1 = review_handler.create_review(senior_detective1, item, True, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 1 sr2 = review_handler.create_review(senior_detective2, item, True, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 2 sr3 = review_handler.create_review(senior_detective3, item, True, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 3 sr4 = review_handler.create_review(senior_detective4, item, True, session) assert item.open_reviews_level_2 == 4 assert item.in_progress_reviews_level_2 == 4 with pytest.raises(Exception): review_handler.create_review(senior_detective5, item, True, session) pairs = review_pair_handler.get_review_pairs_by_item( item.id, True, session) assert len(pairs) == 4 # Detectives reviewing item reviews = [jr1, jr2, jr3, jr4, sr1, sr2, sr3, sr4] for review in reviews: event = event_creator.get_review_event(review, item.id, "in progress", review.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 session.refresh(review) event = event_creator.get_review_event(review, item.id, "closed", review.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 assert item.status == 'closed' assert item.in_progress_reviews_level_1 == 0 assert item.in_progress_reviews_level_2 == 0 assert item.open_reviews_level_1 == 0 assert item.open_reviews_level_2 == 0 assert item.open_reviews == 0 assert item.close_timestamp is not None send_quota = conn.get_send_quota() sent_count = int(send_quota["SentLast24Hours"]) assert sent_count == 1 session.refresh(submission) assert not submission.mail
def test_get_open_items_for_user(self, monkeypatch): monkeypatch.setenv("DBNAME", "Test") session = get_db_session(True, None) session = setup_scenarios.create_levels_junior_and_senior_detectives( session) session = setup_scenarios.create_questions(session) junior_detective1 = user_handler.get_user_by_id("1", True, session) junior_detective2 = user_handler.get_user_by_id("2", True, session) junior_detective3 = user_handler.get_user_by_id("3", True, session) junior_detective4 = user_handler.get_user_by_id("4", True, session) junior_detective5 = user_handler.get_user_by_id("5", True, session) senior_detective1 = user_handler.get_user_by_id("11", True, session) # Creating 5 items item1 = Item() item1.content = "Item 1" item1.status = "open" item1.item_type_id = "Type1" item1 = item_handler.create_item(item1, True, session) item2 = Item() item2.content = "Item 2" item2.status = "open" item2.item_type_id = "Type1" item2 = item_handler.create_item(item2, True, session) item3 = Item() item3.content = "Item 3" item3.status = "open" item3.item_type_id = "Type1" item3 = item_handler.create_item(item3, True, session) item4 = Item() item4.content = "Item 4" item4.status = "open" item4.item_type_id = "Type1" item4 = item_handler.create_item(item4, True, session) item5 = Item() item5.content = "Item 5" item5.status = "open" item5.item_type_id = "Type1" item5 = item_handler.create_item(item5, True, session) items = item_handler.get_all_items(True, session) assert len(items) == 5 open_items_for_senior = item_handler.get_open_items_for_user( senior_detective1, 5, True, session)['items'] assert len(open_items_for_senior) == 5 open_items_for_junior = item_handler.get_open_items_for_user( junior_detective1, 5, True, session)['items'] assert len(open_items_for_junior) == 5 # JuniorDetective 1 accepting item 1 jr1 = review_handler.create_review(junior_detective1, item1, True, session) open_item_after_accept = item_handler.get_open_items_for_user( junior_detective1, 5, True, session)['items'] assert len(open_item_after_accept) == 1 item1 = item_handler.get_item_by_id(item1.id, True, session) assert item1.in_progress_reviews_level_1 == 1 # Accepting event again should not create a new review review_handler.create_review(junior_detective1, item1, True, session) # app.create_review(accept_event, None, True, session) item1 = item_handler.get_item_by_id(item1.id, True, session) assert item1.in_progress_reviews_level_1 == 1 # JuniorDetective 1 finishing review event = event_creator.get_review_event(jr1, item1.id, "in progress", jr1.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 event = event_creator.get_review_event(jr1, item1.id, "closed", jr1.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 # For JuniorDetective1 only 4 cases should be available open_items_after_submission = item_handler.get_open_items_for_user( junior_detective1, 5, True, session)['items'] assert len(open_items_after_submission) == 4 open_items_limit_3 = item_handler.get_open_items_for_user( junior_detective1, 3, True, session)['items'] assert len(open_items_limit_3) == 3 open_items_after_other_review = item_handler.get_open_items_for_user( junior_detective4, 5, True, session)['items'] assert len(open_items_after_other_review) == 5 # 4 Junior Detectives reviewing Item 2 jr1 = review_handler.create_review(junior_detective1, item2, True, session) jr2 = review_handler.create_review(junior_detective2, item2, True, session) jr3 = review_handler.create_review(junior_detective3, item2, True, session) jr4 = review_handler.create_review(junior_detective4, item2, True, session) reviews = [jr1, jr2, jr3, jr4] for review in reviews: event = event_creator.get_review_event(review, item2.id, "in progress", review.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 event = event_creator.get_review_event(review, item2.id, "closed", review.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 # 4 Cases should be available for Detective 5 open_items_after_other_review = item_handler.get_open_items_for_user( junior_detective5, 5, True, session)['items'] assert len(open_items_after_other_review) == 4 # 5 cases should be available for senior open_items_for_senior = item_handler.get_open_items_for_user( senior_detective1, 5, True, session)['items'] assert len(open_items_for_senior) == 5 # Senior detective accepting item 1 sr1 = review_handler.create_review(senior_detective1, item1, True, session) open_item_after_accept = item_handler.get_open_items_for_user( senior_detective1, 5, True, session)['items'] assert len(open_item_after_accept) == 1 # Senior detective finishing review event = event_creator.get_review_event(sr1, item1.id, "in progress", sr1.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 event = event_creator.get_review_event(sr1, item1.id, "closed", sr1.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 # For SeniorDetective1 only 4 cases should be available open_items_after_submission = item_handler.get_open_items_for_user( senior_detective1, 5, True, session)['items'] assert len(open_items_after_submission) == 4 # SeniorDetective 1 accepting item 3 sr1 = review_handler.create_review(senior_detective1, item3, True, session) open_item_after_accept = item_handler.get_open_items_for_user( senior_detective1, 5, True, session)['items'] assert len(open_item_after_accept) == 1 item3 = item_handler.get_item_by_id(item3.id, True, session) assert item3.in_progress_reviews_level_2 == 1 # Accepting event again should not create a new review review_handler.create_review(senior_detective1, item3, True, session) item3 = item_handler.get_item_by_id(item3.id, True, session) assert item3.in_progress_reviews_level_2 == 1 # SeniorDetective 1 finishing review event = event_creator.get_review_event(sr1, item3.id, "in progress", sr1.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 event = event_creator.get_review_event(sr1, item3.id, "closed", sr1.user_id, 1, session) response = update_review(event, None, True, session) assert response['statusCode'] == 200 open_items_for_senior = item_handler.get_open_items_for_user( senior_detective1, 5, True, session)['items'] assert len(open_items_for_senior) == 3 event = { "requestContext": { "identity": { "cognitoAuthenticationProvider": "...CognitoSignIn:{}".format(senior_detective1.id) } } } response = get_open_items(event, None, True, session) assert 'is_open_review' in response['headers'] assert response['headers']['is_open_review'] == "False" body = json.loads(response['body']) assert len(body) == 3
def create_review(event, context, is_test=False, session=None): """Creates a new review. Parameters ---------- - user_id is retrieved from the event - item_id is retrieved from query parameters Returns ------ - Status code 201 (Created) - The newly created review """ logger = logging.getLogger() logger.setLevel(logging.INFO) helper.log_method_initiated("Create Review", event, logger) if session == None: session = connection_handler.get_db_session(False, None) try: # get item id from body item_id = json.loads(event['body'])['item_id'] if isinstance( event['body'], str) else event['body']['item_id'] # get cognito id user_id = helper.cognito_id_from_event(event) except Exception: return helper.get_text_response( 400, "Malformed request. Please provide a valid request.", event, is_test) try: # get user and item from the db user = user_handler.get_user_by_id(user_id, is_test, session) except Exception: return helper.get_text_response(404, "No user found.", event, is_test) item = item_handler.get_item_by_id(item_id, is_test, session) if item is None: return helper.get_text_response(404, "No item found.", event, is_test) # Try to accept item try: review = review_handler.create_review(user, item, is_test, session) response = { "statusCode": 201, 'headers': { "content-type": "application/json; charset=utf-8" }, "body": json.dumps(review.to_dict_with_questions_and_answers()) } response_cors = helper.set_cors(response, event, is_test) return response_cors except: return helper.get_text_response( 500, "Internal server error. Stacktrace: {}".format( traceback.format_exc()), event, is_test)
def test_get_open_items_for_user(self, monkeypatch): monkeypatch.setenv("CORS_ALLOW_ORIGIN", "http://localhost:4200") with Session() as session: session = setup_scenarios.create_levels_junior_and_senior_detectives( session) session = setup_scenarios.create_questions(session) junior_detective1 = user_handler.get_user_by_id("1", session) junior_detective2 = user_handler.get_user_by_id("2", session) junior_detective3 = user_handler.get_user_by_id("3", session) junior_detective4 = user_handler.get_user_by_id("4", session) junior_detective5 = user_handler.get_user_by_id("5", session) senior_detective1 = user_handler.get_user_by_id("11", session) # Creating 5 items item1 = Item() item1.content = "Item 1" item1.status = "open" item1.item_type_id = "Type1" item1.open_timestamp = datetime.now() + timedelta(seconds=1) item1 = item_handler.create_item(item1, session) url = URL() url.id = str(uuid4()) url.url = 'www.test.com' item_url = ItemURL() item_url.id = str(uuid4()) item_url.item_id = item1.id item_url.url_id = url.id session.add_all([url, item_url]) item2 = Item() item2.content = "Item 2" item2.status = "open" item2.item_type_id = "Type1" item2.open_timestamp = datetime.now() + timedelta(seconds=2) item2 = item_handler.create_item(item2, session) item3 = Item() item3.content = "Item 3" item3.status = "open" item3.item_type_id = "Type1" item3.open_timestamp = datetime.now() + timedelta(seconds=3) item3 = item_handler.create_item(item3, session) item4 = Item() item4.content = "Item 4" item4.status = "open" item4.item_type_id = "Type1" item4.open_timestamp = datetime.now() + timedelta(seconds=4) item4 = item_handler.create_item(item4, session) item5 = Item() item5.content = "Item 5" item5.status = "open" item5.item_type_id = "Type1" item5.open_timestamp = datetime.now() + timedelta(seconds=5) item5 = item_handler.create_item(item5, session) items = item_handler.get_all_items(session) assert len(items) == 5 open_items_for_senior = item_handler.get_open_items_for_user( senior_detective1, 5, session)['items'] assert len(open_items_for_senior) == 5 open_items_for_junior = item_handler.get_open_items_for_user( junior_detective1, 5, session)['items'] assert len(open_items_for_junior) == 5 # JuniorDetective 1 accepting item 1 jr1 = review_handler.create_review(junior_detective1, item1, session) open_item_after_accept = item_handler.get_open_items_for_user( junior_detective1, 5, session)['items'] assert len(open_item_after_accept) == 1 item1 = item_handler.get_item_by_id(item1.id, session) assert item1.in_progress_reviews_level_1 == 1 # Accepting event again should not create a new review review_handler.create_review(junior_detective1, item1, session) # app.create_review(accept_event, None, True, session) item1 = item_handler.get_item_by_id(item1.id, session) assert item1.in_progress_reviews_level_1 == 1 # JuniorDetective 1 finishing review event = event_creator.get_review_event(jr1, item1.id, "in progress", jr1.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 event = event_creator.get_review_event(jr1, item1.id, "closed", jr1.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 # For JuniorDetective1 only 4 cases should be available open_items_after_submission = item_handler.get_open_items_for_user( junior_detective1, 5, session)['items'] assert len(open_items_after_submission) == 4 open_items_limit_3 = item_handler.get_open_items_for_user( junior_detective1, 3, session)['items'] assert len(open_items_limit_3) == 3 open_items_after_other_review = item_handler.get_open_items_for_user( junior_detective4, 5, session)['items'] assert len(open_items_after_other_review) == 5 # 4 Junior Detectives reviewing Item 2 item2 = item_handler.get_item_by_id(item2.id, session) jr1 = review_handler.create_review(junior_detective1, item2, session) jr2 = review_handler.create_review(junior_detective2, item2, session) jr3 = review_handler.create_review(junior_detective3, item2, session) jr4 = review_handler.create_review(junior_detective4, item2, session) reviews = [jr1, jr2, jr3, jr4] for review in reviews: event = event_creator.get_review_event(review, item2.id, "in progress", review.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 event = event_creator.get_review_event(review, item2.id, "closed", review.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 # 4 Cases should be available for Detective 5 open_items_after_other_review = item_handler.get_open_items_for_user( junior_detective5, 5, session)['items'] assert len(open_items_after_other_review) == 4 # 5 cases should be available for senior open_items_for_senior = item_handler.get_open_items_for_user( senior_detective1, 5, session)['items'] assert len(open_items_for_senior) == 5 # Senior detective accepting item 1 sr1 = review_handler.create_review(senior_detective1, item1, session) open_item_after_accept = item_handler.get_open_items_for_user( senior_detective1, 5, session)['items'] assert len(open_item_after_accept) == 1 # Senior detective finishing review event = event_creator.get_review_event(sr1, item1.id, "in progress", sr1.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 event = event_creator.get_review_event(sr1, item1.id, "closed", sr1.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 # For SeniorDetective1 only 4 cases should be available open_items_after_submission = item_handler.get_open_items_for_user( senior_detective1, 5, session)['items'] assert len(open_items_after_submission) == 4 # SeniorDetective 1 accepting item 3 item3 = item_handler.get_item_by_id(item3.id, session) sr1 = review_handler.create_review(senior_detective1, item3, session) open_item_after_accept = item_handler.get_open_items_for_user( senior_detective1, 5, session)['items'] assert len(open_item_after_accept) == 1 item3 = item_handler.get_item_by_id(item3.id, session) assert item3.in_progress_reviews_level_2 == 1 # Accepting event again should not create a new review review_handler.create_review(senior_detective1, item3, session) item3 = item_handler.get_item_by_id(item3.id, session) assert item3.in_progress_reviews_level_2 == 1 # SeniorDetective 1 finishing review event = event_creator.get_review_event(sr1, item3.id, "in progress", sr1.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 event = event_creator.get_review_event(sr1, item3.id, "closed", sr1.user_id, 1) response = update_review(event, None) assert response['statusCode'] == 200 # Accepting closed item again should not create a new review event = event_creator.get_create_review_event( senior_detective1.id, item3.id) response = create_review.create_review(event, None) assert response['statusCode'] == 500 open_items_for_senior = item_handler.get_open_items_for_user( senior_detective1, 5, session)['items'] assert len(open_items_for_senior) == 3 event = { "requestContext": { "identity": { "cognitoAuthenticationProvider": "...CognitoSignIn:{}".format(senior_detective1.id) } } } response = get_open_items(event, None) # assert 'is_open_review' in response['headers'] # assert response['headers']['is_open_review'] == "False" body = json.loads(response['body']) assert 'is_open_review' in body assert body['is_open_review'] is False assert len(body['items']) == 3