summaryrefslogtreecommitdiff
path: root/tests/helpers
diff options
context:
space:
mode:
authorvarac <varac@users.noreply.github.com>2015-11-19 14:14:57 +0100
committervarac <varac@users.noreply.github.com>2015-11-19 14:14:57 +0100
commit6c6a9c19160268687d20b2bf8098b4f1d2d45508 (patch)
tree5f946c6ca58521943c295a439f103a5b864b12f9 /tests/helpers
parentd146d1525adfe1f08be9df0f72aac389e2370de5 (diff)
parent9f12fd1b52ad79873a699b9d3faa29ff3e3c2677 (diff)
Merge pull request #88 from kalikaneko/bug-do-not-fail-if-not-requests
[bug] do not fail if no requests dep present
Diffstat (limited to 'tests/helpers')
-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: