Skip to content

Commit

Permalink
renamed project to pyramlson
Browse files Browse the repository at this point in the history
  • Loading branch information
jenner committed Nov 4, 2015
1 parent a7b9ee1 commit b1cd0eb
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 52 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include *.md *.txt tox.ini docs/Makefile *.rst LICENSE .coveragerc .travis.yml *.ini
recursive-include pyramid_raml *.py *.ini *.json
recursive-include pyramlson *.py *.ini *.json
recursive-include docs *.py *.rst
recursive-include docs/_static *
prune docs/_build
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
``pyramid_raml``
``pyramlson``
==================

.. image:: https://travis-ci.org/jenner/pyramid_raml.png?branch=master
:target: https://travis-ci.org/jenner/pyramid_raml
.. image:: https://travis-ci.org/jenner/pyramlson.png?branch=master
:target: https://travis-ci.org/jenner/pyramlson

Build REST APIs with RAML_ and Pyramid_.
Build JSON REST APIs with RAML_ and Pyramid_.

.. _RAML: http://raml.org/
.. _Pyramid: http://docs.pylonsproject.org/en/latest/docs/pyramid.html
20 changes: 10 additions & 10 deletions pyramid_raml/__init__.py → pyramlson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,22 @@ def includeme(config):
.. code-block:: python
:linenos:
config = Configurator()
config.include('pyramid_raml')
config.include('pyramlson')
"""
from pyramid_raml.apidef import RamlApiDefinition, IRamlApiDefinition
from pyramlson.apidef import RamlApiDefinition, IRamlApiDefinition
settings = config.registry.settings
settings['pyramid_raml.debug'] = \
settings['pyramlson.debug'] = \
settings.get('debug_all') or \
settings.get('pyramid.debug_all') or \
settings.get('pyramid_raml.debug')
config.add_view('pyramid_raml.error.generic', context=Exception, renderer='json')
config.add_view('pyramid_raml.error.http_error', context=IExceptionResponse, renderer='json')
config.add_notfound_view('pyramid_raml.error.notfound', renderer='json')
config.add_forbidden_view('pyramid_raml.error.forbidden', renderer='json')
settings.get('pyramlson.debug')
config.add_view('pyramlson.error.generic', context=Exception, renderer='json')
config.add_view('pyramlson.error.http_error', context=IExceptionResponse, renderer='json')
config.add_notfound_view('pyramlson.error.notfound', renderer='json')
config.add_forbidden_view('pyramlson.error.forbidden', renderer='json')

if 'pyramid_raml.apidef_path' not in settings:
if 'pyramlson.apidef_path' not in settings:
raise ValueError("Cannot create RamlApiDefinition without a RAML file.")
apidef = RamlApiDefinition(settings['pyramid_raml.apidef_path'])
apidef = RamlApiDefinition(settings['pyramlson.apidef_path'])
config.registry.registerUtility(apidef, IRamlApiDefinition)


Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions pyramid_raml/error.py → pyramlson/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ def err_dict(message):

def generic(context, request):
log.error("error.generic -- context: \"{}\"".format(context))
tb = ''.join(traceback.format_exception(*request.exc_info))
log.error("error.generic -- traceback: \"{}\"".format(tb))
request.response.status_int = 500
try:
response = err_dict(context.args[0])
except IndexError:
response = err_dict('Unknown error')
if request.registry.settings.get('pyramid_raml.debug'):
response['traceback'] = ''.join(
traceback.format_exception(*request.exc_info))
if request.registry.settings.get('pyramlson.debug'):
response['traceback'] = tb
return response


Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ zip_ok = false

[nosetests]
match=^test
nocapture=1
cover-package=pyramid_raml
verbosity=3
nocapture=0
cover-package=pyramlson
cover-erase=1

[aliases]
dev = develop easy_install pyramid_raml[testing]
docs = develop easy_install pyramid_raml[docs]
dev = develop easy_install pyramlson[testing]
docs = develop easy_install pyramlson[docs]

[bdist_wheel]
universal = 1
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
'coverage',
]

setup(name='pyramid_raml',
setup(name='pyramlson',
version='1.0.0',
description='pyramid_raml',
description='pyramlson',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
Expand All @@ -40,8 +40,8 @@
],
author='Igor Stroh',
author_email='[email protected]',
url='http://github.com/jenner/pyramid_raml',
keywords='web pyramid api',
url='http://github.com/jenner/pyramlson',
keywords='web pyramid api json',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
Expand All @@ -50,5 +50,5 @@
extras_require = {
'testing': testing_extras,
},
test_suite="pyramid_raml",
test_suite="pyramlson",
)
2 changes: 1 addition & 1 deletion tests/bad_resource.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyramid_raml import api_service, api_method
from pyramlson import api_service, api_method

@api_service('/books')
class BadResource(object):
Expand Down
2 changes: 1 addition & 1 deletion tests/error_resource.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyramid_raml import api_service, api_method
from pyramlson import api_service, api_method

@api_service('/foo')
class ErrorsResource(object):
Expand Down
22 changes: 21 additions & 1 deletion tests/resource.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
from collections import OrderedDict
from lxml import objectify

from pyramid.httpexceptions import HTTPNotFound
from pyramid.security import (
Allow,
ALL_PERMISSIONS,
DENY_ALL,
)

from pyramid_raml import api_service, api_method
from pyramlson import api_service, api_method


class Book(object):
""" A simcple book class """

def __init__(self, id, title, author, isbn=None):
self.id = id
self.title = title
self.author = author
selfisbn = isbn

@classmethod
def from_dict(klass, id, data):
return klass(id, data['title'], data['author'], data.get('isbn', None))

@classmethod
def from_etree(klass, id, tree):
return klass(id, data['title'], data['author'], data.get('isbn', None))

BOOKS = OrderedDict()
BOOKS[123] = {"id": 123,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_apidef.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pyramid import testing

from pyramid_raml import apidef
from pyramlson import apidef

from .base import DATA_DIR

Expand Down Expand Up @@ -64,7 +64,7 @@ def test_empty_traits():

class TestMissingRaml(unittest.TestCase):
def test_missing_raml(self):
# not providing a path to RAML specs file in settings['pyramid_raml.apidef_path']
# not providing a path to RAML specs file in settings['pyramlson.apidef_path']
# must raise a ValueError
config = testing.setUp()
self.assertRaises(ValueError, config.include, 'pyramid_raml')
self.assertRaises(ValueError, config.include, 'pyramlson')
16 changes: 8 additions & 8 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class ErrorsTests(unittest.TestCase):

def setUp(self):
settings = {
'pyramid_raml.apidef_path': os.path.join(DATA_DIR, 'test-api.raml'),
'pyramlson.apidef_path': os.path.join(DATA_DIR, 'test-api.raml'),
}
auth_policy = BasicAuthAuthenticationPolicy(dummy_check, 'TEST REALM')
self.config = testing.setUp(settings=settings)
self.config.set_authorization_policy(ACLAuthorizationPolicy())
self.config.set_authentication_policy(auth_policy)
self.config.include('pyramid_raml')
self.config.include('pyramlson')
self.config.scan('.resource')
from webtest import TestApp
self.testapp = TestApp(self.config.make_wsgi_app())
Expand All @@ -58,11 +58,11 @@ def test_bad_roles(self):
class ErrorsWithDebugTests(unittest.TestCase):
def setUp(self):
settings = {
'pyramid_raml.apidef_path': os.path.join(DATA_DIR, 'test-errors-api.raml'),
'pyramid_raml.debug': 'true',
'pyramlson.apidef_path': os.path.join(DATA_DIR, 'test-errors-api.raml'),
'pyramlson.debug': 'true',
}
self.config = testing.setUp(settings=settings)
self.config.include('pyramid_raml')
self.config.include('pyramlson')
self.config.scan('.error_resource')
from webtest import TestApp
self.testapp = TestApp(self.config.make_wsgi_app())
Expand All @@ -75,11 +75,11 @@ def test_traceback(self):
class UnknownErrorTests(unittest.TestCase):
def setUp(self):
settings = {
'pyramid_raml.apidef_path': os.path.join(DATA_DIR, 'test-errors-api.raml'),
'pyramid_raml.debug': 'true',
'pyramlson.apidef_path': os.path.join(DATA_DIR, 'test-errors-api.raml'),
'pyramlson.debug': 'true',
}
self.config = testing.setUp(settings=settings)
self.config.include('pyramid_raml')
self.config.include('pyramlson')
self.config.scan('.error_resource')
from webtest import TestApp
self.testapp = TestApp(self.config.make_wsgi_app())
Expand Down
31 changes: 25 additions & 6 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@
from .base import DATA_DIR
from .resource import BOOKS

BOOK_XML_TMPL = """\
<?xml version="1.0" encoding="utf-8"?>
<book id="{}">
<author>Foo</author>
<title>Blah</title>
<isbn>123456789</isbn>
</book>
"""


class ResourceFunctionalTests(unittest.TestCase):

def setUp(self):
settings = {
'pyramid_raml.apidef_path': os.path.join(DATA_DIR, 'test-api.raml'),
'pyramid_raml.debug': 'true',
'pyramlson.apidef_path': os.path.join(DATA_DIR, 'test-api.raml'),
'pyramlson.debug': 'true',
}
self.config = testing.setUp(settings=settings)
self.config.include('pyramid_raml')
self.config.include('pyramlson')
self.config.scan('.resource')
from webtest import TestApp
self.testapp = TestApp(self.config.make_wsgi_app())
Expand Down Expand Up @@ -84,13 +93,23 @@ def test_not_accepted_body_mime_type(self):
assert r.json_body['success'] == False
assert "Unsupported body content-type: 'text/plain'" in r.json_body['message']

def test_succesful_put(self):
def test_succesful_json_put(self):
app = self.testapp
book_id = 123
fake_book = {'id': book_id, 'title': 'Foo', 'author': 'Blah'}
r = app.put_json('/api/v1/books/{}'.format(book_id), params=fake_book, status=200)
assert r.json_body['success'] == True

def test_succesful_xml_put(self):
app = self.testapp
book_id = 123
fake_book_xml = BOOK_XML_TMPL.format(book_id)
r = app.put('/api/v1/books/{}'.format(book_id),
params=fake_book_xml,
content_type='application/xml',
status=200)
assert r.json_body['success'] == True

def test_default_options(self):
app = self.testapp
r = app.options('/api/v1/books', status=204)
Expand All @@ -115,10 +134,10 @@ class NoMatchingResourceMethodTests(unittest.TestCase):

def setUp(self):
settings = {
'pyramid_raml.apidef_path': os.path.join(DATA_DIR, 'test-api.raml'),
'pyramlson.apidef_path': os.path.join(DATA_DIR, 'test-api.raml'),
}
self.config = testing.setUp(settings=settings)

def test_valueerror(self):
self.config.include('pyramid_raml')
self.config.include('pyramlson')
self.assertRaises(ValueError, self.config.scan, '.bad_resource')
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ basepython =
py3: python3.4

commands =
pip install pyramid_raml[testing]
pip install pyramlson[testing]
nosetests --with-xunit --xunit-file=nosetests-{envname}.xml --logging-level=INFO {posargs:}

[testenv:py2-cover]
commands =
pip install pyramid_raml[testing]
coverage run --source=pyramid_raml {envbindir}/nosetests
pip install pyramlson[testing]
coverage run --source=pyramlson {envbindir}/nosetests
coverage xml -o coverage-py2.xml
setenv =
COVERAGE_FILE=.coverage.py2

[testenv:py3-cover]
commands =
pip install pyramid_raml[testing]
coverage run --source=pyramid_raml {envbindir}/nosetests
pip install pyramlson[testing]
coverage run --source=pyramlson {envbindir}/nosetests
coverage xml -o coverage-py3.xml
setenv =
COVERAGE_FILE=.coverage.py3
Expand Down

0 comments on commit b1cd0eb

Please sign in to comment.