# Path: tests/models/student.py
# class Student(Model):
#     # def __init__(self, **kwargs):
#         # We define model relations in __init__ method, because Python parser raises a NameError
#         # if we refer to a not yet defined class in body of another class.
#         # self.contact_info = ContactInfo()
#         # super(Student, self).__init__(**kwargs)
#     # contact_info = ContactInfo()
# 
#     # def row_level_access(self):
#     #     self.objects = self.objects.filter(user_in=self._context.user['id'],)
# 
# 
#     number = field.String("Student No", index=True)
#     pno = field.String("TC No", index=True)
#     name = field.String("First Name", type='text_tr', index=False)
#     surname = field.String("Last Name", type='text_tr', index=False)
#     join_date = field.Date("Join Date", index=True)
#     bio = field.Text("Biography", index=True)
# 
#     class AuthInfo(Node):
#         username = field.String("Username")
#         email = field.String("Email")
#         password = field.String("Password", index=False)
# 
#     class Lectures(ListNode):
#         name = field.String(type='text_tr')
#         code = field.String(required=False)
#         credit = field.Integer(default=0)
#         role = Role('Role_1', index=True)
# 
#         class NodeInListNode(Node):
#             foo = field.String(index=False)
# 
#         class Exams(ListNode):
#             type = field.String(index=False)
#             date = field.Date(index=False)
#             point = field.Integer(index=False)
# 
#         class Attendance(ListNode):
#             date = field.Date(index=False)
#             hour = field.Integer(index=False)
#             attended = field.Boolean(default=False, index=False)
# 
#     class Lecturer(ListNode):
#         role = Role('Role_2', index=True)
# 
# Path: pyoko/db/connection.py
# class FoundInCache(Exception):
# class NotFound(Exception):
# class PyokoMG(MultiGetPool):
#     def _worker_method(self):
# 
# Path: pyoko/settings.py
# DEFAULT_BUCKET_TYPE = os.environ.get('DEFAULT_BUCKET_TYPE', 'pyoko_models')
# VERSION_LOG_BUCKET_TYPE = os.environ.get('VERSION_LOG_BUCKET_TYPE', 'log_version')
# RIAK_SERVER = os.environ.get('RIAK_SERVER', 'localhost')
# RIAK_PROTOCOL = os.environ.get('RIAK_PROTOCOL', 'http')
# RIAK_PORT = os.environ.get('RIAK_PORT', 8098)
# RIAK_HTTP_PORT = os.environ.get('RIAK_HTTP_PORT', 8098)
# REDIS_SERVER = os.environ.get('REDIS_SERVER', '127.0.0.1:6379')
# REDIS_PASSWORD = os.environ.get('REDIS_PASSWORD', None)
# ENABLE_VERSIONS = os.environ.get('ENABLE_VERSIONS', 'False') == 'True'
# VERSION_SUFFIX = os.environ.get('VERSION_SUFFIX', '_version')
# ENABLE_ACTIVITY_LOGGING = os.environ.get('ENABLE_ACTIVITY_LOGGING', 'False') == 'True'
# ACTIVITY_LOGGING_BUCKET = os.environ.get('ACTIVITY_LOGGING_BUCKET', 'log')
# VERSION_BUCKET = os.environ.get('VERSION_BUCKET', 'version')
# ENABLE_CACHING = os.environ.get('ENABLE_CACHING', 'False') == 'True'
# CACHE_EXPIRE_DURATION = os.environ.get('CACHE_EXPIRE_DURATION', 36000)


from tests.models import Student
from pyoko.db.connection import cache
from pyoko import settings
import json
import six
        if settings.ENABLE_CACHING:
            s = Student().blocking_save()

            cached_value = ""
            clean_value = s._data

            try:
                cached_value = cache.get(s.key)
            except:
                pass

            if six.PY3:
                cached_value = cached_value.decode()

            cached_value_d = json.loads(cached_value)

            for key in cached_value_d.keys():
                assert cached_value_d[key] == clean_value[key]


            # To make sure the data is read from cache while key is in it
            try:
                cache.set(s.key, "a")
                assert Student.objects.get(s.key) == "a"
            except:
                pass

            s.blocking_delete()

            try:

# Path: tests/models/student.py
# class Student(Model):
#     # def __init__(self, **kwargs):
#         # We define model relations in __init__ method, because Python parser raises a NameError
#         # if we refer to a not yet defined class in body of another class.
#         # self.contact_info = ContactInfo()
#         # super(Student, self).__init__(**kwargs)
#     # contact_info = ContactInfo()
# 
#     # def row_level_access(self):
#     #     self.objects = self.objects.filter(user_in=self._context.user['id'],)
# 
# 
#     number = field.String("Student No", index=True)
#     pno = field.String("TC No", index=True)
#     name = field.String("First Name", type='text_tr', index=False)
#     surname = field.String("Last Name", type='text_tr', index=False)
#     join_date = field.Date("Join Date", index=True)
#     bio = field.Text("Biography", index=True)
# 
#     class AuthInfo(Node):
#         username = field.String("Username")
#         email = field.String("Email")
#         password = field.String("Password", index=False)
# 
#     class Lectures(ListNode):
#         name = field.String(type='text_tr')
#         code = field.String(required=False)
#         credit = field.Integer(default=0)
#         role = Role('Role_1', index=True)
# 
#         class NodeInListNode(Node):
#             foo = field.String(index=False)
# 
#         class Exams(ListNode):
#             type = field.String(index=False)
#             date = field.Date(index=False)
#             point = field.Integer(index=False)
# 
#         class Attendance(ListNode):
#             date = field.Date(index=False)
#             hour = field.Integer(index=False)
#             attended = field.Boolean(default=False, index=False)
# 
#     class Lecturer(ListNode):
#         role = Role('Role_2', index=True)
# 
# Path: pyoko/db/connection.py
# class FoundInCache(Exception):
# class NotFound(Exception):
# class PyokoMG(MultiGetPool):
#     def _worker_method(self):
# 
# Path: pyoko/settings.py
# DEFAULT_BUCKET_TYPE = os.environ.get('DEFAULT_BUCKET_TYPE', 'pyoko_models')
# VERSION_LOG_BUCKET_TYPE = os.environ.get('VERSION_LOG_BUCKET_TYPE', 'log_version')
# RIAK_SERVER = os.environ.get('RIAK_SERVER', 'localhost')
# RIAK_PROTOCOL = os.environ.get('RIAK_PROTOCOL', 'http')
# RIAK_PORT = os.environ.get('RIAK_PORT', 8098)
# RIAK_HTTP_PORT = os.environ.get('RIAK_HTTP_PORT', 8098)
# REDIS_SERVER = os.environ.get('REDIS_SERVER', '127.0.0.1:6379')
# REDIS_PASSWORD = os.environ.get('REDIS_PASSWORD', None)
# ENABLE_VERSIONS = os.environ.get('ENABLE_VERSIONS', 'False') == 'True'
# VERSION_SUFFIX = os.environ.get('VERSION_SUFFIX', '_version')
# ENABLE_ACTIVITY_LOGGING = os.environ.get('ENABLE_ACTIVITY_LOGGING', 'False') == 'True'
# ACTIVITY_LOGGING_BUCKET = os.environ.get('ACTIVITY_LOGGING_BUCKET', 'log')
# VERSION_BUCKET = os.environ.get('VERSION_BUCKET', 'version')
# ENABLE_CACHING = os.environ.get('ENABLE_CACHING', 'False') == 'True'
# CACHE_EXPIRE_DURATION = os.environ.get('CACHE_EXPIRE_DURATION', 36000)


# Path: tests/test_enable_caching_model.py
from tests.models import Student
from pyoko.db.connection import cache
from pyoko import settings
import json
import six

        if settings.ENABLE_CACHING:
            s = Student().blocking_save()

            cached_value = ""
            clean_value = s._data

            try:
                cached_value = cache.get(s.key)
            except:
                pass

            if six.PY3:
                cached_value = cached_value.decode()

            cached_value_d = json.loads(cached_value)

            for key in cached_value_d.keys():
                assert cached_value_d[key] == clean_value[key]


            # To make sure the data is read from cache while key is in it
            try:
                cache.set(s.key, "a")
                assert Student.objects.get(s.key) == "a"
            except:
                pass

            s.blocking_delete()

            try:

                assert not cache.get(s.key)