from django.test import SimpleTestCase
from django.urls import reverse, resolve
from .views import (
    IndexView, PostListView, PostUpdateView,
    PostDeleteView, PostDetailView, PostCreateView,
    SearchView, CategoryListView
)


class TestUrls(SimpleTestCase):

    def test_index_url(self):
        # class-based views need to be compared by name, as the functions
        # generated by as_view() won't be equal
        url = reverse('index')
        self.assertEqual(resolve(url).func.__name__, IndexView.as_view().__name__)

    def test_blog_url(self):
        url = reverse('blog')
        self.assertEqual(resolve(url).func.__name__, PostListView.as_view().__name__)

    def test_post_url(self):
        url = reverse('post-detail', args=['some-slug'])
        self.assertEqual(resolve(url).func.__name__, PostDetailView.as_view().__name__)

    def test_post_update_url(self):
        url = reverse('post-update', args=['some-slug'])
        self.assertEqual(resolve(url).func.__name__, PostUpdateView.as_view().__name__)

    def test_post_delete_url(self):
        url = reverse('post-delete', args=['some-slug'])
        self.assertEqual(resolve(url).func.__name__, PostDeleteView.as_view().__name__)

    def test_post_create_url(self):
        url = reverse('post-create')
        self.assertEqual(resolve(url).func.__name__, PostCreateView.as_view().__name__)

    def test_search_url(self):
        url = reverse('search')
        self.assertEqual(resolve(url).func.__name__, SearchView.as_view().__name__)

    def test_category_list_url(self):
        url = reverse('category_list', args=['some-slug'])
        self.assertEqual(resolve(url).func.__name__, CategoryListView.as_view().__name__)
