class ProductDocument(Document): _all = Field(enable=False) name = Field('test_name', String(), fields={'raw': Field(String)}) status = Field(Integer) group = Field(Object(GroupDocument)) price = Field(Float) tags = Field(List(Object(TagDocument))) date_created = Field(Date) unused = Field(String) __dynamic_fields__ = [ Field('i_attr_*', Integer), Field('b_attr_*', Boolean), ]
class CarDocument(Document): __doc_type__ = 'car' vendor = Field(String) model = Field(String) year = Field(Integer) seller = Field(Object(CarSellerDocument))
class ProductDocument(Document): __doc_type__ = 'product' __mapping_options__ = { 'dynamic': False, 'date_detection': False, } _routing = Field(required=True, path='company_id') _all = Field(enabled=False) name = Field( String, fields={ 'autocomplete': Field( String, analyzer='ngrams', search_analyzer='text_delimit', norms={'enabled': False} ) } ) company_id = Field(Integer) group = Field(Object(ProductGroupSubDocument)) popularity = Field(Float, doc_values=True) __dynamic_fields__ = [ Field('attr_*', Integer) ]
def test_from_python__is_none(self): # self.assertIsNone(String().from_python(None)) self.assertIsNone(Byte().from_python(None)) self.assertIsNone(Short().from_python(None)) self.assertIsNone(Integer().from_python(None)) self.assertIsNone(Long().from_python(None)) self.assertIsNone(Float().from_python(None)) self.assertIsNone(Double().from_python(None)) # self.assertIsNone(Date().from_python(None)) # self.assertIsNone(Boolean().from_python(None)) # self.assertIsNone(Binary().from_python(None)) self.assertIsNone(Ip().from_python(None)) self.assertIsNone(Object(DynamicDocument).from_python(None)) # self.assertIsNone(Nested().to_python(None)) # self.assertIsNone(List(String).from_python(None)) self.assertIsNone(GeoPoint().from_python(None)) self.assertIsNone(Completion().from_python(None))
class CarSellerDocument(Document): name = Field(Object(NameDocument)) rating = Field(Float)
class TagDocument(Document): id = Field(Integer) name = Field(String) group = Field(Object(GroupDocument))
def test_object(self): t = Object(DynamicDocument) self.assertIs(t.to_python(None), None) doc = t.to_python({'name': 'Test', 'status': 1}) self.assertEqual(doc.name, 'Test') self.assertEqual(doc.status, 1)