Beispiel #1
0
 def test_class_from_jsonschema(self):
     """Tests loading the jsonschema into a Document instance and
     serializing back out to jsonschema via a comparison to the jsonschema
     provided by the test.
     """
     if issubclass(self.klass, SimpleModel):
         there = from_jsonschema(self.jsonschema, self.klass)
         andbackagain = to_jsonschema(there)
         jsonschema = json.loads(andbackagain)
         self.assertDictContainsSubset(self.jsonschema, jsonschema)
Beispiel #2
0
    personal_thoughts = StringType(max_length=255, minimized_field_name="p")
    class Options:
        roles = {
            'owner': blacklist(),
            'public': whitelist('title', 'year'),
        }
        


m = Movie(title='Some Movie',
          year=2011,
          personal_thoughts='It was pretty good')


print 'MOVIE ]', ('-' * 40)
print '    schema ::', to_jsonschema(m)
print '    python ::', to_python(m)
print '      json ::', to_json(m)
print '     owner ::', make_safe_python(Movie, m, 'owner')
print '    public ::', make_safe_json(Movie, m, 'public')
print


#movie_json = m.to_json()
movie_json = make_safe_json(Movie, m, 'owner')
print 'Movie as JSON ]', ('-' * 32)
print '      json ::', movie_json
print


### Reload movie
Beispiel #3
0
                   minimized_field_name="y")
    personal_thoughts = StringType(max_length=255, minimized_field_name="p")

    class Options:
        roles = {
            'owner': blacklist(),
            'public': whitelist('title', 'year'),
        }


m = Movie(title='Some Movie',
          year=2011,
          personal_thoughts='It was pretty good')

print 'MOVIE ]', ('-' * 40)
print '    schema ::', to_jsonschema(m)
print '    python ::', to_python(m)
print '      json ::', to_json(m)
print '     owner ::', make_safe_python(Movie, m, 'owner')
print '    public ::', make_safe_json(Movie, m, 'public')
print

#movie_json = m.to_json()
movie_json = make_safe_json(Movie, m, 'owner')
print 'Movie as JSON ]', ('-' * 32)
print '      json ::', movie_json
print

### Reload movie
movie_data = json.loads(movie_json)
m2 = Movie(**movie_data)
Beispiel #4
0
 def test_class_to_jsonschema(self):
     """Tests whether or not the test jsonschema matches what the test class
     returns for `to_jsonschema()`.
     """
     self.assertDictContainsSubset(self.jsonschema, json.loads(to_jsonschema(self.klass)))