Esempio n. 1
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanotestdb'):
     foo = Field(str)
     bar = Field(datetime.datetime, auto_update=True)
     moo = Field(int, required=False)
Esempio n. 2
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanotestdb'):
     foo = Field(list)
     bar = Field(dict)
     moo = Field(str)
Esempio n. 3
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanotestdb'):
     foo = Field(str)
     bar = Field(int, required=False)
     moo = Field(list)
Esempio n. 4
0
 class Doc(BaseDocument):
     foo = Field(str)
     bar = Field(int)
     __indexes__ = [
         Index('foo.fail'),
         Index([('foo.fail', pymongo.ASCENDING),
                ('bar.fail', pymongo.ASCENDING)]),
     ]
Esempio n. 5
0
 def test_nanomongo_inits(self):
     self.assertRaises(TypeError, Nanomongo, *(1, ))
     self.assertRaises(TypeError, Nanomongo, **{'foo': 'bar'})
     self.assertRaises(TypeError, Nanomongo, **{'fields': 'bar'})
     self.assertRaises(TypeError, Nanomongo.from_dicts)
     self.assertRaises(TypeError, Nanomongo.from_dicts, *(1, ))
     fields_1 = {'foo': Field(str)}
     fields_2 = {'foo': Field(str), 'bar': Field(int)}
     nano_1 = Nanomongo(fields=fields_1)
     nano_2 = Nanomongo.from_dicts(fields_1, fields_2)
     self.assertEqual(['foo'], nano_1.list_fields())
     self.assertEqual(['bar', 'foo'], nano_2.list_fields())
Esempio n. 6
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanotestdb'):
     foo = Field(str)
     bar = Field(int)
     __indexes__ = [
         Index('foo'),
         Index([('bar', pymongo.ASCENDING),
                ('foo', pymongo.DESCENDING)],
               unique=True),
     ]
Esempio n. 7
0
 class Doc4(BaseDocument):
     # test indexes on dotted keys
     foo = Field(list)
     bar = Field(dict)
     __indexes__ = [
         Index('bar.moo'),
         # compund on two embedded document fields
         Index([('bar.moo', pymongo.ASCENDING),
                ('bar.zoo', pymongo.ASCENDING)]),
         # compound on embedded document field + list element document field
         Index([('bar.moo', pymongo.ASCENDING),
                ('foo.whatever', pymongo.ASCENDING)]),
     ]
Esempio n. 8
0
 class Doc2(Doc, client=client, db='nanotestdb'):
     moo = Field(float)
     __indexes__ = [
         Index('bar'),  # pointless, but index test on superclass field
         Index([('moo', pymongo.DESCENDING),
                ('foo', pymongo.ASCENDING)]),
     ]
Esempio n. 9
0
 def test_field_validators(self):
     """Test some validators"""
     bad_dicts = [
         {'foo.bar': 42}, {'$foo': 42}, {'foo': {'bar.foo': 42}},
         {'foo': {'$bar': 42}},
     ]
     for dct in bad_dicts:
         self.assertRaises(ValidationError, Field(dict).validator, *(dct,))
Esempio n. 10
0
 class Doc2(Doc,
            dot_notation=True,
            client=client,
            db='nanomongotest',
            collection='othercollection'):
     bar = Field(int)
Esempio n. 11
0
 def wrapper():
     Field(*args, **kwargs)
Esempio n. 12
0
 class Doc(BaseDocument, dot_notation=True):
     foo = Field(str)
     bar = Field(int, required=False)
     moo = Field(list)
Esempio n. 13
0
 class Doc(BaseDocument):
     foo = Field(str)
     __indexes__ = [Index('foo')]
Esempio n. 14
0
 class Doc2(Doc, dot_notation=True):
     foo = Field(dict)
     zoo = Field(list)
Esempio n. 15
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=MOTOR_CLIENT,
           db='nanotestdb'):
     foo = Field(str)
     bar = Field(int, required=False)
Esempio n. 16
0
 class Doc3(Doc):
     bar = Field(float)
Esempio n. 17
0
 class NewDoc(Doc):
     foo = Field(dict)
Esempio n. 18
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanomongotest'):
     foo = Field(str)
Esempio n. 19
0
 class Doc(BaseDocument):
     foo = Field()
Esempio n. 20
0
 class Doc(BaseDocument, DotNotationMixin):
     foo = Field(str)
Esempio n. 21
0
 class Doc(BaseDocument):
     foo = Field(str, default=1)
Esempio n. 22
0
 class Doc(BaseDocument):
     nanomongo = Field(int)
Esempio n. 23
0
 def test_good_types(self):
     """Test Field definitions with valid types"""
     types = (bool, int, float, bytes, str, list, dict, datetime.datetime, DBRef, ObjectId)
     [Field(t) for t in types]
Esempio n. 24
0
 class Doc(BaseDocument):
     bool_a, bool_b = Field(bool), Field(bool)
     foo = Field(int, default=42)
     bar = Field(str, default=None, required=False)
Esempio n. 25
0
 class Doc(BaseDocument, dot_notation=True):
     foo = Field(str)
Esempio n. 26
0
 class Doc2(BaseDocument, dot_notation=True):
     optional = Field(dict, required=False)
Esempio n. 27
0
 class Doc(BaseDocument, client=PYMONGO_CLIENT, db='nanotestdb'):
     foo = Field(str)
Esempio n. 28
0
 class Doc2(Doc):
     bar = Field(str, required=False)