mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[ADD] base_external_system: Implement interface/adapter (#993)
* [ADD] base_external_system: Implement interface/adapter for external systems * base_external_system: Fix OS model, add inherits, add validate * base_external_system: Usability and private key pass * base_external_system: Use contextmanager in adapter client * base_external_system: Move contextmanager to interface * base_external_system: Include contextmanager on adapter and system * base_external_system: Unify client * Use password widget for password field * Add tests & security * Fix lint * Add plaintext note
This commit is contained in:
45
base_external_system/tests/test_external_system_adapter.py
Normal file
45
base_external_system/tests/test_external_system_adapter.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 LasLabs Inc.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from .common import Common
|
||||
|
||||
|
||||
class TestExternalSystemAdapter(Common):
|
||||
|
||||
def setUp(self):
|
||||
super(TestExternalSystemAdapter, self).setUp()
|
||||
self.system = self.env.ref('base_external_system.external_system_os')
|
||||
self.record = self.env['external.system.adapter'].new({
|
||||
'system_id': self.system.id,
|
||||
})
|
||||
|
||||
def test_client_yields_client(self):
|
||||
"""It should yield the client."""
|
||||
with self._mock_method('external_get_client') as magic:
|
||||
with self.record.client() as client:
|
||||
self.assertEqual(client, magic())
|
||||
|
||||
def test_client_destroys_client(self):
|
||||
"""It should destroy the client after use."""
|
||||
with self._mock_method('external_destroy_client') as magic:
|
||||
with self.record.client() as client:
|
||||
self.assertFalse(magic.call_count)
|
||||
magic.assert_called_once_with(client)
|
||||
|
||||
def test_external_get_client_ensure_one(self):
|
||||
"""It should assert singletons."""
|
||||
with self.assertRaises(ValueError):
|
||||
self.env['external.system.adapter'].external_get_client()
|
||||
|
||||
def test_external_destroy_client_ensure_one(self):
|
||||
"""It should assert singletons."""
|
||||
with self.assertRaises(ValueError):
|
||||
self.env['external.system.adapter'].external_destroy_client(None)
|
||||
|
||||
def test_external_test_connection(self):
|
||||
"""It should raise a UserError."""
|
||||
with self.assertRaises(UserError):
|
||||
self.record.external_test_connection()
|
||||
Reference in New Issue
Block a user