Fix missing enctype="multipart/form-data" when needed

- add app example.files with tests, based on example2.
- add check in base update template which checks if
  form.is_multitype and adds the encoding for it
- update gitignore to ignore the uploaded media folder
- add test to blog to ensure that the create form is not
  multipart encoded
This commit is contained in:
yarbelk 2013-09-11 20:20:55 +08:00
parent eb768817f3
commit 690401d604
35 changed files with 784 additions and 2 deletions

3
.gitignore vendored
View file

@ -56,3 +56,6 @@ logfile
# Sublime Text
*.sublime-workspace
*.sublime-project
# test media upload
media

View file

@ -42,7 +42,7 @@
{% block content %}
<form method="post">
<form method="post" {% if form.is_multipart %}enctype="multipart/form-data" {% endif %}>
{% if view.model_admin.save_on_top %}
{% include "djadmin2theme_default/includes/save_buttons.html" %}

View file

@ -356,6 +356,7 @@ class PostDetailViewTest(BaseIntegrationTest):
class PostCreateViewTest(BaseIntegrationTest):
def test_view_ok(self):
response = self.client.get(reverse("admin2:blog_post_create"))
self.assertNotIn('''enctype="multipart/form-data"''', response.content)
self.assertEqual(response.status_code, 200)
def test_create_post(self):

View file

@ -129,6 +129,7 @@ INSTALLED_APPS = (
'djadmin2',
'djadmin2.themes.djadmin2theme_default',
'blog',
'files',
)
# A sample logging configuration. The only tangible logging

View file

10
example/files/admin.py Normal file
View file

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, unicode_literals
from django.contrib import admin
from .models import CaptionedFile, UncaptionedFile
admin.site.register(CaptionedFile)
admin.site.register(UncaptionedFile)

10
example/files/admin2.py Normal file
View file

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, unicode_literals
import djadmin2
from .models import CaptionedFile, UncaptionedFile
djadmin2.default.register(CaptionedFile)
djadmin2.default.register(UncaptionedFile)

Binary file not shown.

View file

@ -0,0 +1,51 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# dbrgn <gezuru@gmail.com>, 2013
# Jannis Leidel <jannis@leidel.info>, 2013
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-08 08:49+0000\n"
"Last-Translator: dbrgn <gezuru@gmail.com>\n"
"Language-Team: German (http://www.transifex.com/projects/p/django-admin2/"
"language/de/)\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr "Beispiel Start"
#: templates/home.html:8
msgid "(for reference)"
msgstr "(für's Protokoll)"

Binary file not shown.

View file

@ -0,0 +1,46 @@
# This file is distributed under the same license as the django-admin2 package.
#
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-09 11:57+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr ""
#: templates/home.html:8
msgid "(for reference)"
msgstr ""

Binary file not shown.

View file

@ -0,0 +1,51 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# NotSqrt <notsqrt@gmail.com>, 2013.
#
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: NotSqrt <notsqrt@gmail.com>\n"
"Language-Team: French (http://www.transifex.com/projects/p/django-admin2/"
"language/fr/)\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr "Exemple de page d'accueil"
#: templates/home.html:8
msgid "(for reference)"
msgstr "(pour référence)"

Binary file not shown.

View file

@ -0,0 +1,50 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# brente <sbrentegani@gmail.com>, 2013
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-07 17:47+0000\n"
"Last-Translator: brente <sbrentegani@gmail.com>\n"
"Language-Team: Italian (http://www.transifex.com/projects/p/django-admin2/"
"language/it/)\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr ""
#: templates/home.html:8
msgid "(for reference)"
msgstr "(per riferimento)"

Binary file not shown.

View file

@ -0,0 +1,50 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# Density21.5 <jasper@plainspace.com>, 2013
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-08 10:46+0000\n"
"Last-Translator: Density21.5 <jasper@plainspace.com>\n"
"Language-Team: Dutch (http://www.transifex.com/projects/p/django-admin2/"
"language/nl/)\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr "Voorbeeld Home"
#: templates/home.html:8
msgid "(for reference)"
msgstr "(ter verwijzing)"

