1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
from django.test import TestCase
from mixer.backend.django import mixer
from notes.models import Note, Notebook
from accounts.models import User
class NotebookModelTest(TestCase):
def test_string_representation(self):
user = mixer.blend(User, username='tpynchon')
notebook = Notebook(owner=user, name="San Miguel Notes")
self.assertEqual(str(notebook), "San Miguel Notes")
class NoteModelTest(TestCase):
def setUp(self):
self.user = mixer.blend(User, username='tpynchon')
self.note = Note.objects.create(
owner=self.user,
title="test note",
body_text="the body of the note",
url="https://luxagraf.net/",
tags="mine,cool site"
)
self.note.save()
self.note_no_title = Note.objects.create(
owner=self.user,
body_text="the body of the note",
url="https://luxagraf.net/",
tags="mine,cool site"
)
self.note_no_title.save()
def test_string_representation(self):
self.assertEqual(str(self.note), "test note")
self.assertEqual(str(self.note.body_text), "the body of the note")
self.assertEqual(str(self.note.url), "https://luxagraf.net/")
self.assertEqual(str(self.note.tags), "mine,cool site")
# titleless note gets date
self.assertEqual(str(self.note_no_title), str(self.note_no_title.body_text)[:50])
def test_get_absolute_url(self):
self.assertEqual(str(self.note.get_absolute_url), "/notes/%s/%s" % (self.note.owner.username, self.note.slug))
|