|
35 | 35 | builder.validate.when.called_with({'MyAddress': 1234}).should.throw(pjs.ValidationError)
|
36 | 36 | builder.validate.when.called_with({'MyAddress': '1234'}).should_not.throw(pjs.ValidationError)
|
37 | 37 |
|
38 |
| - |
39 | 38 | it 'should be able to read an object':
|
40 | 39 | for nm, ex in self.examples.iteritems():
|
41 | 40 | builder = pjs.ObjectBuilder(ex, resolved=self.examples)
|
42 | 41 | builder.should.be.ok
|
43 | 42 |
|
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) |
47 | 50 | 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) |
50 | 75 |
|
51 | 76 | context 'PersonExample':
|
52 | 77 | before_each:
|
|
66 | 91 | int(person.age).should.equal(35)
|
67 | 92 | person.should.be.ok
|
68 | 93 |
|
| 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 | + |
69 | 99 | it 'should validate enumerations':
|
70 | 100 | person = self.Person()
|
71 | 101 |
|
|
0 commit comments