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.

45 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  4. from odoo.exceptions import UserError
  5. from .common import Common
  6. class TestExternalSystemAdapter(Common):
  7. def setUp(self):
  8. super(TestExternalSystemAdapter, self).setUp()
  9. self.system = self.env.ref('base_external_system.external_system_os')
  10. self.record = self.env['external.system.adapter'].new({
  11. 'system_id': self.system.id,
  12. })
  13. def test_client_yields_client(self):
  14. """It should yield the client."""
  15. with self._mock_method('external_get_client') as magic:
  16. with self.record.client() as client:
  17. self.assertEqual(client, magic())
  18. def test_client_destroys_client(self):
  19. """It should destroy the client after use."""
  20. with self._mock_method('external_destroy_client') as magic:
  21. with self.record.client() as client:
  22. self.assertFalse(magic.call_count)
  23. magic.assert_called_once_with(client)
  24. def test_external_get_client_ensure_one(self):
  25. """It should assert singletons."""
  26. with self.assertRaises(ValueError):
  27. self.env['external.system.adapter'].external_get_client()
  28. def test_external_destroy_client_ensure_one(self):
  29. """It should assert singletons."""
  30. with self.assertRaises(ValueError):
  31. self.env['external.system.adapter'].external_destroy_client(None)
  32. def test_external_test_connection(self):
  33. """It should raise a UserError."""
  34. with self.assertRaises(UserError):
  35. self.record.external_test_connection()