From 24a451c108fa0f664838d6a8f59236187d986f51 Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Mon, 28 Oct 2019 15:22:45 +0700 Subject: [PATCH] Avoiding long strings by using random dummy txids; code formatting --- test/apps/cli/test_pisa_cli.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/test/apps/cli/test_pisa_cli.py b/test/apps/cli/test_pisa_cli.py index dc545b2..c4a2228 100644 --- a/test/apps/cli/test_pisa_cli.py +++ b/test/apps/cli/test_pisa_cli.py @@ -10,6 +10,7 @@ from cryptography.hazmat.primitives.asymmetric import ec import apps.cli.pisa_cli as pisa_cli from apps.cli import PISA_PUBLIC_KEY +from test.unit.conftest import get_random_value_hex # TODO: should find a way of doing without this from apps.cli.pisa_cli import build_appointment @@ -27,18 +28,18 @@ pisa_cli.pisa_api_port = 12345 pisa_endpoint = pisa_cli.pisa_api_server + ":" + str(pisa_cli.pisa_api_port) dummy_appointment_request = { - "tx": "01000000018c8414a5c6b39130304af37b8d053c6b225df525877e5e0cf73a147f2c2edcdb0100000000ffffffff01f82a0000000000001976a9146fe8102ebe0fccb56de43ec82601ba16c68496af88ac00000000", - "tx_id": "dbdc2e2c7f143af70c5e7e8725f55d226b3c058d7bf34a303091b3c6a514848c", + "tx": get_random_value_hex(192), + "tx_id": get_random_value_hex(32), "start_time": 1500, "end_time": 50000, - "dispute_delta": 200 + "dispute_delta": 200, } dummy_appointment = build_appointment(**dummy_appointment_request) def sign_appointment(sk, appointment): - data = json.dumps(appointment, sort_keys=True, separators=(',', ':')).encode('utf-8') - return hexlify(sk.sign(data, ec.ECDSA(hashes.SHA256()))).decode('utf-8') + data = json.dumps(appointment, sort_keys=True, separators=(",", ":")).encode("utf-8") + return hexlify(sk.sign(data, ec.ECDSA(hashes.SHA256()))).decode("utf-8") def test_is_appointment_signature_valid(): @@ -56,12 +57,9 @@ def test_add_appointment(): # Simulate a request to add_appointment for dummy_appointment, make sure that the right endpoint is requested # and the return value is True - response = { - 'locator': dummy_appointment['locator'], - 'signature': sign_appointment(pisa_sk, dummy_appointment) - } + response = {"locator": dummy_appointment["locator"], "signature": sign_appointment(pisa_sk, dummy_appointment)} - request_url = 'http://{}/'.format(pisa_endpoint) + request_url = "http://{}/".format(pisa_endpoint) responses.add(responses.POST, request_url, json=response, status=200) result = pisa_cli.add_appointment([json.dumps(dummy_appointment_request)]) @@ -77,11 +75,11 @@ def test_add_appointment_with_invalid_signature(): # Simulate a request to add_appointment for dummy_appointment, but sign with a different key, # make sure that the right endpoint is requested, but the return value is False response = { - 'locator': dummy_appointment['locator'], - 'signature': sign_appointment(other_sk, dummy_appointment) # signing with a different key + "locator": dummy_appointment["locator"], + "signature": sign_appointment(other_sk, dummy_appointment), # signing with a different key } - request_url = 'http://{}/'.format(pisa_endpoint) + request_url = "http://{}/".format(pisa_endpoint) responses.add(responses.POST, request_url, json=response, status=200) result = pisa_cli.add_appointment([json.dumps(dummy_appointment_request)])