FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-openapi-codec/tests/test_encode.py at master · aljp/python-openapi-codec · GitHub
aljp
/
python-openapi-codec
Public
forked from
core-api/python-openapi-codec
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-openapi-codec
/
tests
/
test_encode.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (96 loc) · 3.35 KB
Breadcrumbs
python-openapi-codec
/
tests
/
test_encode.py
Copy path
File metadata and controls
108 lines (96 loc) · 3.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import
coreapi
import
coreschema
from
openapi_codec
.
encode
import
generate_swagger_object
,
_get_parameters
from
unittest
import
TestCase
class
TestBasicInfo
(
TestCase
):
def
setUp
(
self
):
self
.
document
=
coreapi
.
Document
(
title
=
'Example API'
,
url
=
'https://www.example.com/'
,
description
=
'Example description.'
,
)
self
.
swagger
=
generate_swagger_object
(
self
.
document
)
def
test_info
(
self
):
self
.
assertIn
(
'info'
,
self
.
swagger
)
expected
=
{
'title'
:
self
.
document
.
title
,
'version'
:
''
,
'description'
:
self
.
document
.
description
,
}
self
.
assertEquals
(
self
.
swagger
[
'info'
],
expected
)
def
test_swagger_version
(
self
):
self
.
assertIn
(
'swagger'
,
self
.
swagger
)
expected
=
'2.0'
self
.
assertEquals
(
self
.
swagger
[
'swagger'
],
expected
)
def
test_host
(
self
):
self
.
assertIn
(
'host'
,
self
.
swagger
)
expected
=
'www.example.com'
self
.
assertEquals
(
self
.
swagger
[
'host'
],
expected
)
def
test_schemes
(
self
):
self
.
assertIn
(
'schemes'
,
self
.
swagger
)
expected
=
[
'https'
]
self
.
assertEquals
(
self
.
swagger
[
'schemes'
],
expected
)
class
TestPaths
(
TestCase
):
def
setUp
(
self
):
self
.
path
=
'/users/'
self
.
document
=
coreapi
.
Document
(
content
=
{
'users'
: {
'create'
:
coreapi
.
Link
(
action
=
'post'
,
url
=
self
.
path
),
'list'
:
coreapi
.
Link
(
action
=
'get'
,
url
=
self
.
path
)
}
}
)
self
.
swagger
=
generate_swagger_object
(
self
.
document
)
def
test_paths
(
self
):
self
.
assertIn
(
'paths'
,
self
.
swagger
)
self
.
assertIn
(
self
.
path
,
self
.
swagger
[
'paths'
])
self
.
assertIn
(
'get'
,
self
.
swagger
[
'paths'
][
self
.
path
])
self
.
assertIn
(
'post'
,
self
.
swagger
[
'paths'
][
self
.
path
])
expected
=
{
'responses'
: {
'200'
: {
'description'
:
''
}
},
'parameters'
: [],
'operationId'
:
'list'
,
'tags'
: [
'users'
]
}
self
.
assertEquals
(
self
.
swagger
[
'paths'
][
self
.
path
][
'get'
],
expected
)
expected
=
{
'responses'
: {
'201'
: {
'description'
:
''
}
},
'parameters'
: [],
'operationId'
:
'create'
,
'tags'
: [
'users'
]
}
self
.
assertEquals
(
self
.
swagger
[
'paths'
][
self
.
path
][
'post'
],
expected
)
class
TestParameters
(
TestCase
):
def
setUp
(
self
):
self
.
field
=
coreapi
.
Field
(
name
=
'email'
,
required
=
True
,
location
=
'query'
,
schema
=
coreschema
.
String
(
description
=
'A valid email address.'
)
)
self
.
swagger
=
_get_parameters
(
coreapi
.
Link
(
fields
=
[
self
.
field
]),
encoding
=
''
)
def
test_expected_fields
(
self
):
self
.
assertEquals
(
len
(
self
.
swagger
),
1
)
expected
=
{
'name'
:
self
.
field
.
name
,
'required'
:
self
.
field
.
required
,
'in'
:
'query'
,
'description'
:
self
.
field
.
schema
.
description
,
'type'
:
'string'
# Everything is a string for now.
}
self
.
assertEquals
(
self
.
swagger
[
0
],
expected
)
Back
|
FazBrowse Home
|
New Git URL