from django.urls import reverse, resolve from django.test import TestCase from django.contrib import auth from mixer.backend.django import mixer from notes.models import Note User = auth.get_user_model() class TestNotesURLs(TestCase): """Test URL patterns for notes.""" 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() def test_list_reverse(self): """notes:list should reverse to /n/.""" self.assertEqual(reverse('notes:list'), '/n/') def test_list_resolve(self): """/n/ should resolve to notes:list.""" self.assertEqual(resolve('/n/').view_name, 'notes:list') def test_detail_reverse(self): """notes:detail should reverse to /n/slug/id""" path = '/n/%s/%s' % (self.note.slug, self.note.pk) self.assertEqual( reverse('notes:detail', kwargs={'slug': self.note.slug, 'pk': self.note.pk}), path ) def test_detail_resolve(self): """/n/test-note/1 should resolve to notes:detail.""" self.assertEqual(resolve('/n/test-note/1').view_name, 'notes:detail') def test_create_reverse(self): """notes:create should reverse to /n/create/.""" self.assertEqual(reverse('notes:create'), '/n/create/') def test_create_resolve(self): """/n/create/ should resolve to notes:create""" self.assertEqual( resolve('/n/create/').view_name, 'notes:create' ) class TestNotebooksURLs(TestCase): """Test URL patterns for notebooks.""" def test_list_reverse(self): """notebooks:list should reverse to /nb/.""" self.assertEqual(reverse('notebooks:list'), '/nb/') def test_list_resolve(self): """/n/ should resolve to notes:list.""" self.assertEqual(resolve('/nb/').view_name, 'notebooks:list') def test_detail_reverse(self): """notes:detail should reverse to /nb/slug""" self.assertEqual(reverse('notebooks:detail', kwargs={'slug': 'test-notebook'}), '/nb/test-notebook') def test_detail_resolve(self): """/n/test-note/1 should resolve to notes:detail.""" self.assertEqual(resolve('/nb/test-notebook').view_name, 'notebooks:detail')