You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.0 KiB

  1. # coding: utf-8
  2. # @ 2015 Valentin CHEMIERE @ Akretion
  3. # ©2016 @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. import logging
  6. from base64 import b64decode
  7. from .common import TestConnection, ContextualStringIO
  8. from .mock_server import server_mock_filestore
  9. _logger = logging.getLogger(__name__)
  10. class TestfilestoreConnection(TestConnection):
  11. def setUp(self):
  12. super(TestfilestoreConnection, self).setUp()
  13. self.test_file_filestore = ContextualStringIO()
  14. self.test_file_filestore.write('import filestore')
  15. self.test_file_filestore.seek(0)
  16. def test_00_filestore_import(self):
  17. self.task = self.env.ref(
  18. 'external_file_location.filestore_import_task')
  19. with server_mock_filestore(
  20. {'open': self.test_file_filestore,
  21. 'listdir': ['test-import-filestore.txt']}):
  22. self.task.run_import()
  23. search_file = self.env['ir.attachment.metadata'].search(
  24. [('name', '=', 'test-import-filestore.txt')])
  25. self.assertEqual(len(search_file), 1)
  26. self.assertEqual(b64decode(search_file[0].datas), 'import filestore')
  27. def test_01_filestore_export(self):
  28. self.task = self.env.ref(
  29. 'external_file_location.filestore_export_task')
  30. self.filestore_attachment = self.env.ref(
  31. 'external_file_location.ir_attachment_export_file_filestore')
  32. with server_mock_filestore(
  33. {'setcontents': ''}) as Fakefilestore:
  34. self.task.run_export()
  35. if Fakefilestore:
  36. self.assertEqual('setcontents', Fakefilestore[-1]['method'])
  37. self.assertEqual('done', self.filestore_attachment.state)
  38. self.assertEqual(
  39. '/home/user/test/filestore_test_export.txt',
  40. Fakefilestore[-1]['args'][0])
  41. self.assertEqual(
  42. 'test filestore file export',
  43. Fakefilestore[-1]['kwargs']['data'])