Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / schema_util_test.py
blob8116f220ce9bef2740311d90e9a55e0aa4d5c707
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import unittest
7 from copy import deepcopy
9 from schema_util import RemoveNoDocs, DetectInlineableTypes, InlineDocs
12 class SchemaUtilTest(unittest.TestCase):
14 def testRemoveNoDocs(self):
15 expected_nodoc = [
17 'name': 'B',
18 'list': [
20 'name': 'B2'
25 'name': 'D',
26 'nodoc': False
29 'name': 'E',
30 'items1': [
32 'name': 'E1',
33 'items': [
35 'name': 'E1.3'
40 'name': 'E2'
46 nodoc_data = [
48 'name': 'A',
49 'nodoc': True
52 'name': 'B',
53 'list': [
55 'name': 'B1',
56 'nodoc': True
59 'name': 'B2'
62 'name': 'B3',
63 'nodoc': True
68 'name': 'C',
69 'nodoc': True
72 'name': 'D',
73 'nodoc': False
76 'name': 'E',
77 'dict': {
78 'name': 'Ed',
79 'nodoc': True
81 'items1': [
83 'name': 'E1',
84 'items': [
86 'name': 'E1.1',
87 'nodoc': True
90 'name': 'E1.2',
91 'nodoc': True
94 'name': 'E1.3'
99 'name': 'E2'
102 'name': 'E3',
103 'nodoc': True
109 RemoveNoDocs(nodoc_data)
110 self.assertEquals(expected_nodoc, nodoc_data)
112 def testInlineDocs(self):
113 schema = {
114 'namespace': 'storage',
115 'properties': {
116 'key2': {
117 'description': 'second key',
118 '$ref': 'Key'
120 'key1': {
121 'description': 'first key',
122 '$ref': 'Key'
125 'types': [
127 'inline_doc': True,
128 'type': 'string',
129 'id': 'Key', # Should be inlined into both properties and be removed
130 # from types.
131 'description': 'This is a key.', # This description should disappear.
132 'marker': True # This should appear three times in the output.
135 'items': {
136 '$ref': 'Key'
138 'type': 'array',
139 'id': 'KeyList',
140 'description': 'A list of keys'
145 expected_schema = {
146 'namespace': 'storage',
147 'properties': {
148 'key2': {
149 'marker': True,
150 'type': 'string',
151 'description': 'second key'
153 'key1': {
154 'marker': True,
155 'type': 'string',
156 'description': 'first key'
159 'types': [
161 'items': {
162 'marker': True,
163 'type': 'string'
165 'type': 'array',
166 'id': 'KeyList',
167 'description': 'A list of keys'
172 inlined_schema = deepcopy(schema)
173 InlineDocs(inlined_schema)
174 self.assertEqual(expected_schema, inlined_schema)
176 def testDetectInline(self):
177 schema = {
178 'types': [
180 'id': 'Key',
181 'items': {
182 '$ref': 'Value'
186 'id': 'Value',
187 'marker': True
192 expected_schema = {
193 'types': [
195 'id': 'Key',
196 'items': {
197 'marker': True,
203 DetectInlineableTypes(schema)
204 InlineDocs(schema)
205 self.assertEqual(expected_schema, schema)
208 if __name__ == '__main__':
209 unittest.main()