# Path: jellyblog/views.py
# @minified_response
# def index(request):
#     return index_with_page(request, 1)
# 
# @minified_response
# def search_documents(request):
#     form = SearchForm(request.POST)
#     if form.is_valid():
#         documents = Document.search_document(form.cleaned_data['search_query'])
#         context = {
#             'documents': documents,
#             'category_list': Category.sorted_category()
#         }
#         return render(request, 'jellyblog/search_result.html', context)
#     else:
#         return render(request, 'jellyblog/search_result.html')
# 
# def init_category():
#     Category.init_category()
# 
# 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 Note(models.Model):
#     # 노트 Model
#     def __str__(self):
#         return self.content
# 
#     id = models.AutoField(primary_key=True)
#     content = models.CharField(max_length=300)
#     time = models.DateTimeField(auto_now_add=True)
#     update_time = models.DateTimeField(auto_now=True)
# 
# 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))


from django.core.urlresolvers import reverse
from django.http import HttpRequest
from django.test.testcases import LiveServerTestCase
from selenium import webdriver
from jellyblog.views import index, search_documents, init_category
from .models import Category, Note, Document
            content="Content content content",
            meta_tag="metametametametametameta",
            public_doc=True
        )

        self.test_doc2 = Document.objects.create(
            category=category,
            title="Document Test2",
            content="Content2 content2 content2",
            meta_tag="metametametametametameta",
            public_doc=False
        )

    def test_get_document(self):
        request = HttpRequest()
        response = index(request)

        self.assertIn(self.test_doc1.title, response.content.decode())
        self.assertIn(self.test_doc1.content, response.content.decode())

    def test_about_private_doc(self):
        request = HttpRequest()
        response = index(request)
        self.assertNotIn(self.test_doc2.title, response.content.decode())
        self.assertNotIn(self.test_doc2.content, response.content.decode())


class DocumentSearchTest(LiveServerTestCase):
    def setUp(self):
        init_category()

# Path: jellyblog/views.py
# @minified_response
# def index(request):
#     return index_with_page(request, 1)
# 
# @minified_response
# def search_documents(request):
#     form = SearchForm(request.POST)
#     if form.is_valid():
#         documents = Document.search_document(form.cleaned_data['search_query'])
#         context = {
#             'documents': documents,
#             'category_list': Category.sorted_category()
#         }
#         return render(request, 'jellyblog/search_result.html', context)
#     else:
#         return render(request, 'jellyblog/search_result.html')
# 
# def init_category():
#     Category.init_category()
# 
# 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 Note(models.Model):
#     # 노트 Model
#     def __str__(self):
#         return self.content
# 
#     id = models.AutoField(primary_key=True)
#     content = models.CharField(max_length=300)
#     time = models.DateTimeField(auto_now_add=True)
#     update_time = models.DateTimeField(auto_now=True)
# 
# 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/tests.py
from django.core.urlresolvers import reverse
from django.http import HttpRequest
from django.test.testcases import LiveServerTestCase
from selenium import webdriver
from jellyblog.views import index, search_documents, init_category
from .models import Category, Note, Document

            content="Content content content",
            meta_tag="metametametametametameta",
            public_doc=True
        )

        self.test_doc2 = Document.objects.create(
            category=category,
            title="Document Test2",
            content="Content2 content2 content2",
            meta_tag="metametametametametameta",
            public_doc=False
        )

    def test_get_document(self):
        request = HttpRequest()
        response = index(request)

        self.assertIn(self.test_doc1.title, response.content.decode())
        self.assertIn(self.test_doc1.content, response.content.decode())

    def test_about_private_doc(self):
        request = HttpRequest()
        response = index(request)
        self.assertNotIn(self.test_doc2.title, response.content.decode())
        self.assertNotIn(self.test_doc2.content, response.content.decode())


class DocumentSearchTest(LiveServerTestCase):
    def setUp(self):
        init_category()

        category = Category.objects.get(name="Home")