from django.core.urlresolvers import reverse
from django.test import TestCase
from feder.users.factories import UserFactory
from feder.main.mixins import PermissionStatusMixin
from .factories import CaseFactory


class ObjectMixin(object):
    def setUp(self):
        self.user = UserFactory(username="john")
        self.case = CaseFactory()
        self.permission_object = self.case.monitoring


class CaseListViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
    status_anonymous = 200
    status_no_permission = 200

    def get_url(self):
        return reverse('cases:list')


class CaseDetailViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
    status_anonymous = 200
    status_no_permission = 200

    def get_url(self):
        return reverse('cases:details', kwargs={'slug': self.case.slug})


class CaseCreateViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
    permission = ['monitorings.add_case', ]

    def get_url(self):
        return reverse('cases:create', kwargs={'monitoring': str(self.case.monitoring.pk)})


class CaseUpdateViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
    permission = ['monitorings.change_case', ]

    def get_url(self):
        return reverse('cases:update', kwargs={'slug': self.case.slug})


class CaseDeleteViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
    permission = ['monitorings.delete_case', ]

    def get_url(self):
        return reverse('cases:delete', kwargs={'slug': self.case.slug})

@@ -66,62 +66,33 @@
 ort 
-TestCase%0Afrom feder.users.factories import UserFactory
+RequestFactory, TestCase%0A
 %0Afro
@@ -149,37 +149,120 @@
 rom 
-.factories import CaseFactory
+feder.users.factories import UserFactory%0A%0Afrom .factories import CaseFactory%0Afrom .views import CaseAutocomplete
 %0A%0A%0Ac
@@ -1533,28 +1533,456 @@
 s=%7B'slug': self.case.slug%7D)%0A
+%0A%0Aclass CaseAutocompleteTestCase(TestCase):%0A    def setUp(self):%0A        self.factory = RequestFactory()%0A%0A    def test_filter_by_name(self):%0A        CaseFactory(name='123')%0A        CaseFactory(name='456')%0A        request = self.factory.get('/customer/details', data=%7B'q': '123'%7D)%0A        response = CaseAutocomplete.as_view()(request)%0A        self.assertContains(response, '123')%0A        self.assertNotContains(response, '456')%0A

Add CaseAutocompleteTestCase