예제 #1
0
 def test_generates_repr_string(self):
     # given
     att = Attachment(path='/path/to/file')
     att.id = 123
     #when
     r = repr(att)
     # then
     self.assertEqual('Attachment(\'/path/to/file\', id=123)', r)
예제 #2
0
 def test_lazy_overrides_non_lazy_attachments(self):
     # given
     attachment = Attachment('attachment')
     attachment2 = Attachment('attachment2')
     # when
     result = Task.from_dict({'attachments': [attachment]},
                             lazy={'attachments': [attachment2]})
     # then
     self.assertIsInstance(result, Task)
     self.assertEqual([attachment2], list(result.attachments))
예제 #3
0
 def test_generates_str_string(self):
     # given
     att = Attachment(path='/path/to/file')
     att.id = 123
     #when
     r = str(att)
     # then
     expected = 'Attachment(\'/path/to/file\', attachment id=123, id=[{}])'
     expected = expected.format(id(att))
     self.assertEqual(expected, r)
예제 #4
0
 def test_clearing_nullifies_task(self):
     # given
     task = Task('task')
     attachment = Attachment('attachment')
     attachment.task = task
     # precondition
     self.assertIs(task, attachment.task)
     # when
     attachment.clear_relationships()
     # then
     self.assertIsNone(attachment.task)
예제 #5
0
 def test_valid_task_gets_set(self):
     # given
     task = Task('task')
     # when
     result = Attachment.from_dict({'task': task})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertIs(task, result.task)
예제 #6
0
 def test_attachments_non_empty_yields_same(self):
     # given
     attachment = Attachment('attachment')
     # when
     result = Task.from_dict({'attachments': [attachment]})
     # then
     self.assertIsInstance(result, Task)
     self.assertEqual([attachment], list(result.attachments))
예제 #7
0
 def test_valid_task_id_is_ignored(self):
     # given
     task = Task('task')
     # when
     result = Attachment.from_dict({'task_id': task.id})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertIsNone(result.task_id)
예제 #8
0
 def test_lazy_overrides_non_lazy_task(self):
     # given
     task = Task('task')
     task2 = Task('task2')
     # when
     result = Attachment.from_dict({'task': task},
                                   lazy={'task': lambda: task2})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertIs(task2, result.task)
예제 #9
0
 def test_empty_yields_empty_dbattachment(self):
     # when
     result = Attachment.from_dict({})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertIsNone(result.id)
     self.assertIsNone(result.path)
     self.assertIsNone(result.description)
     self.assertIsNone(result.timestamp)
     self.assertIsNone(result.filename)
     self.assertIsNone(result.task)
예제 #10
0
파일: layer.py 프로젝트: izrik/tudor
 def create_attachment(self,
                       path,
                       description=None,
                       timestamp=None,
                       filename=None,
                       lazy=None):
     return Attachment(path=path,
                       description=description,
                       timestamp=timestamp,
                       filename=filename,
                       lazy=lazy)
예제 #11
0
 def test_lazy_overrides_all_non_lazy_properties(self):
     # given
     attachment = Attachment('attachment')
     note = Note('note')
     # when
     result = Task.from_dict({'attachments': [attachment]},
                             lazy={'notes': [note]})
     # then
     self.assertIsInstance(result, Task)
     self.assertEqual([], list(result.attachments))
     self.assertEqual([note], list(result.notes))
예제 #12
0
 def test_valid_timestamp_gets_set(self):
     # when
     result = Attachment.from_dict({'timestamp': datetime(2017, 1, 1)})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertEqual(datetime(2017, 1, 1), result.timestamp)
예제 #13
0
 def setUp(self):
     self.task = Task('parent')
     self.n1 = Attachment('n1')
     self.n2 = Attachment('n2')
예제 #14
0
 def test_task_none_is_ignored(self):
     # when
     result = Attachment.from_dict({'task': None})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertIsNone(result.task)
예제 #15
0
 def test_valid_filename_gets_set(self):
     # when
     result = Attachment.from_dict({'filename': 'abc'})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertEqual('abc', result.filename)
예제 #16
0
 def test_timestamp_none_becomes_none(self):
     # when
     result = Attachment.from_dict({'timestamp': None})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertIsNone(result.timestamp)
예제 #17
0
 def test_valid_description_gets_set(self):
     # when
     result = Attachment.from_dict({'description': 'abc'})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertEqual('abc', result.description)
예제 #18
0
 def test_description_none_is_ignored(self):
     # when
     result = Attachment.from_dict({'description': None})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertIsNone(result.description)
예제 #19
0
 def test_valid_id_gets_set(self):
     # when
     result = Attachment.from_dict({'id': 123})
     # then
     self.assertEqual(result.object_type, ObjectTypes.Attachment)
     self.assertEqual(123, result.id)