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.

63 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Agile Business Group <http://www.agilebg.com>
  3. # © 2015 Alessio Gerace <alesiso.gerace@agilebg.com>
  4. # © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
  5. # Copyright 2016 LasLabs Inc.
  6. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  7. import os
  8. from datetime import datetime
  9. from openerp.tests import common
  10. from openerp import exceptions, tools
  11. class TestsAutoBackup(common.TransactionCase):
  12. def setUp(self):
  13. super(TestsAutoBackup, self).setUp()
  14. def new_record(self, method='sftp'):
  15. vals = {
  16. 'name': u'Têst backup',
  17. 'method': method,
  18. }
  19. if method == 'sftp':
  20. vals.update({
  21. 'sftp_host': 'test_host',
  22. 'sftp_port': '222',
  23. 'sftp_user': 'tuser',
  24. })
  25. self.vals = vals
  26. self.env["db.backup"].create(vals)
  27. def test_local(self):
  28. """A local database is backed up."""
  29. rec_id = self.new_record('local')
  30. filename = rec_id.filename(datetime.now())
  31. rec_id.action_backup()
  32. generated_backup = [f for f in os.listdir(rec_id.folder)
  33. if f >= filename]
  34. self.assertEqual(1, len(generated_backup))
  35. def test_compute_name_sftp(self):
  36. """ It should create proper SFTP URI """
  37. rec_id = self.new_record()
  38. self.assertEqual(
  39. 'sftp://%(user)@%(host):%(port)%(folder)' % {
  40. 'user': self.vals['sftp_user'],
  41. 'host': self.vals['sftp_host'],
  42. 'port': self.vals['sftp_port'],
  43. 'folder': self.vals['folder'],
  44. },
  45. rec_id.name,
  46. )
  47. def test_check_folder(self):
  48. """ It should not allow recursive backups """
  49. rec_id = self.new_record()
  50. with self.assertRaises(exceptions.ValidationError):
  51. rec_id.write({
  52. 'folder': '%s/another/path' % tools.config.filestore(
  53. self.env.cr.dbname
  54. ),
  55. })