Skip to content

Commit

Permalink
Merge 1760450 into 5e76e6c
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTilton committed Jan 30, 2024
2 parents 5e76e6c + 1760450 commit 5712d41
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Expand Up @@ -7,7 +7,7 @@ Changelog
- Pass :meth:`~import_export.mixins.BaseExportMixin.get_export_resource_kwargs` to Resource constructor
:meth:`~import_export.admin.ExportMixin.export_action` (#1739)
- Fix issue with model class passed to Resource constructor crashing on export (#1745)

- Unit and integration test for changes to BaseImportExportMixin.get_resource_kwargs added (#1749)
3.3.6 (2024-01-10)
------------------

Expand Down
2 changes: 1 addition & 1 deletion import_export/mixins.py
Expand Up @@ -63,7 +63,7 @@ def get_resource_classes(self):
return [self.resource_class]

def get_resource_kwargs(self, request, *args, **kwargs):
return {}
return kwargs

def get_resource_index(self, form):
resource_index = 0
Expand Down
17 changes: 17 additions & 0 deletions tests/core/tests/test_admin_integration.py
Expand Up @@ -38,6 +38,7 @@
)
from import_export.formats import base_formats
from import_export.formats.base_formats import DEFAULT_FORMATS
from import_export.resources import ModelResource
from import_export.tmp_storages import TempFolderStorage


Expand Down Expand Up @@ -122,6 +123,22 @@ def test_import_export_template(self):
self.assertContains(response, _("Export"))
self.assertContains(response, "Custom change list item")

@patch("import_export.admin.ImportMixin.choose_import_resource_class")
def test_import_passes_correct_kwargs_to_constructor(
self, mock_choose_import_resource_class
):
class TestResource(ModelResource):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.kwargs = kwargs
if "form" not in kwargs:
raise Exception("No form")

mock_choose_import_resource_class.return_value = TestResource

response = self._do_import_post(self.book_import_url, "books.csv")
self.assertEqual(response.status_code, 200)

@override_settings(TEMPLATE_STRING_IF_INVALID="INVALID_VARIABLE")
def test_import(self):
# GET the import form
Expand Down
13 changes: 13 additions & 0 deletions tests/core/tests/test_mixins.py
Expand Up @@ -372,3 +372,16 @@ def test_get_export_form(self):
def test_get_export_form_with_custom_form(self):
m = self.TestExportMixin(self.TestExportForm)
self.assertEqual(self.TestExportForm, m.get_export_form())


class BaseExportImportMixinTest(TestCase):
class TestMixin(mixins.BaseImportExportMixin):
pass

def test_get_resource_kwargs(self):
mixin_instance = self.TestMixin()
test_kwargs = {"key1": "value1", "key2": "value2"}

result = mixin_instance.get_resource_kwargs(HttpRequest, **test_kwargs)

self.assertEqual(result, test_kwargs)

0 comments on commit 5712d41

Please sign in to comment.