Permalink
Browse files

Add test cases

  • Loading branch information...
1 parent a81b82d commit 6b888f7d8b9503627520f3276a75050a268669fe @lqez lqez committed Jan 20, 2014
Showing with 88 additions and 13 deletions.
  1. +1 −0 .coveragerc
  2. +3 −7 .gitignore
  3. +4 −2 django_summernote/models.py
  4. +5 −0 django_summernote/test_settings.py
  5. +75 −4 django_summernote/tests.py
View
@@ -1,2 +1,3 @@
[run]
source = django_summernote
+omit = */test*
View
@@ -25,6 +25,9 @@ pip-log.txt
.coverage
.tox
nosetests.xml
+test_media
+.coveralls.yml
+coverage.xml
# Translations
*.mo
@@ -35,10 +38,3 @@ nosetests.xml
.pydevproject
.ropeproject
-
-# django-setuptest
-coverage.xml
-pep8.txt
-
-
-.coveralls.yml
@@ -44,8 +44,10 @@ def _get_attachment_storage():
class Attachment(models.Model):
name = models.CharField(max_length=255, null=True, blank=True)
- file = models.FileField(upload_to=summernote_config['attachment_upload_to'],
- storage=_get_attachment_storage())
+ file = models.FileField(
+ upload_to=summernote_config['attachment_upload_to'],
+ storage=_get_attachment_storage()
+ )
uploaded = models.DateTimeField(auto_now_add=True)
@@ -6,6 +6,7 @@
}
STATIC_URL = '/'
+MEDIA_ROOT = 'test_media'
SECRET_KEY = 'django_summernote'
@@ -15,3 +16,7 @@
'django.contrib.staticfiles',
'django_summernote',
)
+
+SUMMERNOTE_CONFIG = {
+ 'attachment_storage_class': 'django.core.files.storage.DefaultStorage',
+}
@@ -1,15 +1,20 @@
-from django.test import TestCase
+from django.contrib.admin.sites import AdminSite
from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django_summernote.settings import summernote_config
class DjangoSummernoteTest(TestCase):
+ def setUp(self):
+ self.site = AdminSite()
def test_base(self):
self.assertTrue(True)
def test_url(self):
url = reverse('django_summernote-editor', kwargs={'id': 'foobar'})
response = self.client.get(url)
+
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'summernote.min.js')
self.assertContains(response, 'summernote.css')
@@ -18,8 +23,74 @@ def test_widget(self):
from django_summernote.widgets import SummernoteWidget
widget = SummernoteWidget()
- html = widget.render('foobar', 'lorem ipsum', attrs={'id': 'foobar'})
- url = reverse('django_summernote-editor', kwargs={'id': 'foobar'})
+ html = widget.render(
+ 'foobar', 'lorem ipsum', attrs={'id': 'id_foobar'}
+ )
+ url = reverse('django_summernote-editor', kwargs={'id': 'id_foobar'})
assert url in html
- assert 'id="foobar"' in html
+ assert 'id="id_foobar"' in html
+
+ def test_form(self):
+ from django import forms
+ from django_summernote.widgets import SummernoteWidget
+
+ class SimpleForm(forms.Form):
+ foobar = forms.CharField(widget=SummernoteWidget())
+
+ f = SimpleForm()
+ html = f.as_p()
+ url = reverse('django_summernote-editor', kwargs={'id': 'id_foobar'})
+
+ assert url in html
+ assert 'id="id_foobar"' in html
+
+ def test_attachment(self):
+ import os
+ url = reverse('django_summernote-upload_attachment')
+
+ with open(__file__) as fp:
+ response = self.client.post(url, {'files': [fp]})
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(
+ response, '"name": "{}"'.format(os.path.basename(__file__)))
+ self.assertContains(response, '"url": ')
+ self.assertContains(response, '"size": ')
+
+ def test_attachment_bad_request(self):
+ url = reverse('django_summernote-upload_attachment')
+ response = self.client.get(url)
+
+ self.assertNotEqual(response.status_code, 200)
+
+ def test_attachment_no_attachment(self):
+ url = reverse('django_summernote-upload_attachment')
+ response = self.client.post(url)
+
+ self.assertNotEqual(response.status_code, 200)
+
+ def test_attachment_filesize_exceed(self):
+ import os
+
+ url = reverse('django_summernote-upload_attachment')
+ size = os.path.getsize(__file__)
+ summernote_config['attachment_filesize_limit'] = size - 1
+
+ with open(__file__) as fp:
+ response = self.client.post(url, {'files': [fp]})
+ self.assertNotEqual(response.status_code, 200)
+
+ def test_admin_decorator(self):
+ from django.db import models
+ from django_summernote.admin import SummernoteModelAdmin
+ from django_summernote.widgets import SummernoteWidget
+
+ class SimpleModel(models.Model):
+ foobar = models.TextField()
+
+ ma = SummernoteModelAdmin(SimpleModel, self.site)
+
+ assert isinstance(
+ ma.get_form(None).base_fields['foobar'].widget,
+ SummernoteWidget
+ )

0 comments on commit 6b888f7

Please sign in to comment.