diff options
Diffstat (limited to 'apps/notes/tests/test_views.py')
-rw-r--r-- | apps/notes/tests/test_views.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/apps/notes/tests/test_views.py b/apps/notes/tests/test_views.py index 05cb8db..4f9a4ce 100644 --- a/apps/notes/tests/test_views.py +++ b/apps/notes/tests/test_views.py @@ -2,6 +2,7 @@ import json from django.test import Client from django.test import RequestFactory, TestCase from django.urls import reverse +from django.template.defaultfilters import slugify from rest_framework.test import force_authenticate from rest_framework.test import APIRequestFactory @@ -25,9 +26,9 @@ class NotesViewsTest(TestCase): self.user = User.objects.create(username='testuser', password='password') self.bad_user = User.objects.create(username='someoneelse', password='password') self.note = Note.objects.create( - created_by=self.user, + owner=self.user, title="test note", - body="the body of the note", + body_text="the body of the note", url="https://luxagraf.net/", ) self.note.tags.add("mine,cool site") @@ -40,6 +41,19 @@ class NotesViewsTest(TestCase): self.assertEqual(response.status_code, 200) # bad_user + def test_note_create_view(self): + data = { + 'title': "test note post", + 'body_text': "the body of the note", + 'url': "https://luxagraf.net/", + 'tags': [], + } + self.client.force_login(self.user) + url = reverse("notes:note-create") + response = self.client.post(url, data) + self.assertEqual(response.status_code, 302) + self.assertRedirects(response, '/notes/%s/%s' % (self.user.username, slugify(data['title']))) + def test_api_list(self): # Make an authenticated request to the view... request = self.factory.get('/api/notes/') @@ -51,36 +65,36 @@ class NotesViewsTest(TestCase): self.assertEqual(api_data['title'], 'test note') self.assertEqual(api_data['tags'], ['mine,cool site']) - def test_note_create(self): + def test_api_note_create(self): ''' - post some data to create a new note + Post some data to create a new note ''' data = { 'title': "test note post", - 'body': "the body of the note", + 'body_text': "the body of the note", 'url': "https://luxagraf.net/", 'tags': [], } self.apiclient.force_authenticate(self.user) - url = reverse("notes:notes-list") + url = reverse("notes-api-list") response = self.apiclient.post(url, data, format='json') self.assertEqual(response.status_code, 201) self.assertEqual(Note.objects.count(), 2) response.render() api_data = json.loads(response.content.decode('utf8')) self.assertEqual(api_data['title'], 'test note post') - self.assertEqual(api_data['body'], 'the body of the note') + self.assertEqual(api_data['body_text'], 'the body of the note') self.assertEqual(api_data['tags'], []) def test_note_create_bad(self): # create another user data = { 'title': "", - 'body': "the body of the note", + 'body_text': "the body of the note", 'url': "https://luxagraf.net/", 'tags': [], } - url = reverse("notes:notes-list") + url = reverse("notes-api-list") self.apiclient.force_authenticate(self.user) response = self.apiclient.post(url, data, format='json') self.assertEqual(response.status_code, 400) |