4
4
from coreapi .document import Document , Link , Error , Field
5
5
from coreapi .exceptions import ParseError , NoCodecAvailable
6
6
from coreapi .utils import negotiate_decoder , negotiate_encoder
7
+ from coreschema import Enum , String
7
8
import pytest
8
9
9
10
@@ -21,7 +22,13 @@ def doc():
21
22
'integer' : 123 ,
22
23
'dict' : {'key' : 'value' },
23
24
'list' : [1 , 2 , 3 ],
24
- 'link' : Link (url = 'http://example.org/' , fields = [Field (name = 'example' )]),
25
+ 'link' : Link (
26
+ url = 'http://example.org/' ,
27
+ fields = [
28
+ Field (name = 'noschema' ),
29
+ Field (name = 'string_example' , schema = String ()),
30
+ Field (name = 'enum_example' , schema = Enum (['a' , 'b' , 'c' ])),
31
+ ]),
25
32
'nested' : {'child' : Link (url = 'http://example.org/123' )},
26
33
'_type' : 'needs escaping'
27
34
})
@@ -40,7 +47,26 @@ def test_document_to_primitive(doc):
40
47
'integer' : 123 ,
41
48
'dict' : {'key' : 'value' },
42
49
'list' : [1 , 2 , 3 ],
43
- 'link' : {'_type' : 'link' , 'fields' : [{'name' : 'example' }]},
50
+ 'link' : {'_type' : 'link' , 'fields' : [
51
+ {'name' : 'noschema' },
52
+ {
53
+ 'name' : 'string_example' ,
54
+ 'schema' : {
55
+ '_type' : 'string' ,
56
+ 'title' : '' ,
57
+ 'description' : '' ,
58
+ },
59
+ },
60
+ {
61
+ 'name' : 'enum_example' ,
62
+ 'schema' : {
63
+ '_type' : 'enum' ,
64
+ 'title' : '' ,
65
+ 'description' : '' ,
66
+ 'extra' : {'enum' : ['a' , 'b' , 'c' ]},
67
+ },
68
+ },
69
+ ]},
44
70
'nested' : {'child' : {'_type' : 'link' , 'url' : '/123' }},
45
71
'__type' : 'needs escaping'
46
72
}
@@ -56,7 +82,30 @@ def test_primitive_to_document(doc):
56
82
'integer' : 123 ,
57
83
'dict' : {'key' : 'value' },
58
84
'list' : [1 , 2 , 3 ],
59
- 'link' : {'_type' : 'link' , 'url' : 'http://example.org/' , 'fields' : [{'name' : 'example' }]},
85
+ 'link' : {
86
+ '_type' : 'link' ,
87
+ 'url' : 'http://example.org/' ,
88
+ 'fields' : [
89
+ {'name' : 'noschema' },
90
+ {
91
+ 'name' : 'string_example' ,
92
+ 'schema' : {
93
+ '_type' : 'string' ,
94
+ 'title' : '' ,
95
+ 'description' : '' ,
96
+ },
97
+ },
98
+ {
99
+ 'name' : 'enum_example' ,
100
+ 'schema' : {
101
+ '_type' : 'enum' ,
102
+ 'title' : '' ,
103
+ 'description' : '' ,
104
+ 'extra' : {'enum' : ['a' , 'b' , 'c' ]},
105
+ },
106
+ },
107
+ ],
108
+ },
60
109
'nested' : {'child' : {'_type' : 'link' , 'url' : 'http://example.org/123' }},
61
110
'__type' : 'needs escaping'
62
111
}
0 commit comments