11from __future__ import absolute_import
22
3+ import six
4+
35from swagger_py_codegen .parser import Swagger
46from swagger_py_codegen .sanic import (
57 _swagger_to_sanic_url ,
@@ -80,8 +82,9 @@ def test_swagger_to_sanic_url():
8082 )
8183 }
8284 ]
83- for case in cases :
84- assert _swagger_to_sanic_url (case ['url' ], case ['data' ]) == case ['expect' ]
85+ if six .PY3 :
86+ for case in cases :
87+ assert _swagger_to_sanic_url (case ['url' ], case ['data' ]) == case ['expect' ]
8588
8689
8790def test_path_to_endpoint ():
@@ -95,8 +98,9 @@ def test_path_to_endpoint():
9598 'path' : '/users/{id}/hat-size' ,
9699 'expect' : 'users_id_hat_size'
97100 }]
98- for case in cases :
99- assert _path_to_endpoint (case ['path' ]) == case ['expect' ]
101+ if six .PY3 :
102+ for case in cases :
103+ assert _path_to_endpoint (case ['path' ]) == case ['expect' ]
100104
101105
102106def test_path_to_resource_name ():
@@ -110,8 +114,9 @@ def test_path_to_resource_name():
110114 'path' : '/posts/{post_id}/last-reply' ,
111115 'expect' : 'PostsPostIdLastReply'
112116 }]
113- for case in cases :
114- assert _path_to_resource_name (case ['path' ]) == case ['expect' ]
117+ if six .PY3 :
118+ for case in cases :
119+ assert _path_to_resource_name (case ['path' ]) == case ['expect' ]
115120
116121
117122def test_process_data ():
@@ -133,12 +138,12 @@ def test_process_data():
133138 }
134139 }
135140 }
136- swagger = Swagger ( data )
137- generator = SanicGenerator ( swagger )
138- schemas , routes , view1 , view2 = list ( generator . generate ())[: 4 ]
139- view1 , view2 = sorted ([ view1 , view2 ], key = lambda x : x . data [ 'name' ])
140- print ( schemas . data [ 'validators' ][( 'posts_post_id' , 'GET' ) ])
141- assert ('posts_post_id' , 'GET' ) in schemas .data ['validators' ]
142- assert schemas .data ['validators' ][('posts_post_id' , 'GET' )]['args' ]['properties' ]['page' ]['type' ] == 'integer'
143- assert view1 .data ['url' ] == '/posts/<int:post_id>'
144- assert view1 .data ['name' ] == 'PostsPostId'
141+ if six . PY3 :
142+ swagger = Swagger ( data )
143+ generator = SanicGenerator ( swagger )
144+ schemas , routes , view1 , view2 = list ( generator . generate ())[: 4 ]
145+ view1 , view2 = sorted ([ view1 , view2 ], key = lambda x : x . data [ 'name' ])
146+ assert ('posts_post_id' , 'GET' ) in schemas .data ['validators' ]
147+ assert schemas .data ['validators' ][('posts_post_id' , 'GET' )]['args' ]['properties' ]['page' ]['type' ] == 'integer'
148+ assert view1 .data ['url' ] == '/posts/<int:post_id>'
149+ assert view1 .data ['name' ] == 'PostsPostId'
0 commit comments