aboutsummaryrefslogtreecommitdiff
path: root/apps/notes/tests/test_models.py
blob: 05f2618b66ded74f5d2530d15b5bb58f3c5adbe9 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
from django.test import TestCase
from django.urls import reverse
from django.contrib import auth
from mixer.backend.django import mixer

from notes.models import Note, Notebook 

User = auth.get_user_model()


class NotebookModelTest(TestCase):
    def setUp(self):
        self.user = mixer.blend(User, username='tpynchon')
        self.notebook = Notebook(owner=self.user, name="San Miguel Notes")
        self.notebook.save()

    def test_string_representation(self):
        """Notebook title should be the name of the object"""
        self.assertEqual(str(self.notebook), "San Miguel Notes")

    def test_get_absolute_url(self):
        """Absolute URL should return /nb/slug """
        self.assertEqual(str(self.notebook.get_absolute_url), reverse("notebooks:detail", kwargs={'slug': self.notebook.slug}))


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):
        """Absolute URL should return /n/slug/pk """
        self.assertEqual(str(self.note.get_absolute_url), "/n/%s/%s" % (self.note.slug, self.note.pk))