# Path: tests/data/test_data.py

# 
# 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)


from tests.data.test_data import data, clean_data
from tests.models import Student
# clean_data = sort_it(clean_data, (('lectures','code'),))


# def model_to_json_compact():
def test_model_to_json_compact():
    st = Student(**data)
    st.join_date = data['join_date']
    st.AuthInfo(**data['auth_info'])
    st.Lecturer(**data['lecturer'][0])
    for lct_data in data['lectures']:
        lecture = st.Lectures(**lct_data)
        lecture.NodeInListNode(**lct_data['node_in_list_node'])
        for atd in lct_data['attendance']:
            lecture.Attendance.add(**atd)
        for exam in lct_data['exams']:
            lecture.Exams(**exam)
    # print st.clean_value()
    clean_value = st.clean_value()
    clean_data['timestamp'] = clean_value['timestamp']
    clean_data['updated_at'] = clean_value['updated_at']
    assert clean_data == clean_value


# def test_mode8l_to_json_compact(benchmark):
#     benchmark(model_to_json_compact )



def test_model_to_json_expanded():
    d = data

# Path: tests/data/test_data.py

# 
# 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: tests/test_serialize_model.py
from tests.data.test_data import data, clean_data
from tests.models import Student

# clean_data = sort_it(clean_data, (('lectures','code'),))


# def model_to_json_compact():
def test_model_to_json_compact():
    st = Student(**data)
    st.join_date = data['join_date']
    st.AuthInfo(**data['auth_info'])
    st.Lecturer(**data['lecturer'][0])
    for lct_data in data['lectures']:
        lecture = st.Lectures(**lct_data)
        lecture.NodeInListNode(**lct_data['node_in_list_node'])
        for atd in lct_data['attendance']:
            lecture.Attendance.add(**atd)
        for exam in lct_data['exams']:
            lecture.Exams(**exam)
    # print st.clean_value()
    clean_value = st.clean_value()
    clean_data['timestamp'] = clean_value['timestamp']
    clean_data['updated_at'] = clean_value['updated_at']
    assert clean_data == clean_value


# def test_mode8l_to_json_compact(benchmark):
#     benchmark(model_to_json_compact )



def test_model_to_json_expanded():
    d = data

    s = Student()