Пример #1
0
 def test_schema_with_dict(self):
     data = {
         '$this.thing': 'that',
         'a.t': {
             'a.b': 'thing',
             'dudeman': {
                 'hello.world': 'nothing',
             }
         },
     }
     list_data = [{'this.thing': 'that'}]
     tmp = SchemaWithDict.create(data=data, list_data=list_data)
     raw = SchemaWithDict.collection.find_one({'_id': tmp.id})
     self.assertTrue('$this.thing' in raw['data'])
     self.assertTrue('a.t' in raw['data'])
     self.assertTrue('a.b' in raw['data']['a.t'])
     self.assertTrue(MongoSchema._unfix_dict_keys(raw['data']) == data)
     self.assertTrue(
         MongoSchema._unfix_dict_keys(raw['list_data']) == list_data)
     self.assertTrue(type(tmp.data) is dict)
     new_data = {
         'hello': 'world',
         'dudeman': {
             'h.w': 'nothing',
         }
     }
     tmp.data = new_data
     tmp.save()
     raw = SchemaWithDict.collection.find_one({'_id': tmp.id})
     self.assertTrue('h.w' in raw['data']['dudeman'])
     self.assertTrue(
         MongoSchema._unfix_dict_keys(raw['data']) == new_data, new_data)
Пример #2
0
 def test_schema_with_dict(self):
     data = {
         '$this.thing': 'that',
         'a.t': {
             'a.b': 'thing',
             'dudeman': {
                 'hello.world': 'nothing',
             }
         },
     }
     list_data = [
         {'this.thing': 'that'}
     ]
     tmp = SchemaWithDict.create(data=data, list_data=list_data)
     raw = SchemaWithDict.collection.find_one({'_id': tmp.id})
     self.assertTrue('$this.thing' in raw['data'])
     self.assertTrue('a.t' in raw['data'])
     self.assertTrue('a.b' in raw['data']['a.t'])
     self.assertTrue(MongoSchema._unfix_dict_keys(raw['data']) == data)
     self.assertTrue(
         MongoSchema._unfix_dict_keys(raw['list_data']) == list_data)
     self.assertTrue(type(tmp.data) is dict)
     new_data = {
         'hello': 'world',
         'dudeman': {
             'h.w': 'nothing',
         }
     }
     tmp.data = new_data
     tmp.save()
     raw = SchemaWithDict.collection.find_one({'_id': tmp.id})
     self.assertTrue('h.w' in raw['data']['dudeman'])
     self.assertTrue(
         MongoSchema._unfix_dict_keys(raw['data']) == new_data, new_data)
Пример #3
0
 def test_schemaless_embeded_doc(self):
     data = {'testing': 'nothing', 'hellow': 'world'}
     doc = EmbedDoc.create(data=data)
     raw_doc = doc.ms.collection.find_one({'_id': doc.id})
     self.assertEqual(MongoSchema._unfix_dict_keys(raw_doc['data']), data)
Пример #4
0
 def test_schemaless_embeded_doc(self):
     data = {'testing': 'nothing', 'hellow': 'world'}
     doc = EmbedDoc.create(data=data)
     raw_doc = doc.ms.collection.find_one({'_id': doc.id})
     self.assertEqual(MongoSchema._unfix_dict_keys(raw_doc['data']), data)