Example #1
0
 def test_uuid_json_encode_success(self):
     val = "e9979b9c-c469-11e4-a0ad-37ff5ce3a7bf"
     self.assertEqual(s.uuid().json_encode(UUID(val)), val)
Example #2
0
 def test_uuid_json_encode_error(self):
     self._error(s.uuid().json_encode, "definitely_not_a_uuid")
Example #3
0
 def test_uuid_validate_type_success(self):
     s.uuid().validate(UUID("af327a12-c469-11e4-8e4f-af4f7c44473b"))
Example #4
0
 def test_uuid_validate_type_error(self):
     self._error(s.uuid().validate, "this_is_not_a_uuid")
Example #5
0
 def test_uuid_disallow_none(self):
     self._error(s.uuid().json_encode, None)
Example #6
0
import roax.schema as s
import unittest
import uuid

from roax.resource import Resource, operation


body_schema = s.dict({
    "id": s.uuid(required=False),
    "foo": s.str()
})


class R1(Resource):

    schema = body_schema
    
    @operation(params={"body": body_schema}, returns=s.uuid())
    def create(self, body):
        return uuid.UUID("705d9048-97d6-4071-8359-3dbf0531fee9")


class R2(Resource):
    
    schema = body_schema
    
    def __init__(self):
        super().__init__()
        self.create = operation(params={"body": body_schema}, returns=s.uuid())(self.create)

    def create(self, body):
Example #7
0
def test_uuid_allow_none():
    assert s.uuid(nullable=True).json_encode(None) == None
Example #8
0
 def test_uuid_str_decode_success(self):
     val = "3629cf84-c46a-11e4-9b09-43a2f172bb56"
     self.assertEqual(s.uuid().str_decode(val), UUID(val))
Example #9
0
def test_uuid_str_decode_success():
    val = "3629cf84-c46a-11e4-9b09-43a2f172bb56"
    assert s.uuid().str_decode(val) == UUID(val)
Example #10
0
def test_uuid_disallow_none():
    _error(s.uuid().json_encode, None)
Example #11
0
def test_uuid_json_decode_success():
    val = "15a64a3a-c46a-11e4-b790-cb538a10de85"
    assert s.uuid().json_decode(val) == UUID(val)
Example #12
0
def test_uuid_json_encode_success():
    val = "e9979b9c-c469-11e4-a0ad-37ff5ce3a7bf"
    assert s.uuid().json_encode(UUID(val)) == val
Example #13
0
def test_one_of_json_codec():
    for value in [123, UUID("06b959d0-65e0-11e7-866d-6be08781d5cb"), False]:
        schema = s.one_of([s.int(), s.uuid(), s.bool()])
        assert schema.json_decode(schema.json_encode(value)) == value
Example #14
0
 def test_uuid_json_decode_success(self):
     val = "15a64a3a-c46a-11e4-b790-cb538a10de85"
     self.assertEqual(s.uuid().json_decode(val), UUID(val))
Example #15
0
def test_bytes_str_decode_error():
    _error(s.uuid().str_decode, "and_neither_is_this_a_bytes")
Example #16
0
 def test_uuid_json_decode_error(self):
     self._error(s.uuid().json_decode, "this_is_not_a_uuid_either")
Example #17
0
import roax.schema as s
import unittest
import uuid

from roax.resource import Resource, Resources, operation


body_schema = s.dict(
    properties = {
        "id": s.uuid(),
        "foo": s.str(),
    },
    required = {"foo"},
)


class R1(Resource):

    schema = body_schema
    
    @operation(params={"body": body_schema}, returns=s.uuid())
    def create(self, body):
        return uuid.UUID("705d9048-97d6-4071-8359-3dbf0531fee9")

    @operation(type="query", returns=s.str())
    def foo(self):
        return "bar"

class R2(Resource):
    
    schema = body_schema
Example #18
0
 def test_uuid_str_decode_error(self):
     self._error(s.uuid().str_decode, "and_neither_is_this")
Example #19
0
 def __init__(self):
     super().__init__()
     self.create = operation(params={"body": body_schema}, returns=s.uuid())(self.create)
Example #20
0
 def test_uuid_allow_none(self):
     self.assertEqual(s.uuid(nullable=True).json_encode(None), None)
Example #21
0
import roax.schema as s
import unittest

from roax.openapi import OpenAPIResource
from roax.resource import Resource, operation
from roax.wsgi import App

params = {
    "a": s.list(s.str()),
    "b": s.set(s.str()),
    "c": s.int(),
    "d": s.float(),
    "e": s.bool(),
    "f": s.bytes(),
    "g": s.datetime(),
    "h": s.uuid(),
}


class TestResource(Resource):
    @operation(type="action", params=params, security=[])
    def test(self, a, b, c, d, e, f, g, h):
        pass


app = App("/", "Title", "1.0")
app.register_resource("/test", TestResource())


class TestOpenAPI(unittest.TestCase):
    def test_openapi_no_errors(self):