예제 #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
파일: test.py 프로젝트: hershaw/mongoschema
 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_list(self):
     users = []
     for i in range(0, 10):
         users.append(_create_user(username='******' % i))
     MongoSchema.clear_cache_and_init()
     users_from_db = User.list()
     for user in users_from_db:
         self.assertTrue(user in users)
예제 #4
0
파일: test.py 프로젝트: hershaw/mongoschema
 def test_list(self):
     users = []
     for i in range(0, 10):
         users.append(_create_user(username='******' % i))
     MongoSchema.clear_cache_and_init()
     users_from_db = User.list()
     for user in users_from_db:
         self.assertTrue(user in users)
예제 #5
0
 def test_reference_query(self):
     user = _create_user()
     email = self._create_email(user)
     MongoSchema.clear_cache_and_init()
     email_from_query = Email.get(user=user)
     self.assertTrue(email.id == email_from_query.id)
     MongoSchema.clear_cache_and_init()
     email_from_find = [x for x in Email.find(user=user)][0]
     self.assertTrue(email.id == email_from_find.id)
예제 #6
0
파일: test.py 프로젝트: hershaw/mongoschema
 def test_reference_query(self):
     user = _create_user()
     email = self._create_email(user)
     MongoSchema.clear_cache_and_init()
     email_from_query = Email.get(user=user)
     self.assertTrue(email.id == email_from_query.id)
     MongoSchema.clear_cache_and_init()
     email_from_find = [x for x in Email.find(user=user)][0]
     self.assertTrue(email.id == email_from_find.id)
예제 #7
0
 def test_disabled_cache(self):
     MongoSchema.disable_cache()
     user = _create_user()
     user_again = User.get(id=user.id)
     self.assertTrue(user is not user_again)
     MongoSchema.enable_cache()
예제 #8
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)
예제 #9
0
def _setUp():
    conn.drop_database(TEST_DB_NAME)
    MongoSchema.clear_cache_and_init()
예제 #10
0
파일: test.py 프로젝트: hershaw/mongoschema
 def test_disabled_cache(self):
     MongoSchema.disable_cache()
     user = _create_user()
     user_again = User.get(id=user.id)
     self.assertTrue(user is not user_again)
     MongoSchema.enable_cache()
예제 #11
0
파일: test.py 프로젝트: hershaw/mongoschema
 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)
예제 #12
0
파일: test.py 프로젝트: hershaw/mongoschema
def _setUp():
    conn.drop_database(TEST_DB_NAME)
    MongoSchema.clear_cache_and_init()