예제 #1
0
 def setUp(self):
     json_obj = {
         'title': 'test_title',
         'type': 'test_type',
         'description': 'test_desc'
     }
     self.pi = docsmodel.ParsedItem(json_obj, 'test_name', True, 0)
예제 #2
0
 def test_boolean(self):
     pi = docsmodel.ParsedItem(
         {
             'title': 'boolean',
             'description': 'Example schema description.',
             'type': 'boolean'
         }, 'root', True, 0)
     self.assertEqual(self.parsed_items[0], pi)
예제 #3
0
 def test_root_element(self):
     """Tests if root entry is generated correctly."""
     item = docsmodel.ParsedItem(
         {
             'title': 'simple_object',
             'type': 'object',
             'description': 'Example schema description.'
         }, 'root', True, 0)
     self.assertEqual(self.parsed_items[0], item)
예제 #4
0
 def test_null(self):
     """Tests null schema parsing."""
     item = docsmodel.ParsedItem(
         {
             'title': 'null',
             'type': 'null',
             'description': 'Example schema description.'
         }, 'root', True, 0)
     self.assertEqual(self.parsed_items[0], item)
예제 #5
0
 def test_root_enum_entry(self):
     entries = self.docs_model.parse(self.schema)
     good_entry = docsmodel.ParsedItem(
         {
             'title': 'enum',
             'description': 'Example schema description.',
             'type': None
         }, 'root', True, 0)
     good_entry['enum'] = ['item1', 2]
     self.assertEqual(good_entry, entries[0])
예제 #6
0
 def test_last_name(self):
     item = docsmodel.ParsedItem(
         {
             'title': '',
             'type': 'string',
             'description': 'Last name'
         }, 'lastName', False, 1)
     item['pattern'] = None
     item['minLength'] = None
     item['maxLength'] = None
     item['format'] = None
     self.assertEqual(self.parsed_items[2], item)
예제 #7
0
 def test_number(self):
     item = docsmodel.ParsedItem(
         {
             'title': 'number_defaults',
             'type': 'number',
             'description': 'Example schema description.'
         }, 'root', True, 0)
     item['minimum'] = '-inf'
     item['maximum'] = '+inf'
     item['exclusiveMinimum'] = False
     item['exclusiveMaximum'] = False
     self.assertEqual(self.parsed_items[0], item)
예제 #8
0
 def test_integer(self):
     pi = docsmodel.ParsedItem(
         {
             'title': 'integer',
             'type': 'integer',
             'description': 'Example schema description.'
         }, 'root', True, 0)
     pi['minimum'] = 3
     pi['maximum'] = 10
     pi['exclusiveMinimum'] = True
     pi['exclusiveMaximum'] = False
     self.assertEqual(self.parsed_items[0], pi)
예제 #9
0
    def test_other_entries(self):
        # TODO: test for required field
        entries = self.docs_model.parse(self.schema)
        good_entries = list()
        good_entries.append(
            docsmodel.ParsedItem(
                {
                    'title': '',
                    'description': '',
                    'type': 'number'
                }, 'array item 0', False, 1))
        good_entries[0]['maximum'] = '+inf'
        good_entries[0]['minimum'] = '-inf'
        good_entries[0]['exclusiveMinimum'] = False
        good_entries[0]['exclusiveMaximum'] = False

        good_entries.append(
            docsmodel.ParsedItem(
                {
                    'title': '',
                    'description': '',
                    'type': 'string'
                }, 'array item 1', False, 1))
        good_entries[1]['minLength'] = None
        good_entries[1]['maxLength'] = None
        good_entries[1]['pattern'] = None
        good_entries[1]['format'] = None

        good_entries.append(
            docsmodel.ParsedItem(
                {
                    'title': '',
                    'description': '',
                    'type': 'boolean'
                }, 'array item 2', False, 1))

        self.assertEqual(good_entries[0], entries[1])
        self.assertEqual(good_entries[1], entries[2])
        self.assertEqual(good_entries[2], entries[3])
예제 #10
0
 def test_string(self):
     """Tests parsing string schema model"""
     item = docsmodel.ParsedItem(
         {
             'title': 'string_defaults',
             'type': 'string',
             'description': 'Example schema description.'
         }, 'root', True, 0)
     item['minLength'] = None
     item['maxLength'] = None
     item['pattern'] = None
     item['format'] = None
     self.assertEqual(self.parsed_items[0], item)
예제 #11
0
 def test_string(self):
     """Tests parsing string schema model"""
     item = docsmodel.ParsedItem(
         {
             'title': 'string',
             'type': 'string',
             'description': 'Example schema description.'
         }, 'root', True, 0)
     item['minLength'] = 1
     item['maxLength'] = 20
     item['pattern'] = '^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$'
     item['format'] = 'hostname'
     self.assertEqual(self.parsed_items[0], item)
예제 #12
0
 def test_array_root(self):
     schema = self.schema
     parsed_items = self.docs_model.parse(schema)
     item = docsmodel.ParsedItem(
         {
             'title': 'array_list',
             'type': 'array',
             'description': 'Example schema description.'
         }, 'root', True, 0)
     item['minItems'] = 1
     item['maxItems'] = 10
     item['uniqueItems'] = False
     for item, value in item.items():
         self.assertEqual(parsed_items[0][item], value)
예제 #13
0
    def test_root(self):
        """Tests array tuple root element."""
        entries = self.docs_model.parse(self.schema)
        root_entry = entries[0]
        good_root = docsmodel.ParsedItem(
            {
                "title": "array_tuple",
                "description": "Example schema description.",
                "type": "array"
            }, 'root', True, 0)
        good_root['uniqueItems'] = False
        good_root['minItems'] = None
        good_root['maxItems'] = None

        self.assertEqual(root_entry, good_root)