Skip to content

Commit

Permalink
Update tests, make an important fix in _load_task for handling single…
Browse files Browse the repository at this point in the history
… vs multiple results
  • Loading branch information
kostajh committed Jun 21, 2013
1 parent cf6f3d8 commit 98fe475
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions taskw/test/test_datas.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_completing_task_by_id_unspecified(self):
eq_(tasks['completed'][0]['status'], 'completed')

def test_completing_task_with_date(self):
# TODO: TaskWarriorExperimental doesn't support this, so should skip.
self.tw.task_add("foobar")
uuid = self.tw.load_tasks()['pending'][0]['uuid']
self.tw.task_done(uuid=uuid, end="1234567890")
Expand Down
20 changes: 14 additions & 6 deletions taskw/warrior.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ def get_task(self, **kw):

def _load_task(self, **kw):

# TODO: Change this, because we can actually use multiple args.
if len(kw) != 1:
raise KeyError("Only 1 ID keyword argument may be specified")

key = kw.keys()[0]
if key is not 'id' and key is not 'uuid' and key is not 'description':
search = key + ":" + str(kw[key])
Expand All @@ -418,7 +422,12 @@ def _load_task(self, **kw):
if task:
try:
task_data = json.loads(task)
return task_data[0][six.u('id')], task_data[0]
if type(task_data) is dict:
# Only one item was returned from search
return task_data[six.u('id')], task_data
else:
# Multiple items returned from search, return just the 1st
return task_data[0][six.u('id')], task_data[0]
pass
except:
pass
Expand Down Expand Up @@ -447,10 +456,7 @@ def task_add(self, description, tags=None, **kw):

# Check if 'uuid' is in the task we just added.
if not 'uuid' in added_task:
print('No uuid! uh oh.')
print(id)
pprint.pprint(added_task)
return
raise ValueError('No uuid! uh oh.')
if annotations and 'uuid' in added_task:
for annotation in annotations:
self.task_annotate(added_task, annotation)
Expand All @@ -467,6 +473,8 @@ def task_annotate(self, task, annotation):
return annotated_task

def task_done(self, **kw):
if not kw:
raise ValueError('No key was passed.')
id, task = self.get_task(**kw)

subprocess.Popen([
Expand All @@ -479,7 +487,7 @@ def task_done(self, **kw):
def task_update(self, task):

if 'uuid' not in task:
return None, dict()
raise ValueError('Task must have a UUID.')

id, _task = self.get_task(uuid=task['uuid'])

Expand Down

0 comments on commit 98fe475

Please sign in to comment.