Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Add tests for views/courses.py
Browse files Browse the repository at this point in the history
Still missing tests for some views, and only faculty_overview has a test
for the returned context so far. Otherwise, pretty happy with it.
  • Loading branch information
dellsystem committed Feb 7, 2014
1 parent 04fcac3 commit 02f9bb6
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
36 changes: 36 additions & 0 deletions wiki/fixtures/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@
"name": "Calculus A"
}
},
{
"pk": 2,
"model": "wiki.course",
"fields": {
"watchers": [],
"latest_activity": null,
"description": "N/A",
"num_watchers": 0,
"number": "112",
"credits": "3",
"department": "BIOL",
"name": "Cell and Molecular Biology"
}
},
{
"pk": 3,
"model": "wiki.course",
"fields": {
"watchers": [],
"latest_activity": null,
"description": "N/A",
"num_watchers": 0,
"number": "111",
"credits": "3",
"department": "BIOL",
"name": "Organismal Biology"
}
},
{
"pk": 1,
"model": "wiki.coursesemester",
Expand All @@ -35,6 +63,14 @@
"faculty": 1
}
},
{
"pk": "BIOL",
"model": "wiki.department",
"fields": {
"long_name": "Biology",
"faculty": 1
}
},
{
"pk": 1,
"model": "wiki.faculty",
Expand Down
1 change: 1 addition & 0 deletions wiki/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from wiki.tests.series import *
from wiki.tests.users import *
from wiki.tests.urls import *
from wiki.tests.views import *

"""
MORE TESTS TO COME, EVENTUALLY
Expand Down
129 changes: 129 additions & 0 deletions wiki/tests/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
from django.test.client import Client
from django.test import TestCase

from wiki.models.faculties import Faculty


class _ViewTest(TestCase):
fixtures = ['test']

def setUp(self):
client = Client()
self.response = client.get(self.url)

def test_title(self):
title = self.response.context['title']
self.assertEqual(title, self.title)

def test_first_template(self):
self.assertEqual(self.response.templates[0].name, self.template)


# class RemoveSlashTest:


class FacultyOverviewTest(_ViewTest):
url = '/faculty/science/'
title = 'Faculty of Science'
template = 'courses/faculty_overview.html'

def test_context(self):
context = self.response.context

expected_faculty = Faculty.objects.get(slug='science')
self.assertEqual(context['faculty'], expected_faculty)

course_names = [str(course) for course in context['courses']]
expected_course_names = ['BIOL 111', 'BIOL 112', 'MATH 150']
self.assertEqual(course_names, expected_course_names)

departments = [department.pk for department in context['departments']]
expected_departments = ['BIOL', 'MATH']
self.assertEqual(departments, expected_departments)


class DepartmentOverviewTest(_ViewTest):
url = '/MATH/'
title = 'Department of Mathematics & Statistics (MATH)'
template = 'courses/department_overview.html'


class FacultyBrowseTest(_ViewTest):
url = '/courses/faculty/'
title = 'Browse by faculty'
template = 'courses/faculty_browse.html'


class DepartmentBrowseTest(_ViewTest):
url = '/courses/department/'
title = 'Browse by department'
template = 'courses/department_browse.html'


class ProfessorBrowseTest(_ViewTest):
url = '/courses/professor/'
title = 'Browse by professor'
template = 'courses/professor_browse.html'


# class RandomCourseTest:


class CourseIndexTest(_ViewTest):
url = '/courses/'
title = 'Courses'
template = 'courses/index.html'


class PopularBrowseTest(_ViewTest):
url = '/courses/popular/'
title = 'Browse courses by popularity'
template = 'courses/all_browse.html'


class ActiveBrowseTest(_ViewTest):
url = '/courses/active/'
title = 'Browse courses by activity'
template = 'courses/all_browse.html'


class AllBrowseTest(_ViewTest):
url = '/courses/all/'
title = 'Browse all courses'
template = 'courses/all_browse.html'


# class WatchCourseTest:


# class GetAllTest:


class CourseOverviewTest(_ViewTest):
url = '/MATH_150/'
title = 'MATH 150'
template = 'courses/overview.html'


class SemesterOverviewTest(_ViewTest):
url = '/MATH_150/fall-2011/'
title = 'MATH 150 (Fall 2011)'
template = 'courses/semester_overview.html'


class CourseRecentActivityTest(_ViewTest):
url = '/MATH_150/recent/'
title = 'Recent activity for MATH 150'
template = 'courses/recent.html'


class CategoryOverviewTest(_ViewTest):
url = '/MATH_150/summary/'
title = 'Course summary content for MATH 150'
template = 'courses/category_overview.html'


class ProfessorOverviewTest(_ViewTest):
url = '/professor/james-loveys/'
title = 'Overview for James G Loveys'
template = 'courses/professor_overview.html'

0 comments on commit 02f9bb6

Please sign in to comment.