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))