# Path: about_me/models.py
# class Message(models.Model):
#     name = models.CharField(max_length=40)
#     email = models.CharField(max_length=150)
#     content = models.TextField(null=False)
# 
#     def __str__(self):
#         return self.name
# 
# Path: jellyblog/models.py
# class Category(models.Model):
#     id = models.AutoField(primary_key=True)
#     parent = models.ForeignKey('self')
#     name = models.CharField(max_length=20)
# 
#     def __init__(self, *args, **kwargs):
#         super(Category, self).__init__(*args, **kwargs)
#         self.children = []
# 
#     def __str__(self):
#         return self.name
# 
#     @classmethod
#     def sorted_category(cls):
#         return_category = list(cls.objects.all())
#         childList = []
#         for category in return_category:
#             if (category.parent.id == 1):
#                 continue
#             else:
#                 parent_index = return_category.index(category.parent)
#                 return_category[parent_index].children.append(category)
#                 childList.append(category)
# 
#         for child in childList:
#             return_category.remove(child)
# 
#         return return_category
# 
#     @classmethod
#     def init_category(cls):
#         is_empty = cls.objects.count() == 0
#         if is_empty:
#             with connection.cursor() as cs:
#                 cs.execute('INSERT INTO jellyblog_category \
#                              (name, parent_id) VALUES ("Home", 1)')
# 
# class Document(models.Model):
#     # 문서 Model
#     def __str__(self):
#         return self.title
# 
#     id = models.AutoField(primary_key=True)
#     category = models.ForeignKey(Category)
#     title = models.CharField(max_length=100)
#     content = models.TextField()
#     time = models.DateTimeField(auto_now_add=True)
#     meta_tag = models.CharField(max_length=150)
#     view_count = models.IntegerField(default=0, editable=False)
#     public_doc = models.BooleanField()
#     thumbnail = models.ImageField(null=True, upload_to="thumnail_img/")
#     update_time = models.DateTimeField(auto_now=True)
#     is_markdown = models.BooleanField()
#     linebreaks = models.BooleanField()
# 
#     def read(self):
#         self.view_count += 1
#         self.save()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'detail', (), {'document_id': self.id}
# 
#     @classmethod
#     def search_document(cls, query):
#         if len(query) == 0:
#             return None
#         return cls.objects.filter((
#             Q(title__icontains=query) | Q(content__icontains=query))
#             & Q(public_doc=True))
# 
# Path: jellyblog/views.py
# def init_category():
#     Category.init_category()


from django.test.testcases import LiveServerTestCase
from selenium import webdriver
from about_me.models import Message
from jellyblog.models import Category, Document
from jellyblog.views import init_category

        content = self.browser.find_element_by_name('content')
        content.send_keys(self.test_content)

        self.browser.find_element_by_tag_name('form').submit()
        # Message가 서버에 저장된다.
        # 다시 about me page로 돌아온다.
        self.assertIn('젤리의 망상 - About me', self.browser.title)

        ## Message가 저장되었는지 확인
        message = Message.objects.get(
            name=self.test_name,
            email=self.test_email,
            content=self.test_content
        )
        self.assertTrue(message)


class SearchTest(LiveServerTestCase):
    def setUp(self):
        init_category()
        category = Category.objects.get(name="Home")
        self.searchTestDoc1 = Document.objects.create(
            category=category,
            title="Document Search Test Document",
            content="Search Document Content1 It Would Be Found",
            meta_tag="searchsearchesarchesarchsearch",
            public_doc=True
        )


# Path: about_me/models.py
# class Message(models.Model):
#     name = models.CharField(max_length=40)
#     email = models.CharField(max_length=150)
#     content = models.TextField(null=False)
# 
#     def __str__(self):
#         return self.name
# 
# Path: jellyblog/models.py
# class Category(models.Model):
#     id = models.AutoField(primary_key=True)
#     parent = models.ForeignKey('self')
#     name = models.CharField(max_length=20)
# 
#     def __init__(self, *args, **kwargs):
#         super(Category, self).__init__(*args, **kwargs)
#         self.children = []
# 
#     def __str__(self):
#         return self.name
# 
#     @classmethod
#     def sorted_category(cls):
#         return_category = list(cls.objects.all())
#         childList = []
#         for category in return_category:
#             if (category.parent.id == 1):
#                 continue
#             else:
#                 parent_index = return_category.index(category.parent)
#                 return_category[parent_index].children.append(category)
#                 childList.append(category)
# 
#         for child in childList:
#             return_category.remove(child)
# 
#         return return_category
# 
#     @classmethod
#     def init_category(cls):
#         is_empty = cls.objects.count() == 0
#         if is_empty:
#             with connection.cursor() as cs:
#                 cs.execute('INSERT INTO jellyblog_category \
#                              (name, parent_id) VALUES ("Home", 1)')
# 
# class Document(models.Model):
#     # 문서 Model
#     def __str__(self):
#         return self.title
# 
#     id = models.AutoField(primary_key=True)
#     category = models.ForeignKey(Category)
#     title = models.CharField(max_length=100)
#     content = models.TextField()
#     time = models.DateTimeField(auto_now_add=True)
#     meta_tag = models.CharField(max_length=150)
#     view_count = models.IntegerField(default=0, editable=False)
#     public_doc = models.BooleanField()
#     thumbnail = models.ImageField(null=True, upload_to="thumnail_img/")
#     update_time = models.DateTimeField(auto_now=True)
#     is_markdown = models.BooleanField()
#     linebreaks = models.BooleanField()
# 
#     def read(self):
#         self.view_count += 1
#         self.save()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'detail', (), {'document_id': self.id}
# 
#     @classmethod
#     def search_document(cls, query):
#         if len(query) == 0:
#             return None
#         return cls.objects.filter((
#             Q(title__icontains=query) | Q(content__icontains=query))
#             & Q(public_doc=True))
# 
# Path: jellyblog/views.py
# def init_category():
#     Category.init_category()


# Path: functional_test/tests.py
from django.test.testcases import LiveServerTestCase
from selenium import webdriver
from about_me.models import Message
from jellyblog.models import Category, Document
from jellyblog.views import init_category


        content = self.browser.find_element_by_name('content')
        content.send_keys(self.test_content)

        self.browser.find_element_by_tag_name('form').submit()
        # Message가 서버에 저장된다.
        # 다시 about me page로 돌아온다.
        self.assertIn('젤리의 망상 - About me', self.browser.title)

        ## Message가 저장되었는지 확인
        message = Message.objects.get(
            name=self.test_name,
            email=self.test_email,
            content=self.test_content
        )
        self.assertTrue(message)


class SearchTest(LiveServerTestCase):
    def setUp(self):
        init_category()
        category = Category.objects.get(name="Home")
        self.searchTestDoc1 = Document.objects.create(
            category=category,
            title="Document Search Test Document",
            content="Search Document Content1 It Would Be Found",
            meta_tag="searchsearchesarchesarchsearch",
            public_doc=True
        )


        self.notFoundDoc1 = Document.objects.create(