Binary file not shown.

View file

@ -0,0 +1,52 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# dasm <smigiel.dariusz@gmail.com>, 2013
# Marcin Jabrzyk <marcin.jabrzyk@gmail.com>, 2013
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-08 18:04+0000\n"
"Last-Translator: dasm <smigiel.dariusz@gmail.com>\n"
"Language-Team: Polish (Poland) (http://www.transifex.com/projects/p/django-"
"admin2/language/pl_PL/)\n"
"Language: pl_PL\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr "Początek"
#: templates/home.html:8
msgid "(for reference)"
msgstr "(dla przykładu)"

Binary file not shown.

View file

@ -0,0 +1,49 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-09 05:00+0000\n"
"Last-Translator: Douglas Miranda <douglasmirandasilva@gmail.com>\n"
"Language-Team: Portuguese (Brazil) (http://www.transifex.com/projects/p/"
"django-admin2/language/pt_BR/)\n"
"Language: pt_BR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr "Página inicial de exemplo"
#: templates/home.html:8
msgid "(for reference)"
msgstr "(para referência)"

Binary file not shown.

View file

@ -0,0 +1,50 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# Ivana Kellyerova <eruraina@gmail.com>, 2013
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-07 12:47+0000\n"
"Last-Translator: marekzelinka <mzelinka@myopera.com>\n"
"Language-Team: Slovak (http://www.transifex.com/projects/p/django-admin2/"
"language/sk/)\n"
"Language: sk\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr "Ukážka domovskej stránky"
#: templates/home.html:8
msgid "(for reference)"
msgstr "(pre informáciu)"

Binary file not shown.

View file

@ -0,0 +1,50 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# rukku <rk.aranas@gmail.com>, 2013
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-09 08:22+0000\n"
"Last-Translator: rukku <rk.aranas@gmail.com>\n"
"Language-Team: Tagalog (Philippines) (http://www.transifex.com/projects/p/"
"django-admin2/language/tl_PH/)\n"
"Language: tl_PH\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr ""
#: templates/home.html:8
msgid "(for reference)"
msgstr ""

Binary file not shown.

View file

@ -0,0 +1,50 @@
# This file is distributed under the same license as the django-admin2 package.
#
# Translators:
# EricHo <eric913@gmail.com>, 2013
msgid ""
msgstr ""
"Project-Id-Version: django-admin2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-11 06:09-0500\n"
"PO-Revision-Date: 2013-07-07 11:16+0000\n"
"Last-Translator: EricHo <eric913@gmail.com>\n"
"Language-Team: Chinese (http://www.transifex.com/projects/p/django-admin2/"
"language/zh/)\n"
"Language: zh\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: models.py:9
msgid "caption"
msgstr ""
#: models.py:10 models.py:21
msgid "Uploaded File"
msgstr ""
#: models.py:16
msgid "Captioned File"
msgstr ""
#: models.py:17
msgid "Captioned Files"
msgstr ""
#: models.py:27
msgid "Uncaptioned File"
msgstr ""
#: models.py:28
msgid "Uncaptioned Files"
msgstr ""
#: templates/home.html:4
msgid "Example Home"
msgstr "首頁範本"
#: templates/home.html:8
msgid "(for reference)"
msgstr "(參考)"

28
example/files/models.py Normal file
View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
class CaptionedFile(models.Model):
caption = models.CharField(max_length=200, verbose_name=_('caption'))
publication = models.FileField(upload_to='media', verbose_name=_('Uploaded File'))
def __unicode__(self):
return self.caption
class Meta:
verbose_name = _('Captioned File')
verbose_name_plural = _('Captioned Files')
class UncaptionedFile(models.Model):
publication = models.FileField(upload_to='media', verbose_name=_('Uploaded File'))
def __unicode__(self):
return unicode(self.publication)
class Meta:
verbose_name = _('Uncaptioned File')
verbose_name_plural = _('Uncaptioned Files')

View file

