From 067efcca73723675eb28afef3656ca3bdf47e116 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Mon, 7 Oct 2019 11:58:28 +0100 Subject: [PATCH] Clean unused imports and more cleanup --- apps/cli/blob.py | 3 ++- apps/cli/pisa-cli.py | 7 ++++--- test/add_appointment_test.py | 7 ++++--- test/appointment_tests.py | 21 ++++++--------------- test/simulator/bitcoin_sim_tests.py | 3 +-- test/unit/test_cleaner.py | 1 - 6 files changed, 17 insertions(+), 25 deletions(-) diff --git a/apps/cli/blob.py b/apps/cli/blob.py index 968f9e3..ac7dfa3 100644 --- a/apps/cli/blob.py +++ b/apps/cli/blob.py @@ -1,6 +1,7 @@ -from binascii import hexlify, unhexlify from hashlib import sha256 +from binascii import hexlify, unhexlify from cryptography.hazmat.primitives.ciphers.aead import AESGCM + from apps.cli import SUPPORTED_HASH_FUNCTIONS, SUPPORTED_CIPHERS diff --git a/apps/cli/pisa-cli.py b/apps/cli/pisa-cli.py index 3dd22f1..3252f79 100644 --- a/apps/cli/pisa-cli.py +++ b/apps/cli/pisa-cli.py @@ -5,13 +5,14 @@ import json import logging import requests from sys import argv -from getopt import getopt, GetoptError from hashlib import sha256 -from binascii import hexlify, unhexlify +from binascii import unhexlify +from getopt import getopt, GetoptError from requests import ConnectTimeout, ConnectionError -from apps.cli import DEFAULT_PISA_API_SERVER, DEFAULT_PISA_API_PORT, CLIENT_LOG_FILE + from apps.cli.blob import Blob from apps.cli.help import help_add_appointment, help_get_appointment +from apps.cli import DEFAULT_PISA_API_SERVER, DEFAULT_PISA_API_PORT, CLIENT_LOG_FILE def show_message(message, debug, logging): diff --git a/test/add_appointment_test.py b/test/add_appointment_test.py index 35aa1b0..1608779 100644 --- a/test/add_appointment_test.py +++ b/test/add_appointment_test.py @@ -1,12 +1,13 @@ import os import json -import requests import time +import requests from copy import deepcopy from hashlib import sha256 -from binascii import hexlify, unhexlify -from apps.cli.blob import Blob +from binascii import unhexlify + from pisa import HOST, PORT +from apps.cli.blob import Blob from pisa.utils.auth_proxy import AuthServiceProxy from pisa.conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT diff --git a/test/appointment_tests.py b/test/appointment_tests.py index a35dc59..40e2f61 100644 --- a/test/appointment_tests.py +++ b/test/appointment_tests.py @@ -1,21 +1,12 @@ -import logging +import pisa.conf as conf from pisa.inspector import Inspector from pisa.appointment import Appointment -from pisa import errors -from pisa.utils.authproxy import AuthServiceProxy, JSONRPCException -from pisa.conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT, SUPPORTED_HASH_FUNCTIONS, \ - SUPPORTED_CIPHERS, TEST_LOG_FILE - -logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO, handlers=[ - logging.FileHandler(TEST_LOG_FILE) -]) +from pisa import errors, logging, bitcoin_cli +from pisa.utils.auth_proxy import JSONRPCException appointment = {"locator": None, "start_time": None, "end_time": None, "dispute_delta": None, "encrypted_blob": None, "cipher": None, "hash_function": None} -bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % (BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, - BTC_RPC_PORT)) - try: block_height = bitcoin_cli.getblockcount() @@ -54,7 +45,7 @@ cipher_rets = [errors.APPOINTMENT_EMPTY_FIELD, errors.APPOINTMENT_WRONG_FIELD_TY hash_function_rets = [errors.APPOINTMENT_EMPTY_FIELD, errors.APPOINTMENT_WRONG_FIELD_TYPE, errors.APPOINTMENT_HASH_FUNCTION_NOT_SUPPORTED, errors.APPOINTMENT_HASH_FUNCTION_NOT_SUPPORTED] -inspector = Inspector(debug=True, logging=logging) +inspector = Inspector() print("Locator tests\n") for locator, ret in zip(locators, locators_rets): @@ -119,7 +110,7 @@ for cipher, ret in zip(ciphers, cipher_rets): print(r) # Setting the cipher to the only supported one for now -appointment['cipher'] = SUPPORTED_CIPHERS[0] +appointment['cipher'] = conf.SUPPORTED_CIPHERS[0] print("\nHash function tests\n") for hash_function, ret in zip(hash_functions, hash_function_rets): @@ -130,7 +121,7 @@ for hash_function, ret in zip(hash_functions, hash_function_rets): print(r) # Setting the cipher to the only supported one for now -appointment['hash_function'] = SUPPORTED_HASH_FUNCTIONS[0] +appointment['hash_function'] = conf.SUPPORTED_HASH_FUNCTIONS[0] r = inspector.inspect(appointment) assert type(r) == Appointment diff --git a/test/simulator/bitcoin_sim_tests.py b/test/simulator/bitcoin_sim_tests.py index bc5f45a..cb1c5bb 100644 --- a/test/simulator/bitcoin_sim_tests.py +++ b/test/simulator/bitcoin_sim_tests.py @@ -1,6 +1,5 @@ import os -import binascii -from pisa.utils.authproxy import AuthServiceProxy, JSONRPCException +from pisa.utils.auth_proxy import AuthServiceProxy, JSONRPCException from pisa.conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT from pisa.tools import check_txid_format diff --git a/test/unit/test_cleaner.py b/test/unit/test_cleaner.py index de1be8a..5308ca6 100644 --- a/test/unit/test_cleaner.py +++ b/test/unit/test_cleaner.py @@ -1,7 +1,6 @@ import random from os import urandom from uuid import uuid4 -from binascii import hexlify from pisa import logging from pisa.responder import Job