from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.test.client import Client

from model_mommy import mommy

from devices.models import Device
from users.models import Lageruser


class HistoryTests(TestCase):
    def setUp(self):
        self.client = Client()
        self.admin = Lageruser.objects.create_superuser('test', 'test@test.com', "test")
        self.client.login(username="test", password="test")

    def test_global_view(self):
        response = self.client.get('/history/global/')
        self.assertEqual(response.status_code, 200)

    def test_list_view(self):
        content_type = ContentType.objects.get(model='device')
        device = mommy.make(Device)
        response = self.client.get('/history/%i/%i/' % (content_type.pk, device.pk))
        self.assertEqual(response.status_code, 200)

    def test_detail_view(self):
        device = mommy.make(Device)
        response = self.client.post('/devices/%i/edit/' % device.pk, data={
            'name': 'test',
            'creator': self.admin.pk,
        })
        self.assertEqual(response.status_code, 302)
        response = self.client.get('/history/version/1/')
        self.assertEqual(response.status_code, 200)

[((13, 22, 13, 30), 'django.test.client.Client', 'Client', ({}, {}), '()', False, 'from django.test.client import Client\n'), ((14, 21, 14, 88), 'users.models.Lageruser.objects.create_superuser', 'Lageruser.objects.create_superuser', ({(14, 56, 14, 62): '"""test"""', (14, 64, 14, 79): '"""test@test.com"""', (14, 81, 14, 87): '"""test"""'}, {}), "('test', 'test@test.com', 'test')", False, 'from users.models import Lageruser\n'), ((22, 23, 22, 62), 'django.contrib.contenttypes.models.ContentType.objects.get', 'ContentType.objects.get', (), '', False, 'from django.contrib.contenttypes.models import ContentType\n'), ((23, 17, 23, 35), 'model_mommy.mommy.make', 'mommy.make', ({(23, 28, 23, 34): 'Device'}, {}), '(Device)', False, 'from model_mommy import mommy\n'), ((28, 17, 28, 35), 'model_mommy.mommy.make', 'mommy.make', ({(28, 28, 28, 34): 'Device'}, {}), '(Device)', False, 'from model_mommy import mommy\n')]