Package: quickbolt
QuickboltAsynchronously make and validate requests!This was forked fromapi-automation-tools.Table of contentsInstallationUsagePytestAsync requests with aiohttp or httpxAsync calls with grpcValidationsExamplesProject structureInstallation$pipinstallquickboltUsagePytestThe CorePytestBase loadsjsonfiles fromcredentialsanddatafolders during setup. Validations and reporting are performed during the teardown.Async requests with aiohttp or httpxMake single or batched style async requests using aiohttp or httpx. Each request method call will generate a csv containing useful data about the request(s). The usual request arguments of aiohttp and httpx are supported.There's a nifty function calledgenerate_batchthat'll intake valid (200 type) request information and return a list of corruptions for execution.fromquickbolt.clientsimportAioRequests,HttpxRequestsaiohttp_requests=AioRequests()httpx_requests=HttpxRequests()batch={'method':'get','headers':{...},'url':'...'}response=aiohttp_requests.request(batch)response=httpx_requests.request(batch)orbatch=[{'method':'get','headers':{...},'url':'...'},{...},...]responses=aiohttp_requests.request(batch)responses=httpx_requests.request(batch)orfromquickbolt.batch_generationimportgenerate_batchbatch=generate_batch("get",...)responses=aiohttp_requests.request(batch)responses=httpx_requests.request(batch)Note: Both clients have an awaitable request method called async_request e.g.await aiohttp_requests.async_request(...)orawait httpx_requests.async_request(...).Note: You can indicate where the batch generator will start looking for path parameters by placing asemicolon (;)where the path parameters start (before a/) e.g.https://httpbin.org/get;/param/value.Async calls with grpcMake single or batched style async calls using grpc. Each call method call will generate a csv containing useful data about the call(s).Seeherefor a quick tutorial on the mechanics of making grpc calls.fromquickbolt.clientsimportAioGPRCfromtests.client.gprc.serversimporthelloworld_pb2,helloworld_pb2_grpcaio_grpc=AioGPRC()options={"address":"localhost:50051",# the address of the server"stub":helloworld_pb2_grpc.GreeterStub,# the stub class reference of the service"method":"SayHello",# the service method to call"method_args":helloworld_pb2.HelloRequest(name="Quickbolt"),# the args the service method accepts}responses=awaitpytest.aio_grpc.call(options)Note: Generate batch is not supported for async grpc calls.ValidationsAfter eachrequest, a scrubbed copy of the csv history of the execution will be generated. This file (or the original) can be used to validate against executions over time. These files will have the same name as the running test, just with thecsvextenstion instead. Any mismatches can be raised as errors and are reported in a separate csv. Historical csv files to be used as reference can be stored in a validations folder at the root level.fromquickbolt.validationsimportValidations...requestsweremadeandcsvfilesweregenerated...validations=Validations()mismatches=awaitvalidations.validate_references(actual_refs={...})mismatches=>[{"values":[{"key":"ACTUAL_CODE","d1":"404","d2":"999"},...],"keys":[...],"skipped_keys":[...],"actual_refs":{...},"expected_refs":{...},"unscrubbed_refs":{...},},{...},]ExamplesAn example of a test -test_get.pyAn example of a base class showing a setup and teardown -some_pytest_base.pyAn example of the scrubbed csv report file generated from running the test -get_scrubbed.csvProject structureThis package requires the following base structure for the project..
├── credentials                         # Optional - credentials
│   └── credentials.json                # Optional - credentials as json
├── tests                               # Required - test files
│   ├── data                            # Optional - test data
│   │   └── data.json                   # Optional - test data as json
│   └── test_some_request.py            # Required - pytest test
└── validations                         # Optional - validation data
    └── some_request.json               # Optional - validation data as json. the validation files 
                                                     directory structure must match the structure of the tests in the tests folder.