Пример #1
0
 def test_fields_none_exports_all(self):
     # given
     task = object()
     att = GenericAttachment('/path/to/file', 'desc', datetime(2018, 1, 1),
                             'file.ext', 123, task)
     # precondition
     self.assertEqual(123, att.id)
     self.assertEqual(datetime(2018, 1, 1),att.timestamp)
     self.assertEqual('/path/to/file',att.path)
     self.assertEqual('file.ext', att.filename)
     self.assertEqual('desc', att.description)
     self.assertIs(task, att.task)
     # when
     d = att.to_dict(fields=None)
     # then
     self.assertEqual(6, len(d))
     self.assertIn('id', d)
     self.assertEqual(123, d['id'])
     self.assertIn('timestamp', d)
     self.assertEqual('2018-01-01 00:00:00', d['timestamp'])
     self.assertIn('path', d)
     self.assertEqual('/path/to/file', d['path'])
     self.assertIn('filename', d)
     self.assertEqual('file.ext', d['filename'])
     self.assertIn('description', d)
     self.assertEqual('desc', d['description'])
     self.assertIn('task', d)
     self.assertIs(task, d['task'])
Пример #2
0
 def test_all_fields_exports_all(self):
     # given
     task = object()
     att = GenericAttachment('/path/to/file', 'desc', datetime(2018, 1, 1),
                             'file.ext', 123, task)
     # precondition
     self.assertEqual(123, att.id)
     self.assertEqual(datetime(2018, 1, 1), att.timestamp)
     self.assertEqual('/path/to/file',att.path)
     self.assertEqual('file.ext', att.filename)
     self.assertEqual('desc', att.description)
     self.assertIs(task, att.task)
     # when
     d = att.to_dict(
         fields=[att.FIELD_ID, att.FIELD_PATH, att.FIELD_DESCRIPTION,
                 att.FIELD_TIMESTAMP, att.FIELD_FILENAME, att.FIELD_TASK])
     # then
     self.assertEqual(6, len(d))
     self.assertIn('id', d)
     self.assertEqual(123, d['id'])
     self.assertIn('timestamp', d)
     self.assertEqual('2018-01-01 00:00:00', d['timestamp'])
     self.assertIn('path', d)
     self.assertEqual('/path/to/file', d['path'])
     self.assertIn('filename', d)
     self.assertEqual('file.ext', d['filename'])
     self.assertIn('description', d)
     self.assertEqual('desc', d['description'])
     self.assertIn('task', d)
     self.assertIs(task, d['task'])
Пример #3
0
 def test_multiple_fields_exports_those_indicated(self):
     # given
     task = object()
     att = GenericAttachment('/path/to/file', 'desc', datetime(2018, 1, 1),
                             'file.ext', 123, task)
     # precondition
     self.assertEqual(123, att.id)
     self.assertEqual(datetime(2018, 1, 1), att.timestamp)
     self.assertEqual('/path/to/file',att.path)
     self.assertEqual('file.ext', att.filename)
     self.assertEqual('desc', att.description)
     self.assertIs(task, att.task)
     # when
     d = att.to_dict(
         fields=[att.FIELD_ID, att.FIELD_TIMESTAMP, att.FIELD_PATH])
     # then
     self.assertEqual(3, len(d))
     self.assertIn('id', d)
     self.assertEqual(123, d['id'])
     self.assertIn('timestamp', d)
     self.assertEqual('2018-01-01 00:00:00', d['timestamp'])
     self.assertIn('path', d)
     self.assertEqual('/path/to/file', d['path'])
     self.assertNotIn('filename', d)
     self.assertNotIn('description', d)
     self.assertNotIn('task', d)
Пример #4
0
 def test_filename_in_dict_changes_filename(self):
     # given
     att = GenericAttachment()
     # precondition
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
     # when
     att.update_from_dict({'filename': 'file.ext'})
     # then
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertEqual('file.ext', att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
Пример #5
0
 def test_empty_dict_no_changes(self):
     # given
     att = GenericAttachment()
     # precondition
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
     # when
     att.update_from_dict({})
     # then
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
Пример #6
0
 def test_path_in_dict_changes_path(self):
     # given
     att = GenericAttachment()
     # precondition
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
     # when
     att.update_from_dict({'path': '/path/to/file'})
     # then
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertEqual('/path/to/file', att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
Пример #7
0
 def test_timestamp_in_dict_changes_timestamp(self):
     # given
     att = GenericAttachment()
     # precondition
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
     # when
     att.update_from_dict({'timestamp': datetime(2018, 1, 1)})
     # then
     self.assertIsNone(att.id)
     self.assertEqual(datetime(2018, 1, 1), att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
Пример #8
0
 def test_other_names_silently_ignored(self):
     # given
     att = GenericAttachment()
     # precondition
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
     # when
     att.update_from_dict({'something': 'other thing'})
     # then
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
Пример #9
0
 def test_task_in_dict_changes_task(self):
     # given
     att = GenericAttachment()
     # precondition
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIsNone(att.task)
     task = object()
     # when
     att.update_from_dict({'task': task})
     # then
     self.assertIsNone(att.id)
     self.assertIsNone(att.timestamp)
     self.assertIsNone(att.path)
     self.assertIsNone(att.filename)
     self.assertIsNone(att.description)
     self.assertIs(task, att.task)
Пример #10
0
 def test_fields_id_exports_only_id(self):
     # given
     task = object()
     att = GenericAttachment('/path/to/file', 'desc', datetime(2018, 1, 1),
                             'file.ext', 123, task)
     # precondition
     self.assertEqual(123, att.id)
     self.assertEqual(datetime(2018, 1, 1),att.timestamp)
     self.assertEqual('/path/to/file',att.path)
     self.assertEqual('file.ext', att.filename)
     self.assertEqual('desc', att.description)
     self.assertIs(task, att.task)
     # when
     d = att.to_dict(fields=[att.FIELD_ID])
     # then
     self.assertEqual(1, len(d))
     self.assertIn('id', d)
     self.assertNotIn('timestamp', d)
     self.assertNotIn('path', d)
     self.assertNotIn('filename', d)
     self.assertNotIn('description', d)
     self.assertNotIn('task', d)