Skip to content

Commit

Permalink
Merge pull request #48 from WangJiannan/master
Browse files Browse the repository at this point in the history
Add missing stuff and fix typo for Renderer
  • Loading branch information
mission-liao committed Nov 27, 2015
2 parents 29be92d + 0d7d507 commit ab07c00
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/md/tutorial/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pyswagger could be used to generate random inputs to test your own APIs. Below i
```python
from pyswagger import SwaggerApp
from pyswagger.primitives import Renderer
from pyswagger.contrib.client.request import Client
from pyswagger.contrib.client.requests import Client

# create a SwaggerApp with a local resource file
app = SwaggerApp.create('/path/to/your/resource/file/swagger.json')
# init client
cilent = Client()
client = Client()
# init renderer
renderer = Renderer()

Expand Down
5 changes: 4 additions & 1 deletion pyswagger/primitives/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def default():
- max_prop_count: maximum count of properties (count of fixed properties + additional properties)
- max_str_length: maximum length of string type
- max_byte_length: maximum length of byte type
- max_array_length: maximum length of array
- max_file_length: maximum length of file, in byte
- minimal_property: only generate 'required' properties
- minimal_parameter: only generate 'required' parameter
Expand Down Expand Up @@ -298,13 +299,15 @@ def render_all(self, op, exclude=[], opt=None):
"""
opt = self.default() if opt == None else opt
if not isinstance(op, Operation):
raise ValueError('Not a Operation: {0}'.format(params))
raise ValueError('Not a Operation: {0}'.format(op))
if not isinstance(opt, dict):
raise ValueError('Not a dict: {0}'.format(opt))

template = opt['parameter_template']
out = {}
for p in op.parameters:
if p.name in exclude:
continue
if p.name in template:
out.update({p.name: template[p.name]})
continue
Expand Down
8 changes: 8 additions & 0 deletions pyswagger/tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,11 @@ def test_minimal(self):
self.assertTrue('p3' in ps, 'p3 should exist')
self.assertTrue(count > 0, 'count should be larger than zero, not {0}'.format(count))

def test_exclude(self):
""" make sure exclude works """
op = self.app.s('api.1').get
opt = self.rnd.default()
opt['minimal_parameter'] = False
for _ in six.moves.xrange(50):
ps = self.rnd.render_all(op, exclude=['p1'], opt=opt)
self.assertTrue('p1' not in ps, 'p1 should be excluded')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
'Programming Language :: Python :: 3.4',
'Topic :: Software Development :: Libraries :: Python Modules',
],
install_requires = ['six >= 1.7.2', 'pyaml>=15.03.1']
install_requires = ['six >= 1.7.2', 'pyaml>=15.03.1', 'validate_email']
)

0 comments on commit ab07c00

Please sign in to comment.