Skip to content

Commit

Permalink
refactored cli local and remote and supplied better unittests for them
Browse files Browse the repository at this point in the history
  • Loading branch information
niknow committed Nov 22, 2015
1 parent 782595a commit a8ff054
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tarenalib/arena.py
Expand Up @@ -223,11 +223,11 @@ def __repr__(self):
def __str__(self):
return str(self.__repr__())

def get_local_tasks(self):
return self.tw_local.tasks(['Arena:' + self.name])
def get_local_tasks(self, pattern=[]):
return self.tw_local.tasks(['Arena:' + self.name] + pattern)

def get_remote_tasks(self):
return self.tw_remote.tasks(['Arena:' + self.name])
def get_remote_tasks(self, pattern=[]):
return self.tw_remote.tasks(['Arena:' + self.name] + pattern)


class TaskEmperor(object):
Expand Down
17 changes: 4 additions & 13 deletions tarenalib/cli.py
Expand Up @@ -136,26 +136,17 @@ def remove(found_arena, pattern):
@click.argument('pattern', nargs=-1)
def local(found_arena, pattern):
if found_arena:
list_tasks(found_arena.arena, pattern, found_arena.arena.local_data)
for task in found_arena.arena.get_local_tasks(list(pattern)):
iom.send_message(task.tw_task['description'])


@cli.command(help='Lists all remote tasks matching PATTERN from ARENA.')
@click.argument('found_arena', callback=find_arena)
@click.argument('pattern', nargs=-1)
def remote(found_arena, pattern):
if found_arena:
list_tasks(found_arena.arena, pattern, found_arena.arena.remote_data)


def list_tasks(arena, pattern, data_location):
p = subprocess.Popen(
['task',
'rc.data.location:' + data_location,
'Arena:' + arena.name,
pattern],
stderr=subprocess.PIPE
)
p.communicate()
for task in found_arena.arena.get_remote_tasks(list(pattern)):
iom.send_message(task.tw_task['description'])


@cli.command(help='Synchronizes ARENA')
Expand Down
33 changes: 33 additions & 0 deletions tarenalib/tests/test_cli.py
Expand Up @@ -64,6 +64,8 @@ def test_delete(self):
result_check = self.runner.invoke(cli, cmd + ['arenas'])
assert result_delete.exit_code == 0
assert 'No arenas found' in result_check.output
result_not_found = self.runner.invoke(cli, cmd + ['delete', 'foo'])
assert 'not found' in result_not_found.output

def test_arenas(self):
with self.runner.isolated_filesystem():
Expand Down Expand Up @@ -103,6 +105,37 @@ def test_remove(self):
tw.config.update({uda[0]: uda[1]})
assert len(tw.tasks.filter('Arena:foo')) == 0

def test_local(self):
with self.runner.isolated_filesystem():
dloc = os.getcwd() + '/local'
tw = TaskWarrior(dloc)
t = Task(tw)
description = 'do dishes'
t['description'] = description
t.save()
self.runner.invoke(cli, cmd_dummy_arena)
self.runner.invoke(cli, cmd + ['add', 'foo', description])
for uda in uda_config_list:
tw.config.update({uda[0]: uda[1]})
result = self.runner.invoke(cli, cmd + ['local', 'foo', 'dishes'])
assert 'dishes' in result.output

def test_remote(self):
with self.runner.isolated_filesystem():
self.runner.invoke(cli, cmd_dummy_arena)
dloc = os.getcwd() + '/remote'
tw = TaskWarrior(dloc)
for uda in uda_config_list:
tw.config.update({uda[0]: uda[1]})
t = Task(tw)
description = 'do dishes'
t['description'] = description
t['Arena'] = 'foo'
t['ArenaTaskID'] = '1'
t.save()
result = self.runner.invoke(cli, cmd + ['remote', 'foo', 'dishes'])
assert 'dishes' in result.output

def test_sync(self):
with self.runner.isolated_filesystem():
cwd = os.getcwd()
Expand Down

0 comments on commit a8ff054

Please sign in to comment.