@ -0,0 +1,10 @@
{% extends "djadmin2theme_default/base.html" %}
{% load i18n %}
{% block content %}
<h1>{% trans "Example Home" %}</h1>
<ul>
<li><a href="{% url "admin2:dashboard" %}">django-admin2</a></li>
<li><a href="{% url "admin:index" %}">django.contrib.admin</a> {% trans "(for reference)" %}</li>
</ul>
{% endblock %}

View file

@ -0,0 +1,2 @@
from test_models import *
from test_views import *

View file

@ -0,0 +1 @@
Hello World

View file

@ -0,0 +1,54 @@
from django.test import TestCase
from django.utils import timezone
from files.models import CaptionedFile
from files.models import UncaptionedFile
from os import path
fixture_dir = path.join(path.abspath(path.dirname(__file__)), 'fixtures')
class CaptionedFileTestCase(TestCase):
def setUp(self):
self.captioned_file = CaptionedFile.objects.create(
caption="this is a file",
publication=path.join('pubtest.txt')
)
self.captioned_file.save()
def test_creation(self):
cf = CaptionedFile.objects.create(
caption="lo lo",
publication=path.join('pubtest.txt')
)
cf.save()
self.assertEqual(CaptionedFile.objects.count(), 2)
# Cause setup created one already
def test_update(self):
self.captioned_file.caption = "I like text files"
self.captioned_file.save()
cf = CaptionedFile.objects.get()
self.assertEqual(cf.caption, "I like text files")
def test_delete(self):
cf = CaptionedFile.objects.get()
cf.delete()
self.assertEqual(CaptionedFile.objects.count(), 0)
class MultiEncodedAdminFormTest(TestCase):
def setUp(self):
self.user = User(
username='admin',
is_staff=True,
is_superuser=True)
self.user.set_password('admin')
self.user.save()
self.create_url = reverse('admin2:example3_captioned_file_create')

View file

