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.

53 lines
1.7 KiB

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