def test_business_comment_json_output(session, client, jwt): """Assert the json output of a comment is correctly formatted.""" identifier = 'CP7654321' b = factory_business(identifier) u = User(username='******', firstname='firstname', lastname='lastname', sub='sub', iss='iss') u.save() now = datetime.datetime(1970, 1, 1, 0, 0).replace(tzinfo=datetime.timezone.utc) with freeze_time(now): factory_business_comment(b, 'some specific text', u) rv = client.get(f'/api/v2/businesses/{identifier}/comments', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.OK == rv.status_code assert 'some specific text' == rv.json.get('comments')[0].get( 'comment').get('comment') assert 'firstname lastname' == rv.json.get('comments')[0].get( 'comment').get('submitterDisplayName') assert now.isoformat() == rv.json.get('comments')[0].get( 'comment').get('timestamp')
def test_get_all_business_comments_only_one(session, client, jwt): """Assert that a list of comments with a single comment is returned correctly.""" identifier = 'CP7654321' b = factory_business(identifier) factory_business_comment(b) rv = client.get(f'/api/v1/businesses/{identifier}/comments', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.OK == rv.status_code assert 1 == len(rv.json.get('comments'))
def test_get_all_business_comments_multiple(session, client, jwt): """Assert that multiple comments are returned correctly.""" identifier = 'CP7654321' b = factory_business(identifier) factory_business_comment(b) factory_business_comment(b, 'other text') rv = client.get(f'/api/v1/businesses/{identifier}/comments', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.OK == rv.status_code assert 2 == len(rv.json.get('comments'))
def test_get_one_business_comment_by_id(session, client, jwt): """Assert that a single comment is returned correctly.""" identifier = 'CP7654321' b = factory_business(identifier) c = factory_business_comment(b, 'some specific text') rv = client.get(f'/api/v1/businesses/{identifier}/comments/{c.id}', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.OK == rv.status_code assert 'some specific text' == rv.json.get('comment').get('comment')