# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import sys
import django
from django.contrib.auth.models import User
from django.test import TestCase, RequestFactory
from polymorphic_tree.templatetags.stylable_admin_list import *

from django.contrib.admin import AdminSite
from django.contrib.admin.views.main import ChangeList
from polymorphic_tree.tests.admin import BaseChildAdmin, TreeNodeParentAdmin
from polymorphic_tree.tests.models import Model2A, ModelWithCustomParentName, ModelWithInvalidMove, ModelWithValidation


class StylableAdminList(TestCase):
    """
    Test Suite for stylable_admin_list template tag
    """
    request_factory = RequestFactory()

    def test_django_fied_does_not_exists_resource(self):
        """
        Check that FieldDoesNotExist successfully extracted from Django core.
        """
        # self.assertRegex(
        #     repr(FieldDoesNotExist),
        #     r"(<class 'django.db.models.FieldDoesNotExist'>)|(<class 'django.core.exceptions.FieldDoesNotExist'>)"
        # )
        self.assertEqual(True, True)
    
    def setUp(self):
        # self.alfred = User.objects.create_superuser('alfred', '<EMAIL>', 'password')
        # # self.change_list_obj = ChangeList.objects.create()
        # self.simple_model = Model2A.objects.create(field1='A1')
    
        # self.parent = ModelWithCustomParentName.objects.create(field5='parent')
        # self.child1 = ModelWithCustomParentName.objects.create(
        #     field5='child1',
        #     chief=self.parent
        # )
        # self.child2 = ModelWithCustomParentName.objects.create(
        #     field5='child2',
        #     chief=self.parent
        # )
        # self.parent_admin = TreeNodeParentAdmin(ModelWithCustomParentName,
        #                                         AdminSite())

        # # HACK: simulating new django-polymorphic child_models interface
        # #       description of changes in below links:
        # # https://github.com/django-polymorphic/django-polymorphic/blob/b4efb59cd5d6b1ce3e10fdb5c495fbe239d91ad7/docs/admin.rst#fieldset-configuration
        # # https://github.com/django-polymorphic/django-polymorphic/blob/b4efb59cd5d6b1ce3e10fdb5c495fbe239d91ad7/docs/changelog.rst#version-10-2016-09-02 
        # self.parent_admin.child_models = (self.parent_admin.child_models[0][0],)

        # # HACK: using private method & vars for test, can be changed in
        # #       django-polymorphic new versions and broke tests here...
        # self.parent_admin._lazy_setup()
        # self.parent_admin._is_setup = False
        # self.parent_admin.register_child(ModelWithCustomParentName, BaseChildAdmin)
        # self.parent_admin._is_setup = True
        # # END OF HACKS

        # self.parent_with_validation = ModelWithValidation.objects.create(
        #     field6='parent'
        # )
        # self.child1_with_validation = ModelWithValidation.objects.create(
        #     field6='child1',
        #     parent=self.parent_with_validation
        # )
        # self.child2_with_validation = ModelWithValidation.objects.create(
        #     field6='child2',
        #     parent=self.parent_with_validation
        # )

        # self.parent_admin_with_validation = TreeNodeParentAdmin(
        #     ModelWithValidation,
        #     AdminSite()
        # )

        # self.parent_invalid_move = ModelWithInvalidMove.objects.create(
        #     field7='parent'
        # )
        # self.child1_invalid_move = ModelWithInvalidMove.objects.create(
        #     field7='child1',
        #     parent=self.parent_invalid_move
        # )
        # self.child2_invalid_move = ModelWithInvalidMove.objects.create(
        #     field7='child2',
        #     parent=self.parent_invalid_move
        # )

        # self.parent_admin_invalid_move = TreeNodeParentAdmin(
        #     ModelWithInvalidMove,
        #     AdminSite()
        # )
        self.assertEqual(True, True)


    def test_stylable_results(self):
        """
        Check test stylable results obj
        """
        # self.assertEqual(repr(stylable_results(self.parent_admin)).split(' at ')[0], '<generator object stylable_results')
        self.assertEqual(True, True)


    def test_stylable_column_repr(self):
        """
        Check stylable column repr obj
        """
        # request = self.request_factory.get('/', {})
        # request.user = self.alfred 
        # request.POST = {
        #     'moved_id': self.child2.id,
        #     'target_id': self.child1.id,
        #     'previous_parent_id': self.parent.id,
        #     'position': 'inside'
        # }
        # cl = self.parent_admin.get_changelist_instance(request)
        # assert isinstance(cl, ChangeList), "cl variable should be an admin ChangeList"
        # result = cl.result_list[0]
        # field_name = 'field5'  # chief
        # self.assertEqual(repr(stylable_column_repr(cl, result, field_name)), "('parent', None)")
        self.assertEqual(True, True)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import sys
import django
from django.contrib.auth.models import User
from django.test import TestCase, RequestFactory
from polymorphic_tree.templatetags.stylable_admin_list import *

from django.contrib.admin import AdminSite
from django.contrib.admin.views.main import ChangeList
from polymorphic_tree.tests.admin import BaseChildAdmin, TreeNodeParentAdmin
from polymorphic_tree.tests.models import Model2A, ModelWithCustomParentName, ModelWithInvalidMove, ModelWithValidation


class StylableAdminList(TestCase):
    """
    Test Suite for stylable_admin_list template tag
    """
    request_factory = RequestFactory()

    def test_django_fied_does_not_exists_resource(self):
        """
        Check that FieldDoesNotExist successfully extracted from Django core.
        """
        # self.assertRegex(
        #     repr(FieldDoesNotExist),
        #     r"(<class 'django.db.models.FieldDoesNotExist'>)|(<class 'django.core.exceptions.FieldDoesNotExist'>)"
        # )
        self.assertEqual(True, True)
    
    def setUp(self):
        # self.alfred = User.objects.create_superuser('alfred', '<EMAIL>', 'password')
        # # self.change_list_obj = ChangeList.objects.create()
        # self.simple_model = Model2A.objects.create(field1='A1')
    
        # self.parent = ModelWithCustomParentName.objects.create(field5='parent')
        # self.child1 = ModelWithCustomParentName.objects.create(
        #     field5='child1',
        #     chief=self.parent
        # )
        # self.child2 = ModelWithCustomParentName.objects.create(
        #     field5='child2',
        #     chief=self.parent
        # )
        # self.parent_admin = TreeNodeParentAdmin(ModelWithCustomParentName,
        #                                         AdminSite())

        # # HACK: simulating new django-polymorphic child_models interface
        # #       description of changes in below links:
        # # https://github.com/django-polymorphic/django-polymorphic/blob/b4efb59cd5d6b1ce3e10fdb5c495fbe239d91ad7/docs/admin.rst#fieldset-configuration
        # # https://github.com/django-polymorphic/django-polymorphic/blob/b4efb59cd5d6b1ce3e10fdb5c495fbe239d91ad7/docs/changelog.rst#version-10-2016-09-02 
        # self.parent_admin.child_models = (self.parent_admin.child_models[0][0],)

        # # HACK: using private method & vars for test, can be changed in
        # #       django-polymorphic new versions and broke tests here...
        # self.parent_admin._lazy_setup()
        # self.parent_admin._is_setup = False
        # self.parent_admin.register_child(ModelWithCustomParentName, BaseChildAdmin)
        # self.parent_admin._is_setup = True
        # # END OF HACKS

        # self.parent_with_validation = ModelWithValidation.objects.create(
        #     field6='parent'
        # )
        # self.child1_with_validation = ModelWithValidation.objects.create(
        #     field6='child1',
        #     parent=self.parent_with_validation
        # )
        # self.child2_with_validation = ModelWithValidation.objects.create(
        #     field6='child2',
        #     parent=self.parent_with_validation
        # )

        # self.parent_admin_with_validation = TreeNodeParentAdmin(
        #     ModelWithValidation,
        #     AdminSite()
        # )

        # self.parent_invalid_move = ModelWithInvalidMove.objects.create(
        #     field7='parent'
        # )
        # self.child1_invalid_move = ModelWithInvalidMove.objects.create(
        #     field7='child1',
        #     parent=self.parent_invalid_move
        # )
        # self.child2_invalid_move = ModelWithInvalidMove.objects.create(
        #     field7='child2',
        #     parent=self.parent_invalid_move
        # )

        # self.parent_admin_invalid_move = TreeNodeParentAdmin(
        #     ModelWithInvalidMove,
        #     AdminSite()
        # )
        self.assertEqual(True, True)


    def test_stylable_results(self):
        """
        Check test stylable results obj
        """
        # self.assertEqual(repr(stylable_results(self.parent_admin)).split(' at ')[0], '<generator object stylable_results')
        self.assertEqual(True, True)


    def test_stylable_column_repr(self):
        """
        Check stylable column repr obj
        """
        # request = self.request_factory.get('/', {})
        # request.user = self.alfred 
        # request.POST = {
        #     'moved_id': self.child2.id,
        #     'target_id': self.child1.id,
        #     'previous_parent_id': self.parent.id,
        #     'position': 'inside'
        # }
        # cl = self.parent_admin.get_changelist_instance(request)
        # assert isinstance(cl, ChangeList), "cl variable should be an admin ChangeList"
        # result = cl.result_list[0]
        # field_name = 'field5'  # chief
        # self.assertEqual(repr(stylable_column_repr(cl, result, field_name)), "('parent', None)")
        self.assertEqual(True, True)
# -*- coding: utf-8 -*- Test Suite for stylable_admin_list template tag Check that FieldDoesNotExist successfully extracted from Django core. # self.assertRegex( #     repr(FieldDoesNotExist), #     r"(<class 'django.db.models.FieldDoesNotExist'>)|(<class 'django.core.exceptions.FieldDoesNotExist'>)" # ) # self.alfred = User.objects.create_superuser('alfred', '<EMAIL>', 'password') # # self.change_list_obj = ChangeList.objects.create() # self.simple_model = Model2A.objects.create(field1='A1') # self.parent = ModelWithCustomParentName.objects.create(field5='parent') # self.child1 = ModelWithCustomParentName.objects.create( #     field5='child1', #     chief=self.parent # ) # self.child2 = ModelWithCustomParentName.objects.create( #     field5='child2', #     chief=self.parent # ) # self.parent_admin = TreeNodeParentAdmin(ModelWithCustomParentName, #                                         AdminSite()) # # HACK: simulating new django-polymorphic child_models interface # #       description of changes in below links: # # https://github.com/django-polymorphic/django-polymorphic/blob/b4efb59cd5d6b1ce3e10fdb5c495fbe239d91ad7/docs/admin.rst#fieldset-configuration # # https://github.com/django-polymorphic/django-polymorphic/blob/b4efb59cd5d6b1ce3e10fdb5c495fbe239d91ad7/docs/changelog.rst#version-10-2016-09-02 # self.parent_admin.child_models = (self.parent_admin.child_models[0][0],) # # HACK: using private method & vars for test, can be changed in # #       django-polymorphic new versions and broke tests here... # self.parent_admin._lazy_setup() # self.parent_admin._is_setup = False # self.parent_admin.register_child(ModelWithCustomParentName, BaseChildAdmin) # self.parent_admin._is_setup = True # # END OF HACKS # self.parent_with_validation = ModelWithValidation.objects.create( #     field6='parent' # ) # self.child1_with_validation = ModelWithValidation.objects.create( #     field6='child1', #     parent=self.parent_with_validation # ) # self.child2_with_validation = ModelWithValidation.objects.create( #     field6='child2', #     parent=self.parent_with_validation # ) # self.parent_admin_with_validation = TreeNodeParentAdmin( #     ModelWithValidation, #     AdminSite() # ) # self.parent_invalid_move = ModelWithInvalidMove.objects.create( #     field7='parent' # ) # self.child1_invalid_move = ModelWithInvalidMove.objects.create( #     field7='child1', #     parent=self.parent_invalid_move # ) # self.child2_invalid_move = ModelWithInvalidMove.objects.create( #     field7='child2', #     parent=self.parent_invalid_move # ) # self.parent_admin_invalid_move = TreeNodeParentAdmin( #     ModelWithInvalidMove, #     AdminSite() # ) Check test stylable results obj # self.assertEqual(repr(stylable_results(self.parent_admin)).split(' at ')[0], '<generator object stylable_results') Check stylable column repr obj # request = self.request_factory.get('/', {}) # request.user = self.alfred # request.POST = { #     'moved_id': self.child2.id, #     'target_id': self.child1.id, #     'previous_parent_id': self.parent.id, #     'position': 'inside' # } # cl = self.parent_admin.get_changelist_instance(request) # assert isinstance(cl, ChangeList), "cl variable should be an admin ChangeList" # result = cl.result_list[0] # field_name = 'field5'  # chief # self.assertEqual(repr(stylable_column_repr(cl, result, field_name)), "('parent', None)")