Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin UI 1675 #1691

Merged
merged 13 commits into from
Nov 25, 2023
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ The following is a list of much appreciated contributors:
* christophehenry (Christophe Henry)
* bgelov (Oleg Belov)
* EricOuma (Eric Ouma)
* RobTilton (Robert Tilton)
4 changes: 3 additions & 1 deletion import_export/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ def add_success_message(self, result, request):
opts = self.model._meta

success_message = _(
"Import finished, with {} new and " "{} updated {}."
"Import complete: {} new, {} updated, {} deleted and {} skipped {}"
RobTilton marked this conversation as resolved.
Show resolved Hide resolved
).format(
result.totals[RowResult.IMPORT_TYPE_NEW],
result.totals[RowResult.IMPORT_TYPE_UPDATE],
result.totals[RowResult.IMPORT_TYPE_DELETE],
result.totals[RowResult.IMPORT_TYPE_SKIP],
opts.verbose_name_plural,
)

Expand Down
89 changes: 74 additions & 15 deletions tests/core/tests/test_admin_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,66 @@ def test_import(self):
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
_("Import finished, with {} new and {} updated {}.").format(
1, 0, Book._meta.verbose_name_plural
_(
"Import complete: {} new, {} updated, {} deleted and" + " {} skipped {}"
).format(1, 0, 0, 0, Book._meta.verbose_name_plural),
)

def test_import_for_deletion(self):
# GET the import form
response = self.client.get(self.book_import_url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "admin/import_export/import.html")
self.assertContains(response, 'form action=""')

# Simulate POST of books.csv
response = self._do_import_post(self.book_import_url, "books.csv")
self.assertEqual(response.status_code, 200)
self.assertIn("result", response.context)
self.assertFalse(response.context["result"].has_errors())
self.assertIn("confirm_form", response.context)
confirm_form = response.context["confirm_form"]

# Varify data, POST to DB, Generate Banner.
data = confirm_form.initial
self.assertEqual(data["original_file_name"], "books.csv")
response = self.client.post(self.book_process_import_url, data, follow=True)
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
_(
"Import complete: {} new, {} updated, {} deleted and" + " {} skipped {}"
).format(1, 0, 0, 0, Book._meta.verbose_name_plural),
)

# GET the import form
response = self.client.get(self.book_import_url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "admin/import_export/import.html")
self.assertContains(response, 'form action=""')

# Simulate POST of books-for-delete.csv
response = self._do_import_post(self.book_import_url, "books-for-delete.csv")
self.assertEqual(response.status_code, 200)
self.assertIn("result", response.context)
self.assertFalse(response.context["result"].has_errors())
self.assertIn("confirm_form", response.context)
confirm_form = response.context["confirm_form"]

# Varify data, POST to DB, Generate Banner.
data = confirm_form.initial
self.assertEqual(data["original_file_name"], "books-for-delete.csv")
response = self.client.post(self.book_process_import_url, data, follow=True)
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
_(
"Import complete: {} new, {} updated, {} deleted and" + " {} skipped "
).format(
0,
0,
1,
0,
),
)

Expand Down Expand Up @@ -215,9 +273,9 @@ def test_import_second_resource(self):
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
_("Import finished, with {} new and {} updated {}.").format(
0, 1, Book._meta.verbose_name_plural
),
_(
"Import complete: 0 new, 1 updated, 0 deleted and 0 skipped books"
).format(0, 1, 0, 0, Book._meta.verbose_name_plural),
)
# Check, that we really use second resource - author_email didn't get imported
self.assertEqual(Book.objects.get(id=1).author_email, "")
Expand Down Expand Up @@ -254,7 +312,8 @@ def test_import_legacy_book(self):
)
self.assertEqual(response.status_code, 200)
self.assertContains(
response, "Import finished, with 0 new and 1 updated legacy books."
response,
"Import complete: 1 new, 0 updated, 0 deleted and 0 skipped legacy books",
)

def test_export_admin_action(self):
Expand Down Expand Up @@ -395,8 +454,8 @@ def test_import_mac(self):
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
_("Import finished, with {} new and {} updated {}.").format(
1, 0, Book._meta.verbose_name_plural
_("Import complete: 1 new, 0 updated, 0 deleted and 0 skipped").format(
1, 0, 0, 0, EBook._meta.verbose_name_plural
),
)

Expand Down Expand Up @@ -509,8 +568,8 @@ def test_import_with_customized_forms(self):
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
_("Import finished, with {} new and {} updated {}.").format(
1, 0, EBook._meta.verbose_name_plural
_("Import complete: 1 new, 0 updated, 0 deleted and 0 skipped").format(
1, 0, 0, 0, EBook._meta.verbose_name_plural
),
)

Expand Down Expand Up @@ -918,7 +977,7 @@ def _is_str_in_response(self, filename, input_format, encoding=None):

self.assertEqual(response.status_code, 200)
self.assertContains(
response, "Import finished, with 1 new and 0 updated books."
response, "Import complete: 1 new, 0 updated, 0 deleted and 0 skipped books"
)

@override_settings(
Expand Down Expand Up @@ -1402,7 +1461,7 @@ def test_import_action_create(self):
"books.csv",
"0",
follow=True,
str_in_response="Import finished, with 1 new and 0 updated books.",
str_in_response="Import complete: 1 new, 0 updated, 0 deleted and 0 skipped books",
)
self.assertEqual(1, Book.objects.count())

Expand Down Expand Up @@ -1468,7 +1527,7 @@ def test_import_action_mac(self):
"books-mac.csv",
"0",
follow=True,
str_in_response="Import finished, with 1 new and 0 updated books.",
str_in_response="Import complete: 1 new, 0 updated, 0 deleted and 0 skipped books",
)

def test_import_action_iso_8859_1(self):
Expand All @@ -1477,7 +1536,7 @@ def test_import_action_iso_8859_1(self):
"0",
"ISO-8859-1",
follow=True,
str_in_response="Import finished, with 1 new and 0 updated books.",
str_in_response="Import complete: 1 new, 0 updated, 0 deleted and 0 skipped books",
)

def test_import_action_decode_error(self):
Expand All @@ -1497,5 +1556,5 @@ def test_import_action_binary(self):
"books.xls",
"1",
follow=True,
str_in_response="Import finished, with 1 new and 0 updated books.",
str_in_response="Import complete: 1 new, 0 updated, 0 deleted and 0 skipped books",
)