# Path: lfc/manage/views.py
# def do_transition(request, id):
#     """Processes passed transition for object with passed id.
# 
#     **Parameters:**
# 
#         id
#             The id of the object for which the transition should be done.
# 
#     **Query String:**
# 
#         transition
#             The id of the transition which should be performed.
#     """
#     transition = request.REQUEST.get("transition")
#     try:
#         transition = Transition.objects.get(pk=transition)
#     except Transition.DoesNotExist:
#         pass
#     else:
#         obj = lfc.utils.get_content_object(pk=id)
# 
#         if transition.permission:
#             obj.check_permission(request.user, transition.permission.codename)
# 
#         workflows.utils.do_transition(obj, transition, request.user)
# 
#         # CACHE
#         cache_key_1 = "%s-obj-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, obj.get_absolute_url()[1:])
#         lfc.utils.delete_cache([cache_key_1])
# 
#         # Set publication date
#         if obj.publication_date is None:
#             public_states = [wst.state for wst in WorkflowStatesInformation.objects.filter(public=True)]
#             if obj.get_state() in public_states:
#                 obj.publication_date = datetime.datetime.now()
#                 obj.save()
# 
#         # Add history entry
#         obj.add_history(request, action="Workflow state changes to: %s" % obj.get_state().name)
# 
#     html = (
#         ("#menu", object_menu(request, obj)),
#         ("#navigation", navigation(request, obj)),
#         ("#tabs-inline", object_tabs(request, obj)),
#     )
# 
#     return HttpJsonResponse(
#         content=html,
#         message=_(u"The state has been changed."),
#         tabs=True,
#         content_type="text/plain",
#     )
# 
# Path: lfc/manage/views.py
# def lfc_copy(request, id):
#     """Puts the object with passed id to the clipboard and marks it as copied.
# 
#     **Parameters:**
# 
#         id
#             The id of the object which should be copied to the clipboard
# 
#     **Permission:**
# 
#         add
#     """
#     obj = lfc.utils.get_content_object(pk=id)
#     obj.check_permission(request.user, "add")
# 
#     request.session["clipboard"] = [id]
#     request.session["clipboard_action"] = COPY
# 
#     obj = lfc.utils.get_content_object(pk=id)
# 
#     html = (
#         ("#menu", object_menu(request, obj)),
#     )
# 
#     return return_as_json(html, _(u"The object has been put to the clipboard."))
# 
# Path: lfc/models.py
# class History(models.Model):
#     """
#     Stores some history about a content object.
#     """
#     obj = models.ForeignKey(BaseContent, verbose_name=_(u"Content object"), related_name="content_objects")
#     action = models.CharField(_(u"Action"), max_length=100)
#     user = models.ForeignKey(User, verbose_name=_(u"User"), related_name="user")
#     creation_date = models.DateTimeField(_(u"Creation date"), auto_now_add=True)
# 
#     class Meta:
#         ordering = ("-creation_date", )
# 
# Path: lfc/tests/utils.py
# class RequestFactory(Client):
#     """
#     Class that lets you create mock Request objects for use in testing.
# 
#     Usage:
# 
#     rf = RequestFactory()
#     get_request = rf.get('/hello/')
#     post_request = rf.post('/submit/', {'foo': 'bar'})
# 
#     This class re-uses the django.test.client.Client interface, docs here:
#     http://www.djangoproject.com/documentation/testing/#the-test-client
# 
#     Once you have a request object you can pass it to any view function,
#     just as if that view had been hooked up using a URLconf.
# 
#     """
#     def request(self, **request):
#         """
#         Similar to parent class, but returns the request object as soon as it
#         has created it.
#         """
#         environ = {
#             'HTTP_COOKIE': self.cookies,
#             'PATH_INFO': '/',
#             'QUERY_STRING': '',
#             'REQUEST_METHOD': 'GET',
#             'SCRIPT_NAME': '',
#             'SERVER_NAME': 'testserver',
#             'SERVER_PORT': 80,
#             'SERVER_PROTOCOL': 'HTTP/1.1',
#             'wsgi.input': StringIO(""),
#         }
#         environ.update(self.defaults)
#         environ.update(request)
#         return WSGIRequest(environ)


