OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 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. |
| 5 |
| 6 import schema_util |
| 7 import unittest |
| 8 |
| 9 class SchemaUtilTest(unittest.TestCase): |
| 10 def testStripSchemaNamespace(self): |
| 11 self.assertEquals('Bar', schema_util.StripSchemaNamespace('foo.Bar')) |
| 12 self.assertEquals('Baz', schema_util.StripSchemaNamespace('Baz')) |
| 13 |
| 14 def testPrefixSchemasWithNamespace(self): |
| 15 schemas = [ |
| 16 { 'namespace': 'n1', |
| 17 'types': [ |
| 18 { |
| 19 'id': 'T1', |
| 20 'customBindings': 'T1', |
| 21 'properties': { |
| 22 'p1': {'$ref': 'T1'}, |
| 23 'p2': {'$ref': 'fully.qualified.T'}, |
| 24 } |
| 25 } |
| 26 ], |
| 27 'functions': [ |
| 28 { |
| 29 'parameters': [ |
| 30 { '$ref': 'T1' }, |
| 31 { '$ref': 'fully.qualified.T' }, |
| 32 ], |
| 33 'returns': { '$ref': 'T1' } |
| 34 }, |
| 35 ], |
| 36 'events': [ |
| 37 { |
| 38 'parameters': [ |
| 39 { '$ref': 'T1' }, |
| 40 { '$ref': 'fully.qualified.T' }, |
| 41 ], |
| 42 }, |
| 43 ], |
| 44 }, |
| 45 ] |
| 46 schema_util.PrefixSchemasWithNamespace(schemas) |
| 47 self.assertEquals('n1.T1', schemas[0]['types'][0]['id']) |
| 48 self.assertEquals('n1.T1', schemas[0]['types'][0]['customBindings']) |
| 49 self.assertEquals('n1.T1', |
| 50 schemas[0]['types'][0]['properties']['p1']['$ref']) |
| 51 self.assertEquals('fully.qualified.T', |
| 52 schemas[0]['types'][0]['properties']['p2']['$ref']) |
| 53 |
| 54 self.assertEquals('n1.T1', |
| 55 schemas[0]['functions'][0]['parameters'][0]['$ref']) |
| 56 self.assertEquals('fully.qualified.T', |
| 57 schemas[0]['functions'][0]['parameters'][1]['$ref']) |
| 58 self.assertEquals('n1.T1', |
| 59 schemas[0]['functions'][0]['returns']['$ref']) |
| 60 |
| 61 self.assertEquals('n1.T1', |
| 62 schemas[0]['events'][0]['parameters'][0]['$ref']) |
| 63 self.assertEquals('fully.qualified.T', |
| 64 schemas[0]['events'][0]['parameters'][1]['$ref']) |
| 65 |
| 66 if __name__ == '__main__': |
| 67 unittest.main() |
OLD | NEW |