From 16dff9b02004036a0ab1908ced10629e31b6998a Mon Sep 17 00:00:00 2001 From: Veselin Penev Date: Fri, 7 Dec 2018 12:00:47 +0100 Subject: [PATCH] few more py3 fixes --- automats/automat.py | 2 +- contacts/contactsdb.py | 16 +++++--- .../test_file_upload_download.py | 37 +++++++++---------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/automats/automat.py b/automats/automat.py index 6e92a7a50..ebd1e1aa4 100644 --- a/automats/automat.py +++ b/automats/automat.py @@ -695,7 +695,7 @@ def executeStateChangedCallbacks(self, oldstate, newstate, event_string, args): """ Compare conditions and execute state changed callback methods. """ - for key, cb_list in (self._state_callbacks.items() + self._callbacks_before_die.items()): + for key, cb_list in list(self._state_callbacks.items()) + list(self._callbacks_before_die.items()): old, new = key catched = False if old is None and new is None: diff --git a/contacts/contactsdb.py b/contacts/contactsdb.py index ce9d90acc..11e8a05ff 100644 --- a/contacts/contactsdb.py +++ b/contacts/contactsdb.py @@ -557,7 +557,9 @@ def save_suppliers(path=None, customer_idurl=None): global_id.UrlToGlobalID(customer_idurl), 'supplierids', ) - bpio._write_list(path, suppliers(customer_idurl=customer_idurl)) + lst = suppliers(customer_idurl=customer_idurl) + lst = list(map(strng.to_text, lst)) + bpio._write_list(path, lst) return True def load_suppliers(path=None, customer_idurl=None, all_customers=False): @@ -574,6 +576,7 @@ def load_suppliers(path=None, customer_idurl=None, all_customers=False): if lst is None: lg.warn('did not found suppliers ids at %s' % path) continue + lst = list(map(strng.to_bin, lst)) set_suppliers(lst, customer_idurl=global_id.GlobalUserToIDURL(customer_id)) lg.out(4, 'contactsdb.load_suppliers %d items from %s' % (len(lst), path)) return True @@ -585,6 +588,7 @@ def load_suppliers(path=None, customer_idurl=None, all_customers=False): lst = bpio._read_list(path) if lst is None: lst = list() + lst = list(map(strng.to_bin, lst)) set_suppliers(lst) lg.out(4, 'contactsdb.load_suppliers %d items from %s' % (len(lst), path)) return True @@ -599,7 +603,9 @@ def save_customers(path=None, save_meta_info=False): global _CustomersMetaInfo if path is None: path = settings.CustomerIDsFilename() - bpio._write_list(path, customers()) + lst = customers() + lst = list(map(strng.to_text, lst)) + bpio._write_list(path, lst) if save_meta_info: local_fs.WriteTextFile(settings.CustomersMetaInfoFilename(), jsn.dumps(_CustomersMetaInfo)) @@ -614,6 +620,7 @@ def load_customers(path=None): lst = bpio._read_list(path) if lst is None: lst = list() + lst = list(map(strng.to_bin, lst)) set_customers(lst) _CustomersMetaInfo = jsn.loads( local_fs.ReadTextFile(settings.CustomersMetaInfoFilename()) or '{}' @@ -629,9 +636,8 @@ def save_correspondents(path=None): """ if path is None: path = settings.CorrespondentIDsFilename() - bpio._write_list(path, ["%s %s" % ( - strng.to_text(t[0]), strng.to_text(t[1]),) - for t in correspondents()]) + lst = ["%s %s" % (strng.to_text(t[0]), strng.to_text(t[1]),) for t in correspondents()] + bpio._write_list(path, lst) def load_correspondents(path=None): diff --git a/regression/tests/test_role_customer/test_file_upload_download.py b/regression/tests/test_role_customer/test_file_upload_download.py index 978ff7690..038664a16 100644 --- a/regression/tests/test_role_customer/test_file_upload_download.py +++ b/regression/tests/test_role_customer/test_file_upload_download.py @@ -1,11 +1,10 @@ import time import os -import json import base64 import hashlib import requests -from ..utils import tunnel_url, run_ssh_command_and_wait, run_ssh_curl_and_wait +from ..utils import tunnel_url, run_ssh_command_and_wait def get_hash(path): @@ -46,45 +45,43 @@ def test_customer_1_upload_download_file_with_master(): response = requests.post( url=tunnel_url('customer_1', 'file/create/v1'), - json={'remote_path': remote_path,} + json={ + 'remote_path': remote_path, + }, ) assert response.json()['status'] == 'OK', response.json() - response = run_ssh_curl_and_wait( - host='customer_1', - method='POST', - url='localhost:8180/file/upload/start/v1', - body=json.dumps({ + response = requests.get( + url=tunnel_url('customer_1', 'file/upload/start/v1'), + json={ 'remote_path': remote_path, 'local_path': directory_local_file, 'wait_result': 'true', - }), + }, ) - assert response['status'] == 'OK', response + assert response.json()['status'] == 'OK', response.json() for _ in range(100): - response = run_ssh_curl_and_wait( - host='customer_1', - method='POST', - url='localhost:8180/file/download/start/v1', - body=json.dumps({ + response = requests.get( + url=tunnel_url('customer_1', 'file/download/start/v1'), + json={ 'remote_path': remote_path, 'destination_folder': download_volume, 'wait_result': 'true', - }), + }, ) - if response['status'] == 'OK': + if response.json()['status'] == 'OK': break - if response['errors'][0].startswith('download not possible, uploading'): + if response.json()['errors'][0].startswith('download not possible, uploading'): print('file is not ready for download: retry again in 1 sec') time.sleep(1) else: - assert False, response + assert False, response.json() else: print('download was not successful') - assert False, response + assert False, response.json() assert os.path.exists(directory_dowloaded_file)