| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
"""Tests for the schema helper.""" |
| 4 |
|
| 5 |
import unittest |
| 6 |
|
| 7 |
from acstore.helpers import schema |
| 8 |
|
| 9 |
from tests import test_lib as shared_test_lib |
| 10 |
|
| 11 |
|
| 12 |
class SchemaHelperTest(shared_test_lib.BaseTestCase): |
| 13 |
"""Tests for the schema helper.""" |
| 14 |
|
| 15 |
# pylint: disable=protected-access |
| 16 |
|
| 17 |
def testHasDataType(self): |
| 18 |
"""Tests the HasDataType function.""" |
| 19 |
result = schema.SchemaHelper.HasDataType('str') |
| 20 |
self.assertTrue(result) |
| 21 |
|
| 22 |
result = schema.SchemaHelper.HasDataType('test') |
| 23 |
self.assertFalse(result) |
| 24 |
|
| 25 |
def testRegisterDataType(self): |
| 26 |
"""Tests the RegisterDataType function.""" |
| 27 |
number_of_data_types = len(schema.SchemaHelper._data_types) |
| 28 |
|
| 29 |
schema.SchemaHelper.RegisterDataType('test', {'json': None}) |
| 30 |
|
| 31 |
try: |
| 32 |
self.assertEqual( |
| 33 |
len(schema.SchemaHelper._data_types), number_of_data_types + 1) |
| 34 |
|
| 35 |
with self.assertRaises(KeyError): |
| 36 |
schema.SchemaHelper.RegisterDataType('test', {'json': None}) |
| 37 |
|
| 38 |
finally: |
| 39 |
schema.SchemaHelper.DeregisterDataType('test') |
| 40 |
|
| 41 |
self.assertEqual( |
| 42 |
len(schema.SchemaHelper._data_types), number_of_data_types) |
| 43 |
|
| 44 |
def testRegisterDataTypes(self): |
| 45 |
"""Tests the RegisterDataTypes function.""" |
| 46 |
number_of_data_types = len(schema.SchemaHelper._data_types) |
| 47 |
|
| 48 |
schema.SchemaHelper.RegisterDataTypes({'test': {'json': None}}) |
| 49 |
|
| 50 |
try: |
| 51 |
self.assertEqual( |
| 52 |
len(schema.SchemaHelper._data_types), number_of_data_types + 1) |
| 53 |
|
| 54 |
with self.assertRaises(KeyError): |
| 55 |
schema.SchemaHelper.RegisterDataTypes({'test': {'json': None}}) |
| 56 |
|
| 57 |
finally: |
| 58 |
schema.SchemaHelper.DeregisterDataType('test') |
| 59 |
|
| 60 |
self.assertEqual( |
| 61 |
len(schema.SchemaHelper._data_types), number_of_data_types) |
| 62 |
|
| 63 |
|
| 64 |
if __name__ == '__main__': |
| 65 |
unittest.main() |