Skip to content

Commit

Permalink
Merge pull request #5 from mission-liao/minor_fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
mission-liao committed Nov 26, 2014
2 parents 48f67c1 + af78117 commit 79d7f11
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: python
branches:
only:
- master
python:
- "2.6"
- "2.7"
Expand Down
10 changes: 6 additions & 4 deletions pyswagger/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ class Byte(object):
def __init__(self, _, v):
""" constructor
:param str v: only accept six.string_types
:param str v: accept six.string_types, six.binary_type
"""
if isinstance(v, six.string_types):
if isinstance(v, six.binary_type):
self.v = v
elif isinstance(v, six.string_types):
self.v = v.encode('utf-8')
else:
raise ValueError('Unsupported type for Byte: ' + str(type(v)))

def __str__(self):
return self.v
return self.v.decode('utf-8')

def to_json(self):
""" according to https://github.com/wordnik/swagger-spec/issues/50,
Expand Down Expand Up @@ -77,7 +79,7 @@ def __init__(self, _, v):
"""
self.v = None
if isinstance(v, float):
self.v = datetime.datetime.fromtimestamp(v)
self.v = datetime.datetime.utcfromtimestamp(v)
elif isinstance(v, datetime.datetime):
self.v = v
elif isinstance(v, six.string_types):
Expand Down
2 changes: 1 addition & 1 deletion pyswagger/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def default_tree_traversal(root):

# name of child are json-pointer encoded, we don't have
# to encode it again.
objs.extend(map(lambda i: (path + '/' + i[0],) + (i[1],), obj._children_.iteritems()))
objs.extend(map(lambda i: (path + '/' + i[0],) + (i[1],), six.iteritems(obj._children_)))

# the path we expose here follows JsonPointer described here
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
Expand Down
4 changes: 2 additions & 2 deletions pyswagger/scanner/v1_2/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _operation(self, path, obj, app):
# looking for it in resource object.
_auth = obj.authorizations if obj.authorizations and len(obj.authorizations) > 0 else obj._parent_.authorizations
if _auth:
for name, scopes in _auth.iteritems():
for name, scopes in six.iteritems(_auth):
o.security[name] = [v.scope for v in scopes]

# Operation return value
Expand Down Expand Up @@ -247,7 +247,7 @@ def _model(self, path, obj, app):
self.__swagger.definitions[s] = o

props = {}
for name, prop in obj.properties.iteritems():
for name, prop in six.iteritems(obj.properties):
props[name] = convert_schema_from_datatype(prop, scope)
o.update_field('properties', props)
o.update_field('required', obj.required)
Expand Down
2 changes: 1 addition & 1 deletion pyswagger/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SwaggerUtilsTestCase(unittest.TestCase):

def test_iso8601_convert_from_string(self):
""" convert string to date/datetime """
self.assertEqual(utils.from_iso8601('2007-04-05'), datetime(2007, 04, 05))
self.assertEqual(utils.from_iso8601('2007-04-05'), datetime(2007, 4, 5))
self.assertEqual(utils.from_iso8601('2007-04-05T14:30'), datetime(2007, 4, 5, 14, 30))
self.assertEqual(utils.from_iso8601('2007-04-05T14:30Z'), datetime(2007, 4, 5, 14, 30, tzinfo=utils.FixedTZ(0, 0)))
self.assertEqual(utils.from_iso8601('2007-04-05T12:30-02:00'), datetime(2007, 4, 5, 14, 30, tzinfo=utils.FixedTZ(0, 0)))
Expand Down
3 changes: 2 additions & 1 deletion pyswagger/tests/v1_2/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Authorizations,
Model)
import unittest
import six


app = SwaggerApp._create_(get_test_data_folder(version='1.2', which='wordnik'))
Expand Down Expand Up @@ -213,5 +214,5 @@ def test_children(self):
""" children """
chd = app.raw._children_
self.assertEqual(len(chd), 5)
self.assertEqual(set(['apis/user', 'apis/pet', 'apis/store']), set([k for k, v in chd.iteritems() if isinstance(v, Resource)]))
self.assertEqual(set(['apis/user', 'apis/pet', 'apis/store']), set([k for k, v in six.iteritems(chd) if isinstance(v, Resource)]))

8 changes: 3 additions & 5 deletions pyswagger/tests/v1_2/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_authorization(self):
""" Authorization -> Security Scheme
"""
s = app.root.securityDefinitions
self.assertEqual(s.keys(), ['oauth2'])
self.assertEqual(list(s.keys()), ['oauth2'])

ss = s['oauth2']
self.assertEqual(ss.type, 'oauth2')
Expand All @@ -104,17 +104,15 @@ def test_parameter(self):

# form
o = app.root.paths['/pet/uploadImage'].post
p = sorted([p for p in o.parameters if getattr(p, 'in') == 'formData'])[0]
p = [p for p in o.parameters if getattr(p, 'in') == 'formData' and p.type == 'string'][0]
self.assertEqual(p.name, 'additionalMetadata')
self.assertEqual(p.required, False)
self.assertEqual(p.type, 'string')

# file
o = app.root.paths['/pet/uploadImage'].post
p = sorted([p for p in o.parameters if getattr(p, 'in') == 'formData'])[1]
p = [p for p in o.parameters if getattr(p, 'in') == 'formData' and p.type == 'file'][0]
self.assertEqual(p.name, 'file')
self.assertEqual(p.required, False)
self.assertEqual(p.type, 'file')

def test_model(self):
""" Model -> Definition
Expand Down
11 changes: 6 additions & 5 deletions pyswagger/tests/v2_0/test_prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pyswagger.utils import jp_compose
import unittest
import datetime
import six


class SchemaTestCase(unittest.TestCase):
Expand Down Expand Up @@ -118,7 +119,7 @@ def test_byte(self):

bv = b._prim_("BBBBB")
self.assertEqual(str(bv), "BBBBB")
self.assertEqual(bv.to_json(), "QkJCQkI=")
self.assertEqual(bv.to_json(), six.b("QkJCQkI="))

def test_date(self):
""" test date """
Expand All @@ -138,13 +139,13 @@ def test_date_time(self):
d = self.app.resolve("#/definitions/date-time")

# test input of constructor
self.assertEqual(str(d._prim_(float(0))), "1970-01-01T08:00:00")
self.assertEqual(str(d._prim_(datetime.datetime.fromtimestamp(0))), "1970-01-01T08:00:00")
self.assertEqual(str(d._prim_(datetime.datetime.fromtimestamp(0).isoformat())), "1970-01-01T08:00:00")
self.assertEqual(str(d._prim_(float(0))), "1970-01-01T00:00:00")
self.assertEqual(str(d._prim_(datetime.datetime.utcfromtimestamp(0))), "1970-01-01T00:00:00")
self.assertEqual(str(d._prim_(datetime.datetime.utcfromtimestamp(0).isoformat())), "1970-01-01T00:00:00")

# to_json
dv = d._prim_(float(0))
self.assertEqual(dv.to_json(), "1970-01-01T08:00:00")
self.assertEqual(dv.to_json(), "1970-01-01T00:00:00")


class HeaderTestCase(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion pyswagger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def get_dict_as_tuple(d):
and return it as tuple.
"""
# TODO: test case
for k, v in d.iteritems():
for k, v in six.iteritems(d):
return k, v
return None

Expand Down

0 comments on commit 79d7f11

Please sign in to comment.