from django.contrib.auth.models import User
from django.contrib.sessions.backends.file import SessionStore
from django.core.management import call_command
from django.test import TestCase
from lfc.manage.views import do_transition
from lfc.manage.views import lfc_copy
from lfc.models import History
from lfc.tests.utils import RequestFactory
from lfc_page.models import Page
    """
    def setUp(self):
        self.user = User.objects.create(username="admin", is_active=True, is_superuser=True)
        call_command('lfc_init_simple')

        self.p1 = Page.objects.create(title="Page 1", slug="page-1")

    def test_change_workflow_state(self):
        """
        For each change a history object should be created.
        """
        request = RequestFactory().get("/", {"transition": 1})
        request.user = self.user
        request.session = SessionStore()

        do_transition(request, self.p1.id)
        self.assertEqual(History.objects.count(), 1)

        do_transition(request, self.p1.id)
        self.assertEqual(History.objects.count(), 2)

        # Delete content object
        self.p1.delete()

        self.assertEqual(History.objects.count(), 0)

    def test_copy(self):
        """
        Tests the history after an object has been copied.
        """

# Path: lfc/manage/views.py
# def do_transition(request, id):
#     """Processes passed transition for object with passed id.
# 
#     **Parameters:**
# 
#         id
#             The id of the object for which the transition should be done.
# 
#     **Query String:**
# 
#         transition
#             The id of the transition which should be performed.
#     """
#     transition = request.REQUEST.get("transition")
#     try:
#         transition = Transition.objects.get(pk=transition)
#     except Transition.DoesNotExist:
#         pass
#     else:
#         obj = lfc.utils.get_content_object(pk=id)
# 
#         if transition.permission:
#             obj.check_permission(request.user, transition.permission.codename)
# 
#         workflows.utils.do_transition(obj, transition, request.user)
# 
#         # CACHE
#         cache_key_1 = "%s-obj-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, obj.get_absolute_url()[1:])
#         lfc.utils.delete_cache([cache_key_1])
# 
#         # Set publication date
#         if obj.publication_date is None:
#             public_states = [wst.state for wst in WorkflowStatesInformation.objects.filter(public=True)]
#             if obj.get_state() in public_states:
#                 obj.publication_date = datetime.datetime.now()
#                 obj.save()
# 
#         # Add history entry
#         obj.add_history(request, action="Workflow state changes to: %s" % obj.get_state().name)
# 
#     html = (
#         ("#menu", object_menu(request, obj)),
#         ("#navigation", navigation(request, obj)),
#         ("#tabs-inline", object_tabs(request, obj)),
#     )
# 
#     return HttpJsonResponse(
#         content=html,
#         message=_(u"The state has been changed."),
#         tabs=True,
#         content_type="text/plain",
#     )
# 
# Path: lfc/manage/views.py
# def lfc_copy(request, id):
#     """Puts the object with passed id to the clipboard and marks it as copied.
# 
#     **Parameters:**
# 
#         id
#             The id of the object which should be copied to the clipboard
# 
#     **Permission:**
# 
#         add
#     """
#     obj = lfc.utils.get_content_object(pk=id)
#     obj.check_permission(request.user, "add")
# 
#     request.session["clipboard"] = [id]
#     request.session["clipboard_action"] = COPY
# 
#     obj = lfc.utils.get_content_object(pk=id)
# 
#     html = (
#         ("#menu", object_menu(request, obj)),
#     )
# 
#     return return_as_json(html, _(u"The object has been put to the clipboard."))
# 
# Path: lfc/models.py
# class History(models.Model):
#     """
#     Stores some history about a content object.
#     """
#     obj = models.ForeignKey(BaseContent, verbose_name=_(u"Content object"), related_name="content_objects")
#     action = models.CharField(_(u"Action"), max_length=100)
#     user = models.ForeignKey(User, verbose_name=_(u"User"), related_name="user")
#     creation_date = models.DateTimeField(_(u"Creation date"), auto_now_add=True)
# 
#     class Meta:
#         ordering = ("-creation_date", )
# 
# Path: lfc/tests/utils.py
# class RequestFactory(Client):
#     """
#     Class that lets you create mock Request objects for use in testing.
# 
#     Usage:
# 
#     rf = RequestFactory()
#     get_request = rf.get('/hello/')
#     post_request = rf.post('/submit/', {'foo': 'bar'})
# 
#     This class re-uses the django.test.client.Client interface, docs here:
#     http://www.djangoproject.com/documentation/testing/#the-test-client
# 
#     Once you have a request object you can pass it to any view function,
#     just as if that view had been hooked up using a URLconf.
# 
#     """
#     def request(self, **request):
#         """
#         Similar to parent class, but returns the request object as soon as it
#         has created it.
#         """
#         environ = {
#             'HTTP_COOKIE': self.cookies,
#             'PATH_INFO': '/',
#             'QUERY_STRING': '',
#             'REQUEST_METHOD': 'GET',
#             'SCRIPT_NAME': '',
#             'SERVER_NAME': 'testserver',
#             'SERVER_PORT': 80,
#             'SERVER_PROTOCOL': 'HTTP/1.1',
#             'wsgi.input': StringIO(""),
#         }
#         environ.update(self.defaults)
#         environ.update(request)
#         return WSGIRequest(environ)


# Path: lfc/tests/history_tests.py
from django.contrib.auth.models import User
from django.contrib.sessions.backends.file import SessionStore
from django.core.management import call_command
from django.test import TestCase
from lfc.manage.views import do_transition
from lfc.manage.views import lfc_copy
from lfc.models import History
from lfc.tests.utils import RequestFactory
from lfc_page.models import Page

    """
    def setUp(self):
        self.user = User.objects.create(username="admin", is_active=True, is_superuser=True)
        call_command('lfc_init_simple')

        self.p1 = Page.objects.create(title="Page 1", slug="page-1")

    def test_change_workflow_state(self):
        """
        For each change a history object should be created.
        """
        request = RequestFactory().get("/", {"transition": 1})
        request.user = self.user
        request.session = SessionStore()

        do_transition(request, self.p1.id)
        self.assertEqual(History.objects.count(), 1)

        do_transition(request, self.p1.id)
        self.assertEqual(History.objects.count(), 2)

        # Delete content object
        self.p1.delete()

        self.assertEqual(History.objects.count(), 0)

    def test_copy(self):
        """
        Tests the history after an object has been copied.
        """

        request = RequestFactory().get("/", {"transition": 1})