Skip to content

Commit d6d3fa8

Browse files
author
Chris Wacek
committed
Updated license
1 parent 31721f7 commit d6d3fa8

File tree

4 files changed

+62
-21
lines changed

4 files changed

+62
-21
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Chris Wacek
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

setup.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22
# -*- coding: utf-8 -*-
33
# <python_jsonschema_objects - An object wrapper for JSON Schema definitions>
44
# Copyright (C) <2014-2014> Chris Wacek <[email protected]
5-
#
6-
# This library is free software; you can redistribute it and/or
7-
# modify it under the terms of the GNU Lesser General Public
8-
# License as published by the Free Software Foundation; either
9-
# version 2.1 of the License, or (at your option) any later version.
10-
#
11-
# This library is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14-
# Lesser General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU Lesser General Public
17-
# License along with this library; if not, see <http://www.gnu.org/licenses/>
185

196
import ast
207
import os
@@ -73,10 +60,11 @@ def parse_requirements(path):
7360
long_description = ''
7461

7562
setup(name='python_jsonschema_objects',
76-
version='0.0.10',
63+
version='0.0.10.post1',
7764
description='An object wrapper for JSON Schema definitions',
7865
author='Chris Wacek',
7966
long_description=long_description,
67+
license="LICENSE",
8068
author_email='[email protected]',
8169
include_package_data=True,
8270
url='http://github.com/cwacek/python-jsonschema-objects',

test/test.py

+36-6
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,43 @@
3535
builder.validate.when.called_with({'MyAddress': 1234}).should.throw(pjs.ValidationError)
3636
builder.validate.when.called_with({'MyAddress': '1234'}).should_not.throw(pjs.ValidationError)
3737

38-
3938
it 'should be able to read an object':
4039
for nm, ex in self.examples.iteritems():
4140
builder = pjs.ObjectBuilder(ex, resolved=self.examples)
4241
builder.should.be.ok
4342

44-
it 'should be able to build classes':
45-
for nm, ex in self.examples.iteritems():
46-
builder = pjs.ObjectBuilder(self.example, resolved=self.examples)
43+
context "additionalProperties":
44+
45+
before_each:
46+
builder = pjs.ObjectBuilder(self.examples['Example Schema'], resolved=self.examples)
47+
builder.should.be.ok
48+
self.Person = builder.classes['ExampleSchema']
49+
builder = pjs.ObjectBuilder(self.examples['Other'], resolved=self.examples)
4750
builder.should.be.ok
48-
namespace = builder.build_classes()
49-
this(namespace).should.be.ok
51+
self.Other = builder.classes['Other']
52+
53+
it 'should allow additionalProperties by default':
54+
55+
def set_attribute(object):
56+
object.randomAttribute = 4
57+
58+
person = self.Person()
59+
set_attribute.when.called_with(person).should_not.throw(Exception)
60+
61+
int(person.randomAttribute).should.equal(4)
62+
63+
it 'should still raise errors when accessing undefined attributes':
64+
65+
person = self.Person()
66+
#person.should_not.have.property('randomAttribute')
67+
68+
it 'should not allow undefined attributes if false':
69+
70+
def set_attribute(object):
71+
object.randomAttribute = 4
72+
73+
other = self.Other()
74+
set_attribute.when.called_with(other).should.throw(pjs.ValidationError)
5075

5176
context 'PersonExample':
5277
before_each:
@@ -66,6 +91,11 @@
6691
int(person.age).should.equal(35)
6792
person.should.be.ok
6893

94+
it 'should validate when decoding from json':
95+
self.Person.from_json.when.called_with(
96+
'{"firstName":"James"}'
97+
).should.throw(pjs.ValidationError)
98+
6999
it 'should validate enumerations':
70100
person = self.Person()
71101

tox.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ envlist = py27
44

55
[testenv]
66
install_command = pip install --no-compile {opts} {packages}
7-
commands = nosetests --with-noy --rednose -s
7+
commands = coverage run {envbindir}/nosetests --with-noy --rednose -s
8+
coverage html --omit=*test* --include=*python_jsonschema_objects*
89
deps =
910
-rrequirements.txt
1011
nose
12+
coverage
1113
rednose
1214
https://github.com/cwacek/sure/tarball/master
1315
https://github.com/cwacek/nose-of-yeti/tarball/master

0 commit comments

Comments
 (0)