aboutsummaryrefslogtreecommitdiff
path: root/apps/notes/tests
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-11-24 22:29:02 -0600
committerluxagraf <sng@luxagraf.net>2018-11-24 22:29:02 -0600
commit0c2a092e8d8ad33a1c306ee9efca0da96eb56415 (patch)
tree0aaf48f20771c97ec30e005ef818ef6ce4856097 /apps/notes/tests
parent7a284139f6b97bb06548e69d47eef188bc99099d (diff)
way to much for a single commit
Diffstat (limited to 'apps/notes/tests')
-rw-r--r--apps/notes/tests/test_models.py24
-rw-r--r--apps/notes/tests/test_views.py32
2 files changed, 35 insertions, 21 deletions
diff --git a/apps/notes/tests/test_models.py b/apps/notes/tests/test_models.py
index ddb731e..cf21aca 100644
--- a/apps/notes/tests/test_models.py
+++ b/apps/notes/tests/test_models.py
@@ -1,32 +1,32 @@
from django.test import TestCase
from mixer.backend.django import mixer
-from notes.models import Note, Folder
+from notes.models import Note, Notebook
from accounts.models import User
-class FolderModelTest(TestCase):
+class NotebookModelTest(TestCase):
def test_string_representation(self):
user = mixer.blend(User, username='tpynchon')
- folder = Folder(created_by=user, name="My Folder")
- self.assertEqual(str(folder), "My Folder")
+ 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='test')
+ self.user = mixer.blend(User, username='tpynchon')
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/",
tags="mine,cool site"
)
self.note.save()
self.note_no_title = Note.objects.create(
- created_by=self.user,
- body="the body of the note",
+ owner=self.user,
+ body_text="the body of the note",
url="https://luxagraf.net/",
tags="mine,cool site"
)
@@ -34,11 +34,11 @@ class NoteModelTest(TestCase):
def test_string_representation(self):
self.assertEqual(str(self.note), "test note")
- self.assertEqual(str(self.note.body), "the body of the 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.date_created))
+ 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/" % (self.note.id))
+ self.assertEqual(str(self.note.get_absolute_url), "/notes/%s/%s" % (self.note.owner.username, self.note.slug))
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)