From 4c88726dab1025bc525ff3ced17ee99cd9902a58 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sat, 19 Jul 2014 00:45:17 +0100 Subject: [PATCH 1/4] Unittest - Make taskd the first argument of Task() * The most common case is to bind a client to a server and not customizing the location of the task binary --- test/basetest/task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/basetest/task.py b/test/basetest/task.py index f6c263637..4338cbdf2 100644 --- a/test/basetest/task.py +++ b/test/basetest/task.py @@ -20,12 +20,12 @@ class Task(object): A taskw client should not be used after being destroyed. """ - def __init__(self, taskw="task", taskd=None): + def __init__(self, taskd=None, taskw="task"): """Initialize a Task warrior (client) that can interact with a taskd server. The task client runs in a temporary folder. - :arg taskw: Task binary to use as client (defaults: task in PATH) :arg taskd: Taskd instance for client-server configuration + :arg taskw: Task binary to use as client (defaults: task in PATH) """ self.taskw = taskw self.taskd = taskd From b58c6566afc4346d9564fdbca42f4cda2d8d43e8 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sat, 19 Jul 2014 02:06:21 +0100 Subject: [PATCH 2/4] Unittest - Make client credentials available as a dictionary --- test/basetest/task.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/basetest/task.py b/test/basetest/task.py index 4338cbdf2..6cf9a92e4 100644 --- a/test/basetest/task.py +++ b/test/basetest/task.py @@ -105,8 +105,15 @@ class Task(object): else: user, group, org, userkey = taskd_user - self.credentials = "/".join((org, user, userkey)) - self.config("taskd.credentials", self.credentials) + credentials = "/".join((org, user, userkey)) + self.config("taskd.credentials", credentials) + + self.credentials = { + "user": user, + "group": group, + "org": org, + "userkey": userkey, + } def config(self, var, value): """Run setup `var` as `value` in taskd config From 974045da7acb291a6823e2cda6350ec7eebe6889 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sat, 19 Jul 2014 02:28:52 +0100 Subject: [PATCH 3/4] Unittest - Helper code to easily parse tx.data --- test/basetest/taskd.py | 14 +++++++++++++- test/basetest/utils.py | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/test/basetest/taskd.py b/test/basetest/taskd.py index b2e414999..f9fe17185 100644 --- a/test/basetest/taskd.py +++ b/test/basetest/taskd.py @@ -8,7 +8,7 @@ import atexit from time import sleep from subprocess import Popen from .utils import (find_unused_port, release_port, port_used, run_cmd_wait, - which) + which, parse_datafile) from .exceptions import CommandError try: @@ -278,4 +278,16 @@ class Taskd(object): else: return True + def client_data(self, client): + """Return a python list with the content of tx.data matching the given + task client. tx.data will be parsed to string and JSON. + """ + file = os.path.join(self.datadir, + client.credentials["org"], + "users", + client.credentials["userkey"], + "tx.data") + + return parse_datafile(file) + # vim: ai sts=4 et sw=4 diff --git a/test/basetest/utils.py b/test/basetest/utils.py index 6483feee7..5936e100f 100644 --- a/test/basetest/utils.py +++ b/test/basetest/utils.py @@ -9,6 +9,10 @@ from subprocess import Popen, PIPE, STDOUT from threading import Thread from Queue import Queue, Empty from time import sleep +try: + import simplejson as json +except ImportError: + import json from .exceptions import CommandError USED_PORTS = set() @@ -247,4 +251,23 @@ except ImportError: return name return None +def parse_datafile(file): + """Parse .data files on the client and server treating files as JSON + """ + data = [] + with open(file) as fh: + for line in fh: + line = line.rstrip("\n") + + # Turn [] strings into {} to be treated properly as JSON hashes + if line.startswith('[') and line.endswith(']'): + line = '{' + line[1:-1] + '}' + + if line.startswith("{"): + data.append(json.loads(line)) + else: + data.append(line) + return data + + # vim: ai sts=4 et sw=4 From 4a305d5e51c4cccbc99b9ed41476a82966891461 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sat, 19 Jul 2014 02:55:49 +0100 Subject: [PATCH 4/4] Unittest - Fix path to user tx.data --- test/basetest/taskd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/basetest/taskd.py b/test/basetest/taskd.py index f9fe17185..3354c1f81 100644 --- a/test/basetest/taskd.py +++ b/test/basetest/taskd.py @@ -283,6 +283,7 @@ class Taskd(object): task client. tx.data will be parsed to string and JSON. """ file = os.path.join(self.datadir, + "orgs", client.credentials["org"], "users", client.credentials["userkey"],