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)

[((317, 332), 'target.models.Target', 'models.Target', ([], {}), '()\n', (330, 332), False, 'from target import models\n'), ((432, 446), 'django.utils.timezone.now', 'timezone.now', ([], {}), '()\n', (444, 446), False, 'from django.utils import timezone\n'), ((536, 599), 'django.contrib.auth.models.User.objects.create_user', 'User.objects.create_user', (['"""admin"""', '"""admin@example.com"""', '"""abcde"""'], {}), "('admin', 'admin@example.com', 'abcde')\n", (560, 599), False, 'from django.contrib.auth.models import User\n'), ((724, 732), 'django.test.Client', 'Client', ([], {}), '()\n', (730, 732), False, 'from django.test import Client\n'), ((851, 873), 'django.urls.reverse', 'reverse', (['"""target:list"""'], {}), "('target:list')\n", (858, 873), False, 'from django.urls import reverse\n'), ((1018, 1065), 'django.urls.reverse', 'reverse', (['"""target:detail"""'], {'args': '(target.number,)'}), "('target:detail', args=(target.number,))\n", (1025, 1065), False, 'from django.urls import reverse\n'), ((1162, 1186), 'django.urls.reverse', 'reverse', (['"""target:create"""'], {}), "('target:create')\n", (1169, 1186), False, 'from django.urls import reverse\n'), ((1284, 1337), 'django.urls.reverse', 'reverse', (['"""target:create_letters"""'], {'args': "('practical',)"}), "('target:create_letters', args=('practical',))\n", (1291, 1337), False, 'from django.urls import reverse\n'), ((1435, 1470), 'django.urls.reverse', 'reverse', (['"""target:delete"""'], {'args': '(1,)'}), "('target:delete', args=(1,))\n", (1442, 1470), False, 'from django.urls import reverse\n'), ((973, 1000), 'target.models.Target.objects.all', 'models.Target.objects.all', ([], {}), '()\n', (998, 1000), False, 'from target import models\n')]