|
| 1 | +import asyncio |
| 2 | +import json |
| 3 | + |
| 4 | +import httpx |
| 5 | +from kiota_abstractions.base_request_configuration import RequestConfiguration |
| 6 | + |
| 7 | +from horreum import new_horreum_client, ClientConfiguration, AuthMethod, HorreumCredentials |
| 8 | +from horreum.raw_client.api.run.test.test_request_builder import TestRequestBuilder |
| 9 | +from horreum.raw_client.models.extractor import Extractor |
| 10 | +from horreum.raw_client.models.run import Run |
| 11 | +from horreum.raw_client.models.schema import Schema |
| 12 | +from horreum.raw_client.models.test import Test |
| 13 | +from horreum.raw_client.models.transformer import Transformer |
| 14 | + |
| 15 | +DEFAULT_CONNECTION_TIMEOUT: int = 30 |
| 16 | +DEFAULT_REQUEST_TIMEOUT: int = 100 |
| 17 | + |
| 18 | +base_url = "http://localhost:8080" |
| 19 | +# follow https://horreum.hyperfoil.io/docs/tasks/api-keys/#api-key-creation |
| 20 | +api_key = "<REPLACE_WITH_API_KEY>" |
| 21 | + |
| 22 | + |
| 23 | +async def example(): |
| 24 | + timeout = httpx.Timeout(DEFAULT_REQUEST_TIMEOUT, connect=DEFAULT_CONNECTION_TIMEOUT) |
| 25 | + http_client = httpx.AsyncClient(timeout=timeout, http2=False, verify=False) |
| 26 | + client = await new_horreum_client( |
| 27 | + base_url, |
| 28 | + credentials=HorreumCredentials( |
| 29 | + apikey=api_key |
| 30 | + ), |
| 31 | + client_config=ClientConfiguration( |
| 32 | + http_client=http_client, |
| 33 | + auth_method=AuthMethod.API_KEY |
| 34 | + ) |
| 35 | + ) |
| 36 | + |
| 37 | + server_version = await client.raw_client.api.config.version.get() |
| 38 | + print(server_version) |
| 39 | + |
| 40 | + # create the schema |
| 41 | + schema_data = json.load(open("./data/acme_benchmark_schema.json"), object_hook=lambda d: Schema(**d)) |
| 42 | + schema_id = await client.raw_client.api.schema.post(schema_data) |
| 43 | + |
| 44 | + # create transformers |
| 45 | + transformer_data = json.load(open("./data/acme_transformer.json"), object_hook=lambda d: Transformer(**d)) |
| 46 | + extractors_data = json.load(open("./data/acme_transformer_extractors.json"), |
| 47 | + object_hook=lambda d: Extractor(**d)) |
| 48 | + transformer_data.extractors = extractors_data |
| 49 | + transformer_id = await client.raw_client.api.schema.by_id(schema_id).transformers.post(transformer_data) |
| 50 | + |
| 51 | + # create the test |
| 52 | + test_data = json.load(open("./data/roadrunner_test.json"), object_hook=lambda d: Test(**d)) |
| 53 | + test = await client.raw_client.api.test.post(test_data) |
| 54 | + await client.raw_client.api.test.by_id(test.id).transformers.post([transformer_id]) |
| 55 | + |
| 56 | + # upload the run |
| 57 | + run = json.load(open("./data/roadrunner_run.json"), object_hook=lambda d: Run(**d)) |
| 58 | + run_data = json.load(open("./data/roadrunner_run_data.json")) |
| 59 | + run.data = json.dumps(run_data) |
| 60 | + query_params = TestRequestBuilder.TestRequestBuilderPostQueryParameters(test=str(test.id)) |
| 61 | + config = RequestConfiguration(query_parameters=query_params) |
| 62 | + await client.raw_client.api.run.test.post(run, config) |
| 63 | + |
| 64 | + |
| 65 | +if __name__ == '__main__': |
| 66 | + asyncio.run(example()) |
0 commit comments