Răsfoiți Sursa

HUE-8737 [core] Fix desktop unit tests in py3

Ying Chen 5 ani în urmă
părinte
comite
944db9af44

+ 1 - 1
desktop/core/src/desktop/lib/django_util_test.py

@@ -124,7 +124,7 @@ class TestDjangoUtil(object):
     pass
 
   def test_render_json_jsonp(self):
-    assert_equal("foo(3);", django_util.render_json(3, jsonp_callback="foo").content)
+    assert_equal(b"foo(3);", django_util.render_json(3, jsonp_callback="foo").content)
 
   def test_render_json_jsonp_bad_name(self):
     # Bad names

+ 2 - 2
desktop/core/src/desktop/tests.py

@@ -90,7 +90,7 @@ def test_home():
   user = User.objects.get(username="test_home")
 
   response = c.get(reverse(home))
-  assert_equal(["notmine", "trash", "mine", "history"], list(json.loads(response.context[0]['json_tags']).keys()))
+  assert_equal(sorted(["notmine", "trash", "mine", "history"]), sorted(list(json.loads(response.context[0]['json_tags']).keys())))
   assert_equal(200, response.status_code)
 
   from pig.models import PigScript
@@ -362,7 +362,7 @@ def test_status_bar():
   views.register_status_bar_view(f)
 
   response = c.get("/desktop/status_bar")
-  assert_equal("foobar", response.content)
+  assert_equal(b"foobar", response.content)
 
   views._status_bar_views = backup
 

+ 2 - 2
desktop/core/src/desktop/views.py

@@ -215,7 +215,7 @@ def download_log_view(request):
         # in case it is rather big. So we write it to a file line by line
         # and pass that file to zipfile, which might follow a more efficient path.
         tmp = tempfile.NamedTemporaryFile()
-        log_tmp = tempfile.NamedTemporaryFile("w+t")
+        log_tmp = tempfile.NamedTemporaryFile("w+t") if sys.version_info[0] == 2 else tempfile.NamedTemporaryFile("w+t", encoding='utf-8')
         for l in h.buf:
           log_tmp.write(smart_str(l, errors='replace') + '\n')
         # This is not just for show - w/out flush, we often get truncated logs
@@ -267,7 +267,7 @@ def status_bar(request):
   Concatenates multiple views together to build up a "status bar"/"status_bar".
   These views are registered using register_status_bar_view above.
   """
-  resp = ""
+  resp = b""
   for view in _status_bar_views:
     try:
       r = view(request)