Giter VIP home page Giter VIP logo

stoplight's Introduction

I've been writing software professionally within two distinct millennia now, mostly centered around Python, Go, C/C++, security, and general Linux nerdiness.

Father. Husband. Shameless purveyor of dad jokes. Admirer of nature. Aviation addict. Amateur Radio operator.

stoplight's People

Contributors

benjamenmeyer avatar drewbrew avatar painterjd avatar sriram-mv avatar tomfaulkner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

stoplight's Issues

`\}` in URL generates error message to the application...

$ curl 'localhost:8081/myendpoint/\}'

generates

[] - [] - [2018/04/04 17:07:48] - [myproj_api.api.handlers.generic] - [ERROR] - Unhandled Exception
Traceback (most recent call last):
  File "/home/devuser/code/myproj/.venv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/devuser/code/myproj/.venv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/devuser/code/myproj/.venv/lib/python3.5/site-packages/stoplight/decorators.py", line 144, in wrapper
    if _apply_rule(f, rule, param, getval) is not None:
  File "/home/devuser/code/myproj/.venv/lib/python3.5/site-packages/stoplight/decorators.py", line 40, in _apply_rule
    resp = rule.vfunc(value)
  File "/home/devuser/code/myproj/.venv/lib/python3.5/site-packages/stoplight/decorators.py", line 173, in wrapper
    func(value)
  File "/home/devuser/code/myproj/myproj_api/api/validation/validators.py", line 39, in validate_id
    raise ValidationFailed('Invalid ID {0}'.format(value))
  File "/home/devuser/code/myproj/.venv/lib/python3.5/site-packages/stoplight/exceptions.py", line 7, in __init__
    msg = msg.format(*args, **kwargs)
ValueError: Single '}' encountered in format string

Applying the following diff can reproduce in the unit tests:

diff --git a/stoplight/tests/test_validation.py b/stoplight/tests/test_validation.py
index 6fb6121..0b78c76 100644
--- a/stoplight/tests/test_validation.py
+++ b/stoplight/tests/test_validation.py
@@ -347,7 +347,8 @@ class TestValidationDecorator(TestCase):
         negative_cases = [
             'z', 'y', 'z',
             'ww', 'vv', 'uu',
-            'serial', 'cereal', 'surreal'
+            'serial', 'cereal', 'surreal',
+            '\}', '\{'
         ]
 
         for case in positive_cases:

as demonstrated with tox here:

bmeyer@bmeyer:~/Development/other/stoplight$ tox -e py27
GLOB sdist-make: /home/bmeyer/Development/other/stoplight/setup.py
py27 inst-nodeps: /home/bmeyer/Development/other/stoplight/.tox/dist/stoplight-1.2.0.zip
py27 installed: coverage==4.5.1,extras==1.0.0,fixtures==3.0.0,linecache2==1.0.0,nose==1.3.7,pbr==4.0.1,pep8==1.7.1,python-mimeparse==1.6.0,six==1.11.0,stoplight==1.2.0,testtools==2.3.0,traceback2==1.4.0,unittest2==1.1.0
py27 runtests: PYTHONHASHSEED='1507695569'
py27 runtests: commands[0] | nosetests
ERROR: Dispatch function threw an exception.Bad callbackERROR: Dispatch function threw an exception.Bad callbackERROR: Dispatch function threw an exception.Bad callback.....F.......
======================================================================
FAIL: test_function_style_validation (stoplight.tests.test_validation.TestValidationDecorator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bmeyer/Development/other/stoplight/stoplight/tests/test_validation.py", line 359, in test_function_style_validation
    FunctionValidation(case)
AssertionError: RuntimeError not raised

Name                                 Stmts   Miss Branch BrPart  Cover
----------------------------------------------------------------------
stoplight/__init__.py                   62      0      4      0   100%
stoplight/decorators.py                 87      0     30      0   100%
stoplight/exceptions.py                  8      0      0      0   100%
stoplight/rule.py                       21      0      2      0   100%
stoplight/tests/__init__.py              0      0      0      0   100%
stoplight/tests/test_validation.py     284    284     47      0     0%
----------------------------------------------------------------------
TOTAL                                  462    284     83      0    39%
nose.plugins.cover: ERROR: TOTAL Coverage did not reach minimum required: 100%
ERROR: InvocationError: '/home/bmeyer/Development/other/stoplight/.tox/py27/bin/nosetests'
_________________________________________________________________________________ summary __________________________________________________________________________________
ERROR:   py27: commands failed

NOTE: I used py27 as an easy example, but it fails with the other Python versions in tox too.

Drop Py3.3 support

Python 3.3 was dropped from official support by Python end of September 2017. We should be able to safely drop our testing against it now too.

setup requires.io to keep track of dependencies

Some of the dependencies have changed and it's good practice to pin them; requires.io provides a nice travis-ci like solution for detecting when dependencies change and then submitting PRs to do so.

DeprecationWarning on Python 3.6 + pytest 4.1.1

Snipped pytest output when trying to validate rules:

/path/to/my/venv/lib/python3.6/site-packages/stoplight/decorators.py:101: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
    funcparams = inspect.getargspec(f)

and

/path/to/my/venv/lib/python3.6/site-packages/stoplight/rule.py:47: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
    if inspect.getargspec(self.errfunc).args == []:

Per the Python 3.6 docs:

Deprecated since version 3.0: Use getfullargspec() for an updated API that is usually a drop-in replacement, but also correctly handles function annotations and keyword-only parameters.

Updates

  • update for newer versions of Python
    • tox tests need newer versions
    • can no longer import Sequence from collections, need to migrate to a newer API

Provide some standardized validators for common functionality

Adding stoplight to another project, and it seems it would be good to do one of the following:

  1. Have stoplight provide some built-in validators
  2. Provide an add-on library (f.e stoplight-rules) for some built-in validators

The primary purpose is to enable having some various pre-defined rules for well known types that people can just use instead of having to figure out how to do it. Some example types that should be covered as a starting point:

  • int (signed, unsigned)
  • floating point
  • UUID
  • boolean (string, numeric)
  • generic string (perhaps with length specified?)

Some of these may require adding bounds (length, min/max, etc) as configuration/parameters to the provided rules.

NOTE: This is in comparison to other libraries like voluptuous which provide extensive Schema support; voluptuous relies on type-casting thus enabling the Python VM to be cracked via the isinstance and other type-casting methods.

Cleanup Tests

Currently, the tests are in one file and are a bit of a mess. The tests should be broken into different files.

Pass ValidationFailure exceptions to error handlers

Currently, error handlers have no context or idea as to why a validation actually failed. Expose the underlying ValidationFailed exception to the error handler in a clever way without breaking existing users.

Submit to Pypi.

Submit to PyPi so that it can be easily installed via pip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.