# Path: boards/models.py
# class Board(models.Model):
#     name = models.CharField(max_length=30, unique=True)
#     description = models.CharField(max_length=100)
# 
#     def __str__(self):
#         return self.name
# 
#     def get_posts_count(self):
#         return Post.objects.filter(topic__board=self).count()
# 
#     def get_last_post(self):
#         return Post.objects.filter(topic__board=self).order_by('-created_at').first()
# 
# Path: boards/views.py
# class TopicListView(ListView):
#     model = Topic
#     context_object_name = 'topics'
#     template_name = 'topics.html'
#     paginate_by = 20
# 
#     def get_context_data(self, **kwargs):
#         kwargs['board'] = self.board
#         return super().get_context_data(**kwargs)
# 
#     def get_queryset(self):
#         self.board = get_object_or_404(Board, pk=self.kwargs.get('pk'))
#         queryset = self.board.topics.order_by('-last_updated').annotate(replies=Count('posts') - 1)
#         return queryset


from django.test import TestCase
from django.urls import resolve, reverse
from ..models import Board
from ..views import TopicListView



class BoardTopicsTests(TestCase):
    def setUp(self):
        Board.objects.create(name='Django', description='Django board.')

    def test_board_topics_view_success_status_code(self):
        url = reverse('board_topics', kwargs={'pk': 1})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)

    def test_board_topics_view_not_found_status_code(self):
        url = reverse('board_topics', kwargs={'pk': 99})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)


# Path: boards/models.py
# class Board(models.Model):
#     name = models.CharField(max_length=30, unique=True)
#     description = models.CharField(max_length=100)
# 
#     def __str__(self):
#         return self.name
# 
#     def get_posts_count(self):
#         return Post.objects.filter(topic__board=self).count()
# 
#     def get_last_post(self):
#         return Post.objects.filter(topic__board=self).order_by('-created_at').first()
# 
# Path: boards/views.py
# class TopicListView(ListView):
#     model = Topic
#     context_object_name = 'topics'
#     template_name = 'topics.html'
#     paginate_by = 20
# 
#     def get_context_data(self, **kwargs):
#         kwargs['board'] = self.board
#         return super().get_context_data(**kwargs)
# 
#     def get_queryset(self):
#         self.board = get_object_or_404(Board, pk=self.kwargs.get('pk'))
#         queryset = self.board.topics.order_by('-last_updated').annotate(replies=Count('posts') - 1)
#         return queryset


# Path: boards/tests/test_view_board_topics.py
from django.test import TestCase
from django.urls import resolve, reverse
from ..models import Board
from ..views import TopicListView




class BoardTopicsTests(TestCase):
    def setUp(self):
        Board.objects.create(name='Django', description='Django board.')

    def test_board_topics_view_success_status_code(self):
        url = reverse('board_topics', kwargs={'pk': 1})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)

    def test_board_topics_view_not_found_status_code(self):
        url = reverse('board_topics', kwargs={'pk': 99})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)


    def test_board_topics_url_resolves_board_topics_view(self):