Created
July 30, 2015 02:56
-
-
Save alxpck/b861a7931308b626a182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working, throwing "an error: "django.core.urlresolvers.NoReverseMatch"