Skip to content

Instantly share code, notes, and snippets.

@alxpck
Created July 30, 2015 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alxpck/b861a7931308b626a182 to your computer and use it in GitHub Desktop.
Save alxpck/b861a7931308b626a182 to your computer and use it in GitHub Desktop.
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils import timezone
from .models import Course, Step
# Create your tests here.
class CourseModelTests(TestCase):
def test_course_creation(self):
course = Course.objects.create(
title="Python Regular Expressions",
description="Learn to write regular expressions in Python"
)
now = timezone.now()
self.assertLess(course.created_at, now)
def test_step_creation(self):
step = Step.objects.create(
title="Introduction to Doctests",
description="Learn to write tests in your docstrings.",
course=self.course
)
self.assertIn(step, self.course.step_set.all())
class CourseViewTests(TestCase):
def setUp(self):
self.course = Course.objects.create(
title="Python Testing",
description="Learn to write tests in Python"
)
self.course2 = Course.objects.create(
title="New Course",
description="A new course"
)
self.step = Step.objects.create(
title="Introduction to Doctests",
description="Learn to write tests in your docsctrings.",
course=self.course
)
def test_course_list_view(self):
resp = self.client.get(reverse('courses:list'))
self.assertEqual(resp.status_code, 200)
self.assertIn(self.course, resp.context['courses'])
self.assertIn(self.course2, resp.context['courses'])
@alxpck
Copy link
Author

alxpck commented Jul 30, 2015

Not working, throwing "an error: "django.core.urlresolvers.NoReverseMatch"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment