| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
"""Tests for the attribute container manager.""" |
| 4 |
|
| 5 |
import unittest |
| 6 |
|
| 7 |
from acstore.containers import manager |
| 8 |
|
| 9 |
from tests import test_lib as shared_test_lib |
| 10 |
|
| 11 |
|
| 12 |
class AttributeContainersManagerTest(shared_test_lib.BaseTestCase): |
| 13 |
"""Tests for the attribute container manager.""" |
| 14 |
|
| 15 |
# pylint: disable=protected-access |
| 16 |
|
| 17 |
_TEST_MANAGER = manager.AttributeContainersManager |
| 18 |
|
| 19 |
def testCreateAttributeContainer(self): |
| 20 |
"""Tests the CreateAttributeContainer function.""" |
| 21 |
self._TEST_MANAGER.RegisterAttributeContainer( |
| 22 |
shared_test_lib.TestAttributeContainer) |
| 23 |
|
| 24 |
try: |
| 25 |
attribute_container = self._TEST_MANAGER.CreateAttributeContainer( |
| 26 |
'test_container') |
| 27 |
self.assertIsNotNone(attribute_container) |
| 28 |
|
| 29 |
with self.assertRaises(ValueError): |
| 30 |
self._TEST_MANAGER.CreateAttributeContainer('bogus') |
| 31 |
|
| 32 |
finally: |
| 33 |
self._TEST_MANAGER.DeregisterAttributeContainer( |
| 34 |
shared_test_lib.TestAttributeContainer) |
| 35 |
|
| 36 |
def testGetContainerTypes(self): |
| 37 |
"""Tests the GetContainerTypes function.""" |
| 38 |
self._TEST_MANAGER.RegisterAttributeContainer( |
| 39 |
shared_test_lib.TestAttributeContainer) |
| 40 |
|
| 41 |
try: |
| 42 |
container_types = self._TEST_MANAGER.GetContainerTypes() |
| 43 |
self.assertIn('test_container', container_types) |
| 44 |
|
| 45 |
finally: |
| 46 |
self._TEST_MANAGER.DeregisterAttributeContainer( |
| 47 |
shared_test_lib.TestAttributeContainer) |
| 48 |
|
| 49 |
def testGetSchema(self): |
| 50 |
"""Tests the GetSchema function.""" |
| 51 |
self._TEST_MANAGER.RegisterAttributeContainer( |
| 52 |
shared_test_lib.TestAttributeContainer) |
| 53 |
|
| 54 |
try: |
| 55 |
schema = self._TEST_MANAGER.GetSchema('test_container') |
| 56 |
self.assertIsNotNone(schema) |
| 57 |
self.assertEqual(schema, shared_test_lib.TestAttributeContainer.SCHEMA) |
| 58 |
|
| 59 |
with self.assertRaises(ValueError): |
| 60 |
self._TEST_MANAGER.GetSchema('bogus') |
| 61 |
|
| 62 |
finally: |
| 63 |
self._TEST_MANAGER.DeregisterAttributeContainer( |
| 64 |
shared_test_lib.TestAttributeContainer) |
| 65 |
|
| 66 |
def testAttributeContainerRegistration(self): |
| 67 |
"""Tests the Register and DeregisterAttributeContainer functions.""" |
| 68 |
number_of_classes = len(self._TEST_MANAGER._attribute_container_classes) |
| 69 |
|
| 70 |
self._TEST_MANAGER.RegisterAttributeContainer( |
| 71 |
shared_test_lib.TestAttributeContainer) |
| 72 |
|
| 73 |
try: |
| 74 |
self.assertEqual( |
| 75 |
len(self._TEST_MANAGER._attribute_container_classes), |
| 76 |
number_of_classes + 1) |
| 77 |
|
| 78 |
with self.assertRaises(KeyError): |
| 79 |
self._TEST_MANAGER.RegisterAttributeContainer( |
| 80 |
shared_test_lib.TestAttributeContainer) |
| 81 |
|
| 82 |
finally: |
| 83 |
self._TEST_MANAGER.DeregisterAttributeContainer( |
| 84 |
shared_test_lib.TestAttributeContainer) |
| 85 |
|
| 86 |
self.assertEqual( |
| 87 |
len(self._TEST_MANAGER._attribute_container_classes), |
| 88 |
number_of_classes) |
| 89 |
|
| 90 |
|
| 91 |
if __name__ == '__main__': |
| 92 |
unittest.main() |