Exemplo 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)
Exemplo n.º 2
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanotestdb'):
     foo = Field(list)
     bar = Field(dict)
     moo = Field(str)
Exemplo n.º 3
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanotestdb'):
     foo = Field(str)
     bar = Field(int, required=False)
     moo = Field(list)
Exemplo 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)]),
     ]
Exemplo 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())
Exemplo 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),
     ]
Exemplo 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)]),
     ]
Exemplo 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)]),
     ]
Exemplo 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,))
Exemplo n.º 10
0
 class Doc2(Doc,
            dot_notation=True,
            client=client,
            db='nanomongotest',
            collection='othercollection'):
     bar = Field(int)
Exemplo n.º 11
0
 def wrapper():
     Field(*args, **kwargs)
Exemplo n.º 12
0
 class Doc(BaseDocument, dot_notation=True):
     foo = Field(str)
     bar = Field(int, required=False)
     moo = Field(list)
Exemplo n.º 13
0
 class Doc(BaseDocument):
     foo = Field(str)
     __indexes__ = [Index('foo')]
Exemplo n.º 14
0
 class Doc2(Doc, dot_notation=True):
     foo = Field(dict)
     zoo = Field(list)
Exemplo n.º 15
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=MOTOR_CLIENT,
           db='nanotestdb'):
     foo = Field(str)
     bar = Field(int, required=False)
Exemplo n.º 16
0
 class Doc3(Doc):
     bar = Field(float)
Exemplo n.º 17
0
 class NewDoc(Doc):
     foo = Field(dict)
Exemplo n.º 18
0
 class Doc(BaseDocument,
           dot_notation=True,
           client=client,
           db='nanomongotest'):
     foo = Field(str)
Exemplo n.º 19
0
 class Doc(BaseDocument):
     foo = Field()
Exemplo n.º 20
0
 class Doc(BaseDocument, DotNotationMixin):
     foo = Field(str)
Exemplo n.º 21
0
 class Doc(BaseDocument):
     foo = Field(str, default=1)
Exemplo n.º 22
0
 class Doc(BaseDocument):
     nanomongo = Field(int)
Exemplo 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]
Exemplo 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)
Exemplo n.º 25
0
 class Doc(BaseDocument, dot_notation=True):
     foo = Field(str)
Exemplo n.º 26
0
 class Doc2(BaseDocument, dot_notation=True):
     optional = Field(dict, required=False)
Exemplo n.º 27
0
 class Doc(BaseDocument, client=PYMONGO_CLIENT, db='nanotestdb'):
     foo = Field(str)
Exemplo n.º 28
0
 class Doc2(Doc):
     bar = Field(str, required=False)