Example #1
0
 def test_generates_repr_string(self):
     # given
     note = Note(content='content')
     note.id = 123
     #when
     r = repr(note)
     # then
     self.assertEqual('Note(\'content\', id=123)', r)
Example #2
0
 def test_lazy_overrides_non_lazy_notes(self):
     # given
     note = Note('note')
     note2 = Note('note2')
     # when
     result = Task.from_dict({'notes': [note]}, lazy={'notes': [note2]})
     # then
     self.assertIsInstance(result, Task)
     self.assertEqual([note2], list(result.notes))
Example #3
0
 def test_generates_str_string(self):
     # given
     note = Note(content='content')
     note.id = 123
     #when
     r = str(note)
     # then
     fmt = 'Note(\'content\', note id=123, id=[{}])'
     expected = fmt.format(id(note))
     self.assertEqual(expected, r)
Example #4
0
 def test_clearing_nullifies_task(self):
     # given
     task = Task('task')
     note = Note('note')
     note.task = task
     # precondition
     self.assertIs(task, note.task)
     # when
     note.clear_relationships()
     # then
     self.assertIsNone(note.task)
Example #5
0
 def test_notes_non_empty_yields_same(self):
     # given
     note = Note('note')
     # when
     result = Task.from_dict({'notes': [note]})
     # then
     self.assertIsInstance(result, Task)
     self.assertEqual([note], list(result.notes))
Example #6
0
 def test_valid_task_gets_set(self):
     # given
     task = Task('task')
     # when
     result = Note.from_dict({'task': task})
     # then
     self.assertIsInstance(result, Note)
     self.assertIs(task, result.task)
Example #7
0
 def test_valid_task_id_is_ignored(self):
     # given
     task = Task('task')
     # when
     result = Note.from_dict({'task_id': task.id})
     # then
     self.assertIsInstance(result, Note)
     self.assertIsNone(result.task_id)
Example #8
0
 def test_empty_yields_empty_dbnote(self):
     # when
     result = Note.from_dict({})
     # then
     self.assertIsInstance(result, Note)
     self.assertIsNone(result.id)
     self.assertIsNone(result.content)
     self.assertIsNone(result.timestamp)
     self.assertIsNone(result.task)
Example #9
0
 def test_lazy_overrides_non_lazy_task(self):
     # given
     task = Task('task')
     task2 = Task('task2')
     # when
     result = Note.from_dict({'task': task}, lazy={'task': lambda: task2})
     # then
     self.assertIsInstance(result, Note)
     self.assertIs(task2, result.task)
Example #10
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))
Example #11
0
 def test_timestamp_none_becomes_none(self):
     # when
     result = Note.from_dict({'timestamp': None})
     # then
     self.assertIsInstance(result, Note)
     self.assertIsNone(result.timestamp)
Example #12
0
 def test_task_id_none_is_ignored(self):
     # when
     result = Note.from_dict({'task_id': None})
     # then
     self.assertIsInstance(result, Note)
     self.assertIsNone(result.task_id)
Example #13
0
 def test_valid_timestamp_gets_set(self):
     # when
     result = Note.from_dict({'timestamp': datetime(2017, 1, 1)})
     # then
     self.assertIsInstance(result, Note)
     self.assertEqual(datetime(2017, 1, 1), result.timestamp)
Example #14
0
 def setUp(self):
     self.task = Task('parent')
     self.n1 = Note('n1')
     self.n2 = Note('n2')
Example #15
0
 def test_valid_content_gets_set(self):
     # when
     result = Note.from_dict({'content': 'abc'})
     # then
     self.assertIsInstance(result, Note)
     self.assertEqual('abc', result.content)
Example #16
0
 def test_content_none_is_ignored(self):
     # when
     result = Note.from_dict({'content': None})
     # then
     self.assertIsInstance(result, Note)
     self.assertIsNone(result.content)
Example #17
0
 def test_valid_id_gets_set(self):
     # when
     result = Note.from_dict({'id': 123})
     # then
     self.assertIsInstance(result, Note)
     self.assertEqual(123, result.id)
Example #18
0
File: layer.py Project: izrik/tudor
 def create_note(self, content, timestamp=None, lazy=None):
     return Note(content=content, timestamp=timestamp, lazy=lazy)