Skip to content

Commit

Permalink
ImportMixin does not show button for user w/o add permission (test fa…
Browse files Browse the repository at this point in the history
…ils)
  • Loading branch information
Antonia Blair committed Feb 24, 2016
1 parent 0fd9df7 commit 5998707
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions tests/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib import admin

from import_export.admin import ImportExportMixin, ExportActionModelAdmin
from import_export.admin import ImportExportMixin, ImportMixin, ExportActionModelAdmin

from .models import Book, Category, Author

Expand All @@ -14,6 +14,10 @@ class BookAdmin(ImportExportMixin, admin.ModelAdmin):
class CategoryAdmin(ExportActionModelAdmin):
pass


class AuthorAdmin(ImportMixin, admin.ModelAdmin):
pass

admin.site.register(Book, BookAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Author)
admin.site.register(Author, AuthorAdmin)
16 changes: 14 additions & 2 deletions tests/core/tests/admin_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin.models import LogEntry

from core.admin import BookAdmin
from core.models import Category
from core.admin import BookAdmin, AuthorAdmin
from core.models import Category, Author


class ImportExportAdminIntegrationTest(TestCase):
Expand Down Expand Up @@ -86,6 +86,18 @@ def test_import_export_buttons_visible_without_add_permission(self):
self.assertContains(response, _('Export'))
self.assertContains(response, _('Import'))

def test_import_buttons_visible_without_add_permission(self):
# When using ImportMixin, users should be able to see the import button
# without add permission (to be consistent with ImportExportMixin)

original = AuthorAdmin.has_add_permission
AuthorAdmin.has_add_permission = lambda self, request: False
response = self.client.get('/admin/core/author/')
AuthorAdmin.has_add_permission = original

self.assertContains(response, _('Import'))
self.assertTemplateUsed(response, 'admin/import_export/change_list.html')

def test_import_file_name_in_tempdir(self):
# 65 - import_file_name form field can be use to access the filesystem
import_file_name = os.path.join(
Expand Down

0 comments on commit 5998707

Please sign in to comment.