Skip to content

Instantly share code, notes, and snippets.

@vitorfs
Created October 8, 2017 15:57
Show Gist options
  • Save vitorfs/6b3cd0769f805ab38626f5bd97b4e5e3 to your computer and use it in GitHub Desktop.
Save vitorfs/6b3cd0769f805ab38626f5bd97b4e5e3 to your computer and use it in GitHub Desktop.
from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import resolve, reverse
from ..models import Board, Post, Topic
from ..views import PostListView
class TopicPostsTests(TestCase):
def setUp(self):
board = Board.objects.create(name='Django', description='Django board.')
user = User.objects.create_user(username='john', email='[email protected]', password='123')
topic = Topic.objects.create(subject='Hello, world', board=board, starter=user)
Post.objects.create(message='Lorem ipsum dolor sit amet', topic=topic, created_by=user)
url = reverse('topic_posts', kwargs={'pk': board.pk, 'topic_pk': topic.pk})
self.response = self.client.get(url)
def test_status_code(self):
self.assertEquals(self.response.status_code, 200)
def test_view_function(self):
view = resolve('/boards/1/topics/1/')
self.assertEquals(view.func.view_class, PostListView)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment