from django.contrib.auth.models import User
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from target import models
from django.utils import timezone

# Create your tests here.

class URLSWork(TestCase):

    @classmethod
    def setUpTestData(cls):
        target = models.Target()
        target.letters = 'practical'
        target.words = 'practical'
        target.published = timezone.now()
        target.number = 1
        target.save()

    def test_urls(self):
        user = User.objects.create_user('admin', 'admin@example.com', 'abcde')
        user.is_staff = True
        user.is_active = True
        user.is_superuser = True
        user.save()
        c = Client()
        response = c.login(username='admin', password='abcde')
        self.assertEqual(response, True)
        url = reverse('target:list')
        response = c.get(url)
        self.assertEqual(response.status_code, 200)
        target = models.Target.objects.all()[0]
        url = reverse('target:detail', args=(target.number,))
        response = c.get(url)
        self.assertEqual(response.status_code, 200)
        url = reverse('target:create')
        response = c.post(url)
        self.assertEqual(response.status_code, 200)
        url = reverse('target:create_letters', args=('practical',))
        response = c.post(url)
        self.assertEqual(response.status_code, 200)
        url = reverse('target:delete', args=(1,))
        response = c.get(url)
        self.assertEqual(response.status_code, 200)

[((14, 17, 14, 32), 'target.models.Target', 'models.Target', ({}, {}), '()', False, 'from target import models\n'), ((17, 27, 17, 41), 'django.utils.timezone.now', 'timezone.now', ({}, {}), '()', False, 'from django.utils import timezone\n'), ((22, 15, 22, 78), 'django.contrib.auth.models.User.objects.create_user', 'User.objects.create_user', ({(22, 40, 22, 47): '"""admin"""', (22, 49, 22, 68): '"""admin@example.com"""', (22, 70, 22, 77): '"""abcde"""'}, {}), "('admin', 'admin@example.com', 'abcde')", False, 'from django.contrib.auth.models import User\n'), ((27, 12, 27, 20), 'django.test.Client', 'Client', ({}, {}), '()', False, 'from django.test import Client\n'), ((30, 14, 30, 36), 'django.urls.reverse', 'reverse', ({(30, 22, 30, 35): '"""target:list"""'}, {}), "('target:list')", False, 'from django.urls import reverse\n'), ((34, 14, 34, 61), 'django.urls.reverse', 'reverse', (), '', False, 'from django.urls import reverse\n'), ((37, 14, 37, 38), 'django.urls.reverse', 'reverse', ({(37, 22, 37, 37): '"""target:create"""'}, {}), "('target:create')", False, 'from django.urls import reverse\n'), ((40, 14, 40, 67), 'django.urls.reverse', 'reverse', (), '', False, 'from django.urls import reverse\n'), ((43, 14, 43, 49), 'django.urls.reverse', 'reverse', (), '', False, 'from django.urls import reverse\n'), ((33, 17, 33, 44), 'target.models.Target.objects.all', 'models.Target.objects.all', ({}, {}), '()', False, 'from target import models\n')]