incuna/incuna-test-utils — pull request #40 by KevinEtienne (2014-11-19 10:18:58+00:00)
Title: Add AdminIntegrationTestCase

This executes a little slowly for my liking, but seems to do the job:

```
from django.core.urlresolvers import reverse
from django.test import TestCase

class AdminIntegrationTestCase(TestCase):
def setUp(self):
admin_user = factories.SuperUserFactory.create()
logged_in = self.client.login(
username=admin_user.username,
password=admin_user.raw_password,
)
self.assertTrue(logged_in)

def get_url_name(self, action):
return 'admin:{app}_{model}_{action}'.format(
app=self.model._meta.app_label,
model=self.model._meta.object_name.lower(),
action=action,
)

def get_admin_add_page(self):
url_name = self.get_url_name('add')
return self.client.get(reverse(url_name))

def get_admin_changelist_page(self):
url_name = self.get_url_name('changelist')
return self.client.get(reverse(url_name))

def get_admin_change_page(self, obj):
url_name = self.get_url_name('change')
return self.client.get(reverse(url_name, args=[obj.pk]))

def get_admin_delete_page(self, obj):
url_name = self.get_url_name('delete')
return self.client.get(reverse(url_name, args=[obj.pk]))
```
Here is an example of it in use
```
from . import factories
from .. import models

class TestFooAdmin(AdminIntegrationTestCase):
model = models.Foo
factory = factories.FooFactory

def test_add(self):
response = self.get_admin_add_page()
self.assertEqual(response.status_code, 200)

def test_changelist(self):
response = self.get_admin_changelist_page()
self.assertEqual(response.status_code, 200)

def test_change(self):
foo = self.factory.create()
response = self.get_admin_change_page(foo)
self.assertEqual(response.status_code, 200)

def test_delete(self):
foo = self.factory.create()
response = self.get_admin_delete_page(foo)
self.assertEqual(response.status_code, 200)
```