def test_assert_valid_token(): fp = "test_fingerprint" test_hmac_secret = "secret" token = fingerprint_hmac(fp, test_hmac_secret) api = CometApi(hmac_secret=test_hmac_secret) with api.create_app().app_context(): assert_valid_token(fp, token)
def client(): # pylint: disable=missing-param-doc,missing-type-doc """Create a Flask test client fixture Yields: flask.testing.FlaskClient: a Flask testing client """ api = CometApi(hmac_secret="secret") @api.register_auth() def override(): if g.test_authorized_for: return g.test_authorized_for return [] @api.register_hydrator() def test_hydrate(issues): return [{"fingerprint": x.fingerprint} for x in issues] @api.register_request_hydrator() def request_hydrator(request): return dict(request.headers) app = api.create_app() with app.app_context(): yield app.test_client()
def app_context_with_request_hydrator(): api = CometApi() @api.register_request_hydrator() def request_hydrator(request): return request app = api.create_app() yield app.app_context()
def bad_client(): # pylint: disable=missing-param-doc,missing-type-doc """Create a bad Flask test client fixture Yields: flask.testing.FlaskClient: a Flask testing client """ api = CometApi() app = api.create_app() with app.app_context(): yield app.test_client()
'You have to login with proper credentials', 401, {'WWW-Authenticate': 'Bearer realm="Login Required"'}) @API.register_hydrator() def hydrate(event_records): """Enriches issues with additional data Args: event_records (List[comet_core.model.EventRecord]): list of EventRecords to hydrate Returns: List[dict]: list of dictionaries with the keys fingerprint and details_html, event_metadata """ results = [] for rec in event_records: md = rec.event_metadata # create custom fields result = { 'fingerprint': rec.fingerprint, 'details': f'{md.get("source_readable")} alert for owner {rec.owner}: {md.get("resource_readable")} has the' f' following issue: {md.get("issue_type_readable")}', } # add all metadata fields result.update(rec.event_metadata) results.append(result) return results # create the API app APP = API.create_app()
def test_no_request_hydrator(): api = CometApi() request_mock = mock.Mock() with api.create_app().app_context(): assert not hydrate_with_request_headers(request_mock)
def test_no_hydrator(): api = CometApi() with api.create_app().app_context(): assert not hydrate_open_issues([])
def app_context(): api = CometApi() app = api.create_app() yield app.app_context()