From 9f12fd1b52ad79873a699b9d3faa29ff3e3c2677 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 19 Nov 2015 08:44:56 -0400 Subject: [bug] do not fail if no requests/srp dependencies present client_side_db helper has some extra functions that can be useful in the future for further tests, but right now it shouldn't depend on requests, since it already get all the relevant soledad info passed as arguments. for the same reason, it doesn't need to depend on srp, since we pass the token. --- tests/helpers/client_side_db.py | 50 +++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'tests/helpers') diff --git a/tests/helpers/client_side_db.py b/tests/helpers/client_side_db.py index d2a4bbcb..2f8c220f 100644 --- a/tests/helpers/client_side_db.py +++ b/tests/helpers/client_side_db.py @@ -2,11 +2,15 @@ import logging import os import tempfile import getpass -import requests -import srp._pysrp as srp import binascii import json +try: + import requests + import srp._pysrp as srp +except ImportError: + pass + from twisted.internet.defer import inlineCallbacks from leap.soledad.client import Soledad @@ -14,6 +18,7 @@ from leap.soledad.client import Soledad """ Helper functions to give access to client-side Soledad database. +Copied over from soledad/scripts folder. """ # create a logger @@ -33,6 +38,27 @@ def _fail(reason): exit(2) +def get_soledad_instance(uuid, passphrase, basedir, server_url, cert_file, + token): + # setup soledad info + logger.info('UUID is %s' % uuid) + logger.info('Server URL is %s' % server_url) + secrets_path = os.path.join( + basedir, '%s.secret' % uuid) + local_db_path = os.path.join( + basedir, '%s.db' % uuid) + # instantiate soledad + return Soledad( + uuid, + unicode(passphrase), + secrets_path=secrets_path, + local_db_path=local_db_path, + server_url=server_url, + cert_file=cert_file, + auth_token=token, + defer_encryption=True) + + def _get_api_info(provider): info = requests.get( 'https://'+provider+'/provider.json', verify=False).json() @@ -96,26 +122,6 @@ def _get_soledad_info(username, provider, passphrase, basedir): return auth[2]['id'], server_url, cert_file, auth[2]['token'] -def get_soledad_instance(uuid, passphrase, basedir, server_url, cert_file, - token): - # setup soledad info - logger.info('UUID is %s' % uuid) - logger.info('Server URL is %s' % server_url) - secrets_path = os.path.join( - basedir, '%s.secret' % uuid) - local_db_path = os.path.join( - basedir, '%s.db' % uuid) - # instantiate soledad - return Soledad( - uuid, - unicode(passphrase), - secrets_path=secrets_path, - local_db_path=local_db_path, - server_url=server_url, - cert_file=cert_file, - auth_token=token, - defer_encryption=True) - def _get_passphrase(args): passphrase = args.passphrase if passphrase is None: -- cgit v1.2.3