def test_composition(self): arbitrary_serialized_data = { 'depends': ','.join([ str(uuid.uuid4()), str(uuid.uuid4()), ]), 'description': '&open;Something important', 'due': (datetime.datetime.now().replace(tzinfo=pytz.UTC) + datetime.timedelta(hours=1)).strftime('%Y%m%dT%H%M%SZ'), 'tags': ['one', 'two', 'three'], 'urgency': 10, 'uuid': str(uuid.uuid4()), } task = Task(arbitrary_serialized_data) expected_result = arbitrary_serialized_data after_composition = Task( Task(Task(arbitrary_serialized_data).serialized()).serialized() ).serialized() self.assertEqual(after_composition, expected_result)
def setUp(self): self.task = Task({ 'uuid': str(uuid.uuid4()), 'description': 'Something important', 'due': (datetime.datetime.now().replace(tzinfo=pytz.UTC) + datetime.timedelta(hours=1)).strftime('%Y%m%dT%H%M%SZ'), 'tags': ['one', 'two', 'three'], })
def from_input(self, hook_input: IO[str] = sys.stdin) -> Task: """ Load task from input :return: hook_task """ udas = self.tw.config.get_udas() if self.event == 'on_modify': task = Task.from_input(hook_input, modify=True, udas=udas) return task task = Task.from_input(hook_input, modify=False, udas=udas) return task
def test_deserialize(self): arbitrary_depends_uuids = [uuid.uuid4(), uuid.uuid4()] arbitrary_description = '[one' arbitrary_due_date = ( datetime.datetime.now().replace(tzinfo=pytz.UTC) + datetime.timedelta(hours=1)) arbitrary_tags = [ 'one', 'two', ] arbitrary_urgency = 10 arbitrary_uuid = uuid.uuid4() serialized = { 'depends': ','.join([str(u) for u in arbitrary_depends_uuids]), 'description': arbitrary_description.replace('[', '&open;'), 'due': arbitrary_due_date.strftime('%Y%m%dT%H%M%SZ'), 'tags': arbitrary_tags, 'urgency': arbitrary_urgency, 'uuid': str(arbitrary_uuid) } task = Task(serialized) self.assertEqual(task['depends'], arbitrary_depends_uuids) self.assertEqual(task['description'], arbitrary_description) # Loss of milliseconds when converting to string self.assertAlmostEqual(task['due'], arbitrary_due_date, delta=datetime.timedelta(seconds=1)) self.assertEqual(task['tags'], arbitrary_tags) self.assertEqual(task['urgency'], arbitrary_urgency) self.assertEqual(task['uuid'], arbitrary_uuid)
def setUp(self): self.task = Task({ 'uuid': str(uuid.uuid4()), 'description': 'Something important', 'due': ( datetime.datetime.now().replace(tzinfo=pytz.UTC) + datetime.timedelta(hours=1) ).strftime('%Y%m%dT%H%M%SZ'), 'tags': ['one', 'two', 'three'], })
def test_serialize(self): arbitrary_serialized_data = { 'depends': ','.join([ str(uuid.uuid4()), str(uuid.uuid4()), ]), 'description': '&open;Something important', 'due': ( datetime.datetime.now().replace(tzinfo=pytz.UTC) + datetime.timedelta(hours=1) ).strftime('%Y%m%dT%H%M%SZ'), 'tags': ['one', 'two', 'three'], 'urgency': 10, 'uuid': str(uuid.uuid4()), } task = Task(arbitrary_serialized_data) expected_result = arbitrary_serialized_data actual_result = task.serialized() self.assertEqual(actual_result, expected_result)
def test_example_hook(): test_task = Task({ "status": "pending", "description": "Fix tw-98765", "tags": ["in"], "modified": "20181015T054805Z", "entry": "20181015T054805Z", "uuid": "cee8cefa-0b9d-432c-a7da-cd68f50466bf" }) example_hook.main(test_task) assert test_task[ 'description'] == "Fix https://github.com/GothenburgBitFactory/taskwarrior/issues/tw-98765"
def test_inbox_tag_hook_add(): test_task = Task({ "description": "test task 1", "status": "pending", "tags": ["tag1", "tag2"], "modified": "20181015T054805Z", "entry": "20181015T054805Z", "uuid": "cee8cefa-0b9d-432c-a7da-cd68f50466bf" }) inbox_tag_hook.main(test_task) assert test_task['description'] == "test task 1" assert test_task['tags'] == ["tag1", "tag2", "in"]
def _stub_task(self, description, tags=None, **kw): """ Given a description, stub out a task dict. """ # If whitespace is not removed here, TW will do it when we pass the # task to it. task = {"description": description.strip()} # Allow passing "tags" in as part of kw. if "tags" in kw and tags is None: task["tags"] = tags del (kw["tags"]) if tags is not None: task["tags"] = tags task.update(kw) if self._marshal: return Task.from_stub(task, udas=self.config.get_udas()) return task
def _stub_task(self, description, tags=None, **kw): """ Given a description, stub out a task dict. """ # If whitespace is not removed here, TW will do it when we pass the # task to it. task = {"description": description.strip()} # Allow passing "tags" in as part of kw. if 'tags' in kw and tags is None: task['tags'] = tags del (kw['tags']) if tags is not None: task['tags'] = tags task.update(kw) if self._marshal: return Task.from_stub(task, udas=self.config.get_udas()) return task
def _get_task_object(self, obj): if self._marshal: return Task(obj, udas=self.config.get_udas()) return obj
def test_append_when_absent_but_with_tags(self): self.task = Task({'uuid': str(uuid.uuid4()), 'description': 'Test'}) self.task['tags'].append('awesome') self.assertEqual(self.task['tags'], ['awesome'])
class TestTaskDirtyability(TestCase): def setUp(self): self.task = Task({ 'uuid': str(uuid.uuid4()), 'description': 'Something important', 'due': (datetime.datetime.now().replace(tzinfo=pytz.UTC) + datetime.timedelta(hours=1)).strftime('%Y%m%dT%H%M%SZ'), 'tags': ['one', 'two', 'three'], }) def test_append_when_absent(self): self.task['annotations'].append('awesome') self.assertEqual(self.task['annotations'], ['awesome']) def test_append_when_absent_but_with_tags(self): self.task = Task({'uuid': str(uuid.uuid4()), 'description': 'Test'}) self.task['tags'].append('awesome') self.assertEqual(self.task['tags'], ['awesome']) def test_marks_date_changed(self): original_due_date = self.task['due'] new_due_date = datetime.datetime.now().replace(tzinfo=pytz.UTC) self.task['due'] = new_due_date expected_changes = {'due': (original_due_date, new_due_date)} actual_changes = self.task.get_changes() self.assertEqual(list(six.iterkeys(actual_changes)), ['due']) # Use assertAlmostEqual to allow for millisecond loss when # converting to string in setUp self.assertAlmostEqual(expected_changes['due'][0], actual_changes['due'][0], delta=datetime.timedelta(seconds=1)) self.assertAlmostEqual(expected_changes['due'][1], actual_changes['due'][1], delta=datetime.timedelta(seconds=1)) def test_marks_tags_changed(self): original_tags = copy.deepcopy(self.task['tags']) new_tag = 'alpha' self.task['tags'].append(new_tag) expected_tags = copy.deepcopy(original_tags) expected_tags.append(new_tag) expected_changes = {'tags': [original_tags, expected_tags]} actual_changes = self.task.get_changes() self.assertEqual(actual_changes, expected_changes) def test_does_not_mark_unchanged(self): self.task['description'] = self.task['description'] expected_changes = {} actual_changes = self.task.get_changes() self.assertEqual(actual_changes, expected_changes) def test_does_not_allow_changing_id(self): with self.assertRaises(ValueError): self.task['id'] = 10
def test_append_when_absent_but_with_tags(self): self.task = Task({'uuid': str(uuid.uuid4()), 'description': 'Test'}) self.task['tags'] = [] self.task['tags'].append('awesome') self.assertEqual(self.task['tags'], ['awesome'])
class TestTaskDirtyability(TestCase): def setUp(self): self.task = Task({ 'uuid': str(uuid.uuid4()), 'description': 'Something important', 'due': ( datetime.datetime.now().replace(tzinfo=pytz.UTC) + datetime.timedelta(hours=1) ).strftime('%Y%m%dT%H%M%SZ'), 'tags': ['one', 'two', 'three'], }) def test_append_when_absent(self): self.task['annotations'] = [] self.task['annotations'].append('awesome') self.assertEqual(self.task['annotations'], ['awesome']) def test_append_when_absent_but_with_tags(self): self.task = Task({'uuid': str(uuid.uuid4()), 'description': 'Test'}) self.task['tags'] = [] self.task['tags'].append('awesome') self.assertEqual(self.task['tags'], ['awesome']) def test_marks_date_changed(self): original_due_date = self.task['due'] new_due_date = datetime.datetime.now().replace(tzinfo=pytz.UTC) self.task['due'] = new_due_date expected_changes = {'due': (original_due_date, new_due_date)} actual_changes = self.task.get_changes() self.assertEqual(list(six.iterkeys(actual_changes)), ['due']) # Use assertAlmostEqual to allow for millisecond loss when # converting to string in setUp self.assertAlmostEqual( expected_changes['due'][0], actual_changes['due'][0], delta=datetime.timedelta(seconds=1) ) self.assertAlmostEqual( expected_changes['due'][1], actual_changes['due'][1], delta=datetime.timedelta(seconds=1) ) def test_marks_tags_changed(self): original_tags = copy.deepcopy(self.task['tags']) new_tag = 'alpha' self.task['tags'].append(new_tag) expected_tags = copy.deepcopy(original_tags) expected_tags.append(new_tag) expected_changes = {'tags': [original_tags, expected_tags]} actual_changes = self.task.get_changes() self.assertEqual(actual_changes, expected_changes) def test_does_not_mark_unchanged(self): self.task['description'] = self.task['description'] expected_changes = {} actual_changes = self.task.get_changes() self.assertEqual(actual_changes, expected_changes) def test_does_not_allow_changing_id(self): with self.assertRaises(ValueError): self.task['id'] = 10