Пример #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)
Пример #2
0
###
### The base class
###

class Movie(Model):
    """Simple model that has one StringType member
    """
    id = UUIDType(auto_fill=True)
    title = StringType(max_length=40)
    year = IntType(min_value=1950, max_value=datetime.datetime.now().year)
    personal_thoughts = StringType(max_length=255)

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


### Serialize the schema and the data
m_schema = for_jsonschema(m)
m_data = to_python(m)
print 'M :: ', m_schema
print '\n'

### Rebuild class from schema
m2_cls = from_jsonschema(m_schema)

m2 = m2_cls()
print 'M2:: ', for_jsonschema(m2)
print '\n'
Пример #3
0
###
### The base class
###


class Movie(Model):
    """Simple model that has one StringType member
    """
    id = UUIDType(auto_fill=True)
    title = StringType(max_length=40)
    year = IntType(min_value=1950, max_value=datetime.datetime.now().year)
    personal_thoughts = StringType(max_length=255)


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

### Serialize the schema and the data
m_schema = for_jsonschema(m)
m_data = to_python(m)
print 'M :: ', m_schema
print '\n'

### Rebuild class from schema
m2_cls = from_jsonschema(m_schema)

m2 = m2_cls()
print 'M2:: ', for_jsonschema(m2)
print '\n'