@ -0,0 +1,162 @@
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase, Client
from django.utils import timezone
from ..models import CaptionedFile
from os import path
fixture_dir = path.join(path.abspath(path.dirname(__file__)), 'fixtures')
fixture_file = path.join(fixture_dir, 'pubtest.txt')
class BaseIntegrationTest(TestCase):
"""
Base TestCase for integration tests.
"""
def setUp(self):
self.client = Client()
self.user = get_user_model()(username='user', is_staff=True,
is_superuser=True)
self.user.set_password("password")
self.user.save()
self.client.login(username='user', password='password')
class AdminIndexTest(BaseIntegrationTest):
def test_view_ok(self):
response = self.client.get(reverse("admin2:dashboard"))
self.assertContains(response, reverse("admin2:files_captionedfile_index"))
class CaptionedFileListTest(BaseIntegrationTest):
def test_view_ok(self):
captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
response = self.client.get(reverse("admin2:files_captionedfile_index"))
self.assertContains(response, captioned_file.caption)
def test_actions_displayed(self):
response = self.client.get(reverse("admin2:files_captionedfile_index"))
self.assertInHTML('<a tabindex="-1" href="#" data-name="action" data-value="DeleteSelectedAction">Delete selected items</a>', response.content)
def test_delete_selected_captioned_file(self):
captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
params = {'action': 'DeleteSelectedAction', 'selected_model_pk': str(captioned_file.pk)}
response = self.client.post(reverse("admin2:files_captionedfile_index"), params)
self.assertInHTML('<p>Are you sure you want to delete the selected Captioned File? The following item will be deleted:</p>', response.content)
def test_delete_selected_captioned_file_confirmation(self):
captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
params = {'action': 'DeleteSelectedAction', 'selected_model_pk': str(captioned_file.pk), 'confirmed': 'yes'}
response = self.client.post(reverse("admin2:files_captionedfile_index"), params)
self.assertRedirects(response, reverse("admin2:files_captionedfile_index"))
def test_delete_selected_captioned_file_none_selected(self):
CaptionedFile.objects.create(caption="some file", publication=fixture_file)
params = {'action': 'DeleteSelectedAction'}
response = self.client.post(reverse("admin2:files_captionedfile_index"), params, follow=True)
self.assertContains(response, "Items must be selected in order to perform actions on them. No items have been changed.")
class CaptionedFileDetailViewTest(BaseIntegrationTest):
def test_view_ok(self):
captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
response = self.client.get(reverse("admin2:files_captionedfile_detail", args=(captioned_file.pk, )))
self.assertContains(response, captioned_file.caption)
class CaptionedFileCreateViewTest(BaseIntegrationTest):
def test_view_ok(self):
response = self.client.get(reverse("admin2:files_captionedfile_create"))
self.assertIn('''enctype="multipart/form-data"''', response.content)
self.assertEqual(response.status_code, 200)
def test_create_captioned_file(self):
with open(fixture_file, 'r') as fp:
params = {
"caption": "some file",
"publication": fp,
}
response = self.client.post(reverse("admin2:files_captionedfile_create"),
params,
follow=True)
self.assertTrue(CaptionedFile.objects.filter(caption="some file").exists())
self.assertRedirects(response, reverse("admin2:files_captionedfile_index"))
def test_save_and_add_another_redirects_to_create(self):
"""
Tests that choosing 'Save and add another' from the model create
page redirects the user to the model create page.
"""
with open(fixture_file, 'r') as fp:
params = {
"caption": "some file",
"publication": fp,
"_addanother": ""
}
response = self.client.post(reverse("admin2:files_captionedfile_create"),
params)
self.assertTrue(CaptionedFile.objects.filter(caption="some file").exists())
self.assertRedirects(response, reverse("admin2:files_captionedfile_create"))
def test_save_and_continue_editing_redirects_to_update(self):
"""
Tests that choosing "Save and continue editing" redirects
the user to the model update form.
"""
with open(fixture_file, 'r') as fp:
params = {
"caption": "some file",
"publication": fp,
"_continue": ""
}
response = self.client.post(reverse("admin2:files_captionedfile_create"),
params)
captioned_file = CaptionedFile.objects.get(caption="some file")
self.assertRedirects(response, reverse("admin2:files_captionedfile_update",
args=(captioned_file.pk, )))
class CaptionedFileDeleteViewTest(BaseIntegrationTest):
def test_view_ok(self):
captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
response = self.client.get(reverse("admin2:files_captionedfile_delete",
args=(captioned_file.pk, )))
self.assertContains(response, captioned_file.caption)
def test_delete_captioned_file(self):
captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
response = self.client.post(reverse("admin2:files_captionedfile_delete",
args=(captioned_file.pk, )))
self.assertRedirects(response, reverse("admin2:files_captionedfile_index"))
self.assertFalse(CaptionedFile.objects.filter(pk=captioned_file.pk).exists())
class FileDeleteActionTest(BaseIntegrationTest):
"""
Tests the behaviour of the 'Delete selected items' action.
"""
def test_confirmation_page(self):
cf1 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
cf2 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
params = {
'action': 'DeleteSelectedAction',
'selected_model_pk': [cf1.pk, cf2.pk]
}
response = self.client.post(reverse("admin2:files_captionedfile_index"),
params)
self.assertContains(response, cf1.caption)
self.assertContains(response, cf2.caption)
def test_results_page(self):
cf1 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
cf2 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file)
params = {
'action': 'DeleteSelectedAction',
'selected_model_pk': [cf1.pk, cf2.pk],
'confirmed': 'yes'
}
response = self.client.post(reverse("admin2:files_captionedfile_index"),
params, follow=True)
self.assertContains(response, "Successfully deleted 2 Captioned Files")

1
example/files/views.py Normal file
View file

@ -0,0 +1 @@
# Create your views here.

View file

@ -10,7 +10,7 @@ from django.test.utils import get_runner
from django.conf import settings
def runtests(tests=('blog', 'djadmin2',)):
def runtests(tests=('blog', 'files', 'djadmin2')):
'''
Takes a list as first argument, enumerating the apps and specific testcases
that should be executed. The syntax is the same as for what you would pass