3 # Copyright (C) 2012 FinalsClub Foundation
6 import karmaworld.secret.indexden as secret
9 from django.test import TestCase
10 from karmaworld.apps.notes.search import SearchIndex
12 from karmaworld.apps.notes.models import Note
13 from karmaworld.apps.courses.models import Course
14 from karmaworld.apps.courses.models import School
16 # Tell SearchIndex to put its entries
21 class TestNotes(TestCase):
24 # create base values to test db representations
25 self.now = datetime.datetime.utcnow()
27 # create a school to satisfy course requirements
28 self.school = School()
29 self.school.name = 'Marshall College'
32 # create a course to test relationships
33 self.course = Course()
34 self.course.school = self.school
35 self.course.name = u'Archaeology 101'
37 # override Course.save() appending an ID to the slug
38 self.course.slug = u'archaeology-101'
41 # create a note to test against
43 self.note.course = self.course
44 self.note.name = u"Lecture notes concerning the use of therefore ∴"
45 self.note.file_type = 'doc'
46 self.note.uploaded_at = self.now
47 self.note.text = "This is the plaintext version of a note. It's pretty cool. Alpaca."
50 def test_course_fkey(self):
51 self.assertEqual(self.course, self.note.course)
53 def test_slug_natural(self):
54 """ Test that the slug field is slugifying unicode Note.names """
55 expected = u"lecture-notes-concerning-the-use-of-therefore"
56 self.assertEqual(self.note.slug, expected)
58 def test_remake_slug(self):
59 """ Test the generation of a Note.slug field based on Note.
60 Name collision is expected, so see if slug handles this."""
61 expected = u"lecture-notes-concerning-the-use-of-therefore-{0}-{1}-{2}".format(
62 self.note.uploaded_at.month,
63 self.note.uploaded_at.day, self.note.uploaded_at.microsecond)
67 self.assertEqual(self.note.slug, expected)
69 expected_url_prefix = u'/marshall-college/archaeology-101/'
70 expected_slug = u'lecture-notes-concerning-the-use-of-therefore'
71 expected = expected_url_prefix + expected_slug
73 def test_note_get_absolute_url_slug(self):
74 """ Given a note with a slug, test that an expected url is generated """
75 # check that Note.get_absolute_url() is generating the right url
76 self.assertEqual(self.note.get_absolute_url(), self.expected)
78 def test_note_get_absolute_url_id(self):
80 url = self.expected_url_prefix + str(self.note.id)
81 self.assertEqual(self.note.get_absolute_url(), url)