-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_: add multiple status-backend instances (#6104)
* test_: add multiple status-backend instances * test_: reliable schemas
- Loading branch information
1 parent
11cf42b
commit 35dc84f
Showing
13 changed files
with
144 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import json | ||
import logging | ||
import jsonschema | ||
import requests | ||
|
||
from conftest import option | ||
from json import JSONDecodeError | ||
|
||
class RpcClient: | ||
|
||
def __init__(self, rpc_url, client=requests.Session()): | ||
self.client = client | ||
self.rpc_url = rpc_url | ||
|
||
def _check_decode_and_key_errors_in_response(self, response, key): | ||
try: | ||
return response.json()[key] | ||
except json.JSONDecodeError: | ||
raise AssertionError( | ||
f"Invalid JSON in response: {response.content}") | ||
except KeyError: | ||
raise AssertionError( | ||
f"Key '{key}' not found in the JSON response: {response.content}") | ||
|
||
def verify_is_valid_json_rpc_response(self, response, _id=None): | ||
assert response.status_code == 200, f"Got response {response.content}, status code {response.status_code}" | ||
assert response.content | ||
self._check_decode_and_key_errors_in_response(response, "result") | ||
|
||
if _id: | ||
try: | ||
if _id != response.json()["id"]: | ||
raise AssertionError( | ||
f"got id: {response.json()['id']} instead of expected id: {_id}" | ||
) | ||
except KeyError: | ||
raise AssertionError(f"no id in response {response.json()}") | ||
return response | ||
|
||
def verify_is_json_rpc_error(self, response): | ||
assert response.status_code == 200 | ||
assert response.content | ||
self._check_decode_and_key_errors_in_response(response, "error") | ||
|
||
def rpc_request(self, method, params=[], request_id=13, url=None): | ||
url = url if url else self.rpc_url | ||
data = {"jsonrpc": "2.0", "method": method, "id": request_id} | ||
if params: | ||
data["params"] = params | ||
logging.info(f"Sending POST request to url {url} with data: {json.dumps(data, sort_keys=True, indent=4)}") | ||
response = self.client.post(url, json=data) | ||
try: | ||
logging.info(f"Got response: {json.dumps(response.json(), sort_keys=True, indent=4)}") | ||
except JSONDecodeError: | ||
logging.info(f"Got response: {response.content}") | ||
return response | ||
|
||
def rpc_valid_request(self, method, params=[], _id=None, url=None): | ||
response = self.rpc_request(method, params, _id, url) | ||
self.verify_is_valid_json_rpc_response(response, _id) | ||
return response | ||
|
||
def verify_json_schema(self, response, method): | ||
with open(f"{option.base_dir}/schemas/{method}", "r") as schema: | ||
jsonschema.validate(instance=response, | ||
schema=json.load(schema)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ services: | |
- 8354:8354 | ||
status-backend: | ||
ports: | ||
- 3334:3333 | ||
- 3314-3324:3333 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.