From 5f26ceb4cf4720283228388e7a631086472d9f86 Mon Sep 17 00:00:00 2001
From: Paul Marillonnet <pmarillonnet@entrouvert.com>
Date: Thu, 3 Jun 2021 17:21:42 +0200
Subject: [PATCH] export_site: do not enfore ascii-escaping in json output
 (#54570)

---
 combo/data/management/commands/export_site.py |  2 +-
 tests/test_import_export.py                   | 21 +++++++++++--------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/combo/data/management/commands/export_site.py b/combo/data/management/commands/export_site.py
index 14d78516..43dbe329 100644
--- a/combo/data/management/commands/export_site.py
+++ b/combo/data/management/commands/export_site.py
@@ -40,7 +40,7 @@ class Command(BaseCommand):
                 output = open(options['output'], 'w')
             else:
                 output = sys.stdout
-            json.dump(export_site(), output, indent=2)
+            json.dump(export_site(), output, indent=2, ensure_ascii=False)
         else:
             if options['output'] and options['output'] != '-':
                 try:
diff --git a/tests/test_import_export.py b/tests/test_import_export.py
index 22c875a0..b24023ea 100644
--- a/tests/test_import_export.py
+++ b/tests/test_import_export.py
@@ -33,6 +33,7 @@ def some_data():
     Page.objects.create(title='One', slug='one')
     Page.objects.create(title='Two', slug='two')
     page = Page.objects.create(title='Three', slug='three')
+    Page.objects.create(title='Štiri', slug='four')
     cell = TextCell(page=page, order=0, text='hello world', placeholder='content')
     cell.save()
 
@@ -59,7 +60,9 @@ def get_output_of_command(command, *args, **kwargs):
 
 def test_import_export(app, some_data):
     output = get_output_of_command('export_site')
-    assert len(json.loads(output)['pages']) == 3
+    # test no ascii escape
+    assert not '\\u' in output
+    assert len(json.loads(output)['pages']) == 4
     import_site(data={}, clean=True)
     assert Page.objects.all().count() == 0
     assert TextCell.objects.all().count() == 0
@@ -81,11 +84,11 @@ def test_import_export(app, some_data):
         f.flush()
         call_command('import_site', f.name)
 
-    assert Page.objects.count() == 3
+    assert Page.objects.count() == 4
     assert TextCell.objects.all().count() == 1
 
     import_site(data={}, if_empty=True)
-    assert Page.objects.count() == 3
+    assert Page.objects.count() == 4
     assert TextCell.objects.all().count() == 1
 
     import_site(data=[], clean=True)
@@ -103,7 +106,7 @@ def test_import_export_with_parent(app, some_data):
     Page.objects.all().delete()
     import_site(data=payload)
 
-    assert Page.objects.count() == 3
+    assert Page.objects.count() == 4
     two = Page.objects.get(slug='two')
     assert two.parent.slug == 'one'
 
@@ -117,7 +120,7 @@ def test_import_export_with_unknown_parent(app, some_data):
     Page.objects.all().delete()
     import_site(data=payload)
 
-    assert Page.objects.count() == 3
+    assert Page.objects.count() == 4
     for page in Page.objects.all():
         assert page.parent is None
     one = Page.objects.get(slug='one')
@@ -128,7 +131,7 @@ def test_backward_compatibility_import(app, some_data):
     old_export = Page.export_all_for_json()
     Page.objects.all().delete()
     import_site(data=old_export)
-    assert Page.objects.count() == 3
+    assert Page.objects.count() == 4
 
 
 def test_import_export_map_layers(app, some_map_layers):
@@ -202,7 +205,7 @@ def test_group_restrictions_import_export(app, some_data):
     cell.save()
 
     output = get_output_of_command('export_site')
-    assert len(json.loads(output)['pages']) == 3
+    assert len(json.loads(output)['pages']) == 4
     import_site(data={}, clean=True)
     assert Page.objects.all().count() == 0
     assert TextCell.objects.all().count() == 0
@@ -225,7 +228,7 @@ def test_group_restrictions_import_export(app, some_data):
     group.save()
 
     import_site(json.loads(output), clean=True)
-    assert Page.objects.all().count() == 3
+    assert Page.objects.all().count() == 4
     assert TextCell.objects.all().count() == 1
 
     page = Page.objects.get(slug='one')
@@ -367,7 +370,7 @@ def test_import_export_extra_fields(app, some_data):
             page['cells'][0]['fields']['extra_field_not_in_model'] = True
 
     import_site(site_export)
-    assert Page.objects.count() == 3
+    assert Page.objects.count() == 4
     assert TextCell.objects.count() == 1
 
 
-- 
2.32.0.rc0

