summaryrefslogtreecommitdiff
path: root/tests/helpers/client_side_db.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-11-19 08:44:56 -0400
committerKali Kaneko <kali@leap.se>2015-11-19 08:49:51 -0400
commit9f12fd1b52ad79873a699b9d3faa29ff3e3c2677 (patch)
tree5f946c6ca58521943c295a439f103a5b864b12f9 /tests/helpers/client_side_db.py
parentd146d1525adfe1f08be9df0f72aac389e2370de5 (diff)
[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.
Diffstat (limited to 'tests/helpers/client_side_db.py')
-rw-r--r--tests/helpers/client_side_db.py50
1 files changed, 28 insertions, 22 deletions
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: