# Path: crudbuilder/helpers.py
# def plural(text):
# def mixedToUnder(s):  # pragma: no cover
# def mixedToUnderSub(match):
# def capword(s):
# def lowerword(s):  # pragma: no cover
# def underToMixed(name):
# def model_class_form(name):
# def underToAllCaps(value):  # pragma: no cover
# def import_crud(app):
# def auto_discover():
# def custom_postfix_url(crud, model):
# def get_urlresolver():
# 
# Path: crudbuilder/tests/models.py
# class TestModel(models.Model):
# 
#     name = models.CharField(blank=True, null=True, max_length=100)
#     email = models.EmailField(blank=True, null=True)
#     created_at = models.DateTimeField(auto_now=True)
# 
# Path: crudbuilder/tests/crud.py
# class TestModelCrud(BaseCrudBuilder):
#     model = TestModel
#     search_fields = ['name']
#     tables2_fields = ('name', 'email')
#     tables2_css_class = "table table-bordered table-condensed"
#     tables2_pagination = 20  # default is 10
#     modelform_excludes = ['created_by']
# 
# class TestChildInlineFormset(BaseInlineFormset):
#     inline_model = TestChildModel
#     parent_model = TestModel
#     exclude = ['created_by', 'updated_by']
# 
# Path: crudbuilder/tests/forms.py
# class TestModelForm(forms.ModelForm):
#     class Meta:
#         model = TestModel
#         fields = '__all__'
# 
#     def __init__(self, *args, **kwargs):
#         self.request = kwargs.pop('request', None)
#         # print(self.request.user)
#         super(TestModelForm, self).__init__(*args, **kwargs)
# 
# Path: crudbuilder/tests/tables.py
# class TestModelTable(tables.Table):
# 
#     class Meta:
#         model = TestModel
#         attrs = {"class": "table table-bordered table-condensed"}


from django.test import TestCase, Client
from django.contrib.auth.models import User
from django.template import Context, Template
from django.test.utils import override_settings
from crudbuilder.helpers import reverse
from crudbuilder.tests.models import TestModel
from crudbuilder.tests.crud import TestModelCrud, TestChildInlineFormset
from crudbuilder.tests.forms import TestModelForm
from crudbuilder.tests.tables import TestModelTable



class ViewTestCase(TestCase):
    def setUp(self):
        self.client = Client()
        TestModelCrud.custom_modelform = TestModelForm
        TestModelCrud.custom_table2 = TestModelTable

        self.user = User.objects.create_user(
            username='asdf',
            password='asdf3452',
            email='sa@me.org')

    def client_login(self):
        self.client.login(
            username=self.user.username,
            password='asdf3452'
        )

    def get_list_view(self):
        self.client_login()
        response = self.client.get(reverse('tests-testmodels-list'))
        self.assertEqual(200, response.status_code)

    def get_detail_view(self, obj):
        self.client_login()

# Path: crudbuilder/helpers.py
# def plural(text):
# def mixedToUnder(s):  # pragma: no cover
# def mixedToUnderSub(match):
# def capword(s):
# def lowerword(s):  # pragma: no cover
# def underToMixed(name):
# def model_class_form(name):
# def underToAllCaps(value):  # pragma: no cover
# def import_crud(app):
# def auto_discover():
# def custom_postfix_url(crud, model):
# def get_urlresolver():
# 
# Path: crudbuilder/tests/models.py
# class TestModel(models.Model):
# 
#     name = models.CharField(blank=True, null=True, max_length=100)
#     email = models.EmailField(blank=True, null=True)
#     created_at = models.DateTimeField(auto_now=True)
# 
# Path: crudbuilder/tests/crud.py
# class TestModelCrud(BaseCrudBuilder):
#     model = TestModel
#     search_fields = ['name']
#     tables2_fields = ('name', 'email')
#     tables2_css_class = "table table-bordered table-condensed"
#     tables2_pagination = 20  # default is 10
#     modelform_excludes = ['created_by']
# 
# class TestChildInlineFormset(BaseInlineFormset):
#     inline_model = TestChildModel
#     parent_model = TestModel
#     exclude = ['created_by', 'updated_by']
# 
# Path: crudbuilder/tests/forms.py
# class TestModelForm(forms.ModelForm):
#     class Meta:
#         model = TestModel
#         fields = '__all__'
# 
#     def __init__(self, *args, **kwargs):
#         self.request = kwargs.pop('request', None)
#         # print(self.request.user)
#         super(TestModelForm, self).__init__(*args, **kwargs)
# 
# Path: crudbuilder/tests/tables.py
# class TestModelTable(tables.Table):
# 
#     class Meta:
#         model = TestModel
#         attrs = {"class": "table table-bordered table-condensed"}


# Path: crudbuilder/tests/test_views.py
from django.test import TestCase, Client
from django.contrib.auth.models import User
from django.template import Context, Template
from django.test.utils import override_settings
from crudbuilder.helpers import reverse
from crudbuilder.tests.models import TestModel
from crudbuilder.tests.crud import TestModelCrud, TestChildInlineFormset
from crudbuilder.tests.forms import TestModelForm
from crudbuilder.tests.tables import TestModelTable




class ViewTestCase(TestCase):
    def setUp(self):
        self.client = Client()
        TestModelCrud.custom_modelform = TestModelForm
        TestModelCrud.custom_table2 = TestModelTable

        self.user = User.objects.create_user(
            username='asdf',
            password='asdf3452',
            email='sa@me.org')

    def client_login(self):
        self.client.login(
            username=self.user.username,
            password='asdf3452'
        )

    def get_list_view(self):
        self.client_login()
        response = self.client.get(reverse('tests-testmodels-list'))
        self.assertEqual(200, response.status_code)

    def get_detail_view(self, obj):
        self.client_login()

        response = self.client.get(reverse('tests-testmodels-detail', args=(obj.pk, )))