Exemplo n.º 1
0
    def test_additional_properties(self):
        obj = Object({'test': 'example'},
                     schema=Schema(
                         {'additionalProperties': {
                             'type': 'string'
                         }}))

        self.assertEqual(obj['test'].schema, {'type': 'string'})
Exemplo n.º 2
0
 def test_properties_non_matching(self):
     obj = Object({'test': 'example'},
                  schema=Schema(
                      {'properties': {
                          'tast': {
                              'type': 'string'
                          }
                      }}))
     self.assertEqual(obj['test'].schema, {})
Exemplo n.º 3
0
    def test_additional_items(self):
        obj = Array([1, 2, 3],
                    schema=Schema({
                        'items': ({
                            'type': 'number'
                        }, {
                            'type': 'string'
                        }),
                        'additionalItems': {
                            'type': 'integer'
                        }
                    }))

        self.assertEqual(obj[0].schema, {'type': 'number'})
        self.assertEqual(obj[1].schema, {'type': 'string'})
        self.assertEqual(obj[2].schema, {'type': 'integer'})
Exemplo n.º 4
0
 def test_items_tuple(self):
     obj = Array([{
         'test': 1
     }, {
         'test': 2
     }, {
         'test': 3
     }],
                 schema=Schema(
                     {'items': ({
                         'type': 'number'
                     }, {
                         'type': 'string'
                     })}))
     self.assertEqual(obj[1].schema, {'type': 'string'})
     self.assertEqual(obj[0].schema, {'type': 'number'})
Exemplo n.º 5
0
    def test_items(self):
        obj = Array([{
            'test': 1
        }, {
            'test': 2
        }, {
            'test': '3'
        }],
                    schema=Schema({
                        'items': {
                            'properties': {
                                'test': {
                                    'type': 'number',
                                    'pattern': '1'
                                }
                            }
                        }
                    }))

        self.assertTrue('properties' in obj[1].schema)
        self.assertEqual(obj[1]['test'].schema, {
            'type': 'number',
            'pattern': '1'
        })
Exemplo n.º 6
0
class MessageCollection(api.Collection):
    schema = Schema({'id': 'message-collection'})
    objects = Message.objects
Exemplo n.º 7
0
class Message(api.Resource):
    schema = Schema({'id': 'message'})
Exemplo n.º 8
0
class StoredTestResource(Resource):
    schema = Schema({'id': 'stored-test'})

    @classmethod
    def db(cls):
        return MongoClient()['test']
Exemplo n.º 9
0
import unittest
import os

from pymongo import MongoClient

from json_resource import Resource, Schema, ResourceNotFound, ResourceExists, \
    ValidationError

Schema.register_schema_dir(os.path.join(os.path.dirname(__file__), 'schemas'))


class StoredTestResource(Resource):
    schema = Schema({'id': 'stored-test'})

    @classmethod
    def db(cls):
        return MongoClient()['test']


class StoredResourceTest(unittest.TestCase):
    def setUp(self):
        self.resource = StoredTestResource({'id': 1})

    def tearDown(self):
        StoredTestResource.objects.collection.remove({})

    def test_insert(self):
        self.resource.save(create=True)

        self.assertTrue(self.resource.exists)
Exemplo n.º 10
0
schema = Schema({
    'id':
    'test',
    'description':
    'Test Description',
    'title':
    'Test Title',
    'properties': {
        'id': {
            'type': 'number'
        },
        'sub-resource': {
            'properties': {
                'test': {
                    'type': 'string',
                    'format': 'email'
                }
            }
        },
        'type': {
            'type': 'string'
        }
    },
    'required': ['id'],
    'links': [{
        'rel': 'self',
        'mediaType': 'application/json',
        'href': '/test/{id}'
    }, {
        'rel': 'self',
        'mediaType': 'application/jpeg',
        'href': '/test/{id}.jpg'
    }]
})
Exemplo n.º 11
0
class TestCollection(Collection):
    schema = Schema({'id': 'collection'})
    objects = TestResource.objects