# Path: turbo/model.py
# class BaseModel(BaseBaseModel):
#     """Business model
#     """
# 
#     @classmethod
#     def create_model(cls, name, field=None):
#         """dynamic create new model
#         :args field table field, if field is None or {}, this model can not use create method
#         """
#         if field:
#             attrs = {'name': name, 'field': field}
#         else:
#             attrs = {'name': name, 'field': {'_id': ObjectId()}}
# 
#         return type(str(name), (cls, ), attrs)()
# 
# Path: turbo/util.py
# PY3 = sys.version_info >= (3,)
# _UTF8_TYPES = (bytes, type(None))
# _BASESTRING_TYPES = (basestring_type, type(None))
# def to_list_str(value, encode=None):
# def to_dict_str(origin_value, encode=None):
# def default_encode(v):
# def to_str(v, encode=None):
# def format_time(dt):
# def to_objectid(objid):
# def json_encode(data, **kwargs):
# def json_decode(data, **kwargs):
# def to_int(value, default=None):
# def to_float(value, default=None):
# def to_datetime(t, micro=False):
# def to_time(t, micro=False):
#     def __init__(self, module):
#     def __getattr__(self, name):
# def get_base_dir(currfile, dir_level_num=3):
# def join_sys_path(currfile, dir_level_num=3):
# def import_object(name, package_space=None):
# def camel_to_underscore(name):
# def remove_folder(path, foldername):
# def remove_file(path, filename):
# def remove_extension(path, extension):
# def build_index(model_list):
# def utf8(value):
# def to_basestring(value):
# def get_func_name(func):
# class Escape(object):


import datetime
import json
import gridfs
from bson.objectid import ObjectId
from pymongo import MongoClient
from turbo.model import BaseModel
from turbo.util import PY3, basestring_type as basestring, utf8
from util import unittest, fake_ids, fake_ids_2
    from io import StringIO
    from cStringIO import StringIO
    def test_to_objectid(self):
        self.assertTrue(self.tb_tag.to_objectid(None) is None)
        self.assertEqual(self.tb_tag.to_objectid('52c8fb6f1d41c820f1124350'),
                         ObjectId('52c8fb6f1d41c820f1124350'), 'to_objectid is fail')

    def test_create_model(self):
        self.assertEqual(self.tb_tag.create_model(
            'tag').find_one() is not None, True)

    def test_pymongo_collection_method(self):
        self.assertEqual(self.tb_tag.full_name, 'test.tag')

    def test_sub_collection(self):
        self.assertEqual(self.tb_tag.sub_collection(
            'test').full_name, 'test.tag.test')

    def test_inc(self):
        for index, i in enumerate(self.tb_tag.find_by_id(fake_ids[0:3])):
            self.assertEqual(i['value'], index)

        self.tb_tag.inc(
            {'_id': {'$in': fake_ids[0:3]}}, 'value', 1, multi=True)
        for index, i in enumerate(self.tb_tag.find_by_id(fake_ids[0:3])):
            self.assertEqual(i['value'], index + 1)

        self.tb_tag.inc({'_id': fake_ids[4]}, 'value', 1)
        self.assertEqual(self.tb_tag.find_by_id(fake_ids[4])['value'], 5)

    def test_to_str(self):
        one = self.tb_tag.to_str(self.tb_tag.find(limit=10))

# Path: turbo/model.py
# class BaseModel(BaseBaseModel):
#     """Business model
#     """
# 
#     @classmethod
#     def create_model(cls, name, field=None):
#         """dynamic create new model
#         :args field table field, if field is None or {}, this model can not use create method
#         """
#         if field:
#             attrs = {'name': name, 'field': field}
#         else:
#             attrs = {'name': name, 'field': {'_id': ObjectId()}}
# 
#         return type(str(name), (cls, ), attrs)()
# 
# Path: turbo/util.py
# PY3 = sys.version_info >= (3,)
# _UTF8_TYPES = (bytes, type(None))
# _BASESTRING_TYPES = (basestring_type, type(None))
# def to_list_str(value, encode=None):
# def to_dict_str(origin_value, encode=None):
# def default_encode(v):
# def to_str(v, encode=None):
# def format_time(dt):
# def to_objectid(objid):
# def json_encode(data, **kwargs):
# def json_decode(data, **kwargs):
# def to_int(value, default=None):
# def to_float(value, default=None):
# def to_datetime(t, micro=False):
# def to_time(t, micro=False):
#     def __init__(self, module):
#     def __getattr__(self, name):
# def get_base_dir(currfile, dir_level_num=3):
# def join_sys_path(currfile, dir_level_num=3):
# def import_object(name, package_space=None):
# def camel_to_underscore(name):
# def remove_folder(path, foldername):
# def remove_file(path, filename):
# def remove_extension(path, extension):
# def build_index(model_list):
# def utf8(value):
# def to_basestring(value):
# def get_func_name(func):
# class Escape(object):


# Path: tests/model_test.py
import datetime
import json
import gridfs
from bson.objectid import ObjectId
from pymongo import MongoClient
from turbo.model import BaseModel
from turbo.util import PY3, basestring_type as basestring, utf8
from util import unittest, fake_ids, fake_ids_2
    from io import StringIO
    from cStringIO import StringIO

    def test_to_objectid(self):
        self.assertTrue(self.tb_tag.to_objectid(None) is None)
        self.assertEqual(self.tb_tag.to_objectid('52c8fb6f1d41c820f1124350'),
                         ObjectId('52c8fb6f1d41c820f1124350'), 'to_objectid is fail')

    def test_create_model(self):
        self.assertEqual(self.tb_tag.create_model(
            'tag').find_one() is not None, True)

    def test_pymongo_collection_method(self):
        self.assertEqual(self.tb_tag.full_name, 'test.tag')

    def test_sub_collection(self):
        self.assertEqual(self.tb_tag.sub_collection(
            'test').full_name, 'test.tag.test')

    def test_inc(self):
        for index, i in enumerate(self.tb_tag.find_by_id(fake_ids[0:3])):
            self.assertEqual(i['value'], index)

        self.tb_tag.inc(
            {'_id': {'$in': fake_ids[0:3]}}, 'value', 1, multi=True)
        for index, i in enumerate(self.tb_tag.find_by_id(fake_ids[0:3])):
            self.assertEqual(i['value'], index + 1)

        self.tb_tag.inc({'_id': fake_ids[4]}, 'value', 1)
        self.assertEqual(self.tb_tag.find_by_id(fake_ids[4])['value'], 5)

    def test_to_str(self):
        one = self.tb_tag.to_str(self.tb_tag.find(limit=10))

        self.assertTrue(isinstance(json.dumps(one), basestring))