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
1.6 KiB

8 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Angel Moya (http://angelmoya.es)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. import openerp
  6. from openerp import api
  7. class TestAttachmentBaseSynchronize(TransactionCase):
  8. def setUp(self):
  9. super(TestAttachmentBaseSynchronize, self).setUp()
  10. self.registry.enter_test_mode()
  11. self.env = api.Environment(self.registry.test_cr, self.env.uid,
  12. self.env.context)
  13. self.attachment = self.env.ref(
  14. 'attachment_base_synchronize.attachment_metadata')
  15. self.ir_attachment_metadata = self.env['ir.attachment.metadata']
  16. def tearDown(self):
  17. self.registry.leave_test_mode()
  18. super(TestAttachmentBaseSynchronize, self).tearDown()
  19. def test_attachment_metadata(self):
  20. """Test run_attachment_metadata_scheduler to ensure set state to done
  21. """
  22. self.assertEqual(
  23. self.attachment.state,
  24. 'pending'
  25. )
  26. self.ir_attachment_metadata.run_attachment_metadata_scheduler()
  27. self.env.invalidate_all()
  28. with openerp.registry(self.env.cr.dbname).cursor() as new_cr:
  29. new_env = api.Environment(
  30. new_cr, self.env.uid, self.env.context)
  31. attach = self.attachment.with_env(new_env)
  32. self.assertEqual(
  33. attach.state,
  34. 'done'
  35. )
  36. def test_set_done(self):
  37. """Test set_done manually
  38. """
  39. self.attachment.set_done()
  40. self.assertEqual(
  41. self.attachment.state,
  42. 'done'
  43. )