Эх сурвалжийг харах

[core] Fix dump_config tests by testing an app setting instead of desktop

With the loading of the desktop config first done when adding the
app blacklist, the set_for_testing() seems to be lost when dumping
the global setting variable.
This is only on the dump_config page which uses the global variable.
set_for_testing() continues to work fine in apps, desktop or libs.

Just indentation cleaning on the dump_config template.
Romain Rigaux 11 жил өмнө
parent
commit
30dd3c48b7

+ 1 - 2
desktop/core/src/desktop/lib/conf.py

@@ -430,8 +430,7 @@ class ConfigSection(Config):
 
     # We sort the configuration for canonicalization.
     for programmer_key, config in sorted(self.members.iteritems(), key=lambda x: x[1].key):
-      config.print_help(out=out,
-                        indent=new_indent)
+      config.print_help(out=out, indent=new_indent)
 
 class UnspecifiedConfigSection(Config):
   """

+ 26 - 25
desktop/core/src/desktop/templates/dump_config.mako

@@ -62,20 +62,22 @@ ${layout.menubar(section='dump_config')}
         </div>
 
         <div class="card card-home">
-            <h2 class="card-heading simple">${_('Configuration Sections and Variables')}</h2>
+          <h2 class="card-heading simple">${_('Configuration Sections and Variables')}</h2>
           <div class="card-body">
             <p>
-            <ul class="nav nav-tabs">
-              % for obj in top_level:
-                <li
-                  % if loop.first:
-                      class="active"
-                  % endif
-                ><a href="#${obj.config.key}Conf" data-toggle="tab">${obj.config.key}</a></li>
-              % endfor
-            </ul>
+              <ul class="nav nav-tabs">
+                % for obj in top_level:
+                  <li
+                    % if loop.first:
+                        class="active"
+                    % endif
+                  >
+                    <a href="#${ obj.config.key }Conf" data-toggle="tab">${ obj.config.key }</a>
+                  </li>
+                % endfor
+              </ul>
 
-            ${showTopLevel(top_level)}
+              ${showTopLevel(top_level)}
 
               <br/>
               <br/>
@@ -86,7 +88,6 @@ ${layout.menubar(section='dump_config')}
 
       </div>
 
-
         <%def name="showTopLevel(config_obj, depth=0)">
             <div class="tab-content">
                 % for v in config_obj:
@@ -100,7 +101,7 @@ ${layout.menubar(section='dump_config')}
                         active
                     % endif
                     ">
-                    ${recurse(v, depth + 1)}
+                    ${ recurse(v, depth + 1) }
                   </div>
                 % endfor
             </div>
@@ -109,12 +110,12 @@ ${layout.menubar(section='dump_config')}
         <%def name="recurseList(config_obj, depth=0)">
           <table class="table table-striped recurse">
           % for v in config_obj:
-              <%
-                # Don't recurse into private variables.
-                if v.config.private and not show_private:
-                  continue
-              %>
-              ${recurse(v, depth + 1)}
+            <%
+              # Don't recurse into private variables.
+              if v.config.private and not show_private:
+                continue
+            %>
+            ${ recurse(v, depth + 1) }
           % endfor
           </table>
         </%def>
@@ -126,22 +127,22 @@ ${layout.menubar(section='dump_config')}
               % if is_anonymous(config_obj.config.key):
                 <i>(default section)</i>
               % else:
-                ${config_obj.config.key}
+                ${ config_obj.config.key }
               % endif
               </th>
              % endif
              % if depth == 1:
                 <td style="border-top:0">
              % else:
-                  <td>
+                <td>
              % endif
               % if isinstance(config_obj, BoundContainer):
-                  <p class="dump_config_help"><i>${config_obj.config.help or _('No help available.')}</i></p>
-                  ${recurseList(config_obj.get().values(), depth + 1)}
+                <p class="dump_config_help"><i>${ config_obj.config.help or _('No help available.') }</i></p>
+                ${ recurseList(config_obj.get().values(), depth + 1) }
               % else:
                 <p>${ str(config_obj.get_raw()).decode('utf-8', 'replace') }</p>
-                <p class="dump_config_help"><i>${config_obj.config.help or _('No help available.')}</i></p>
-                <p class="dump_config_default">${_('Default:')} <i>${str(config_obj.config.default).decode('utf-8', 'replace')}</i></p>
+                <p class="dump_config_help"><i>${ config_obj.config.help or _('No help available.') }</i></p>
+                <p class="dump_config_default">${ _('Default:') } <i>${ str(config_obj.config.default).decode('utf-8', 'replace') }</i></p>
               % endif
               </td>
             </tr>

+ 6 - 3
desktop/core/src/desktop/tests.py

@@ -45,6 +45,7 @@ from desktop.lib.django_util import TruncatingModel
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.test_utils import grant_access
 from desktop.views import check_config, home
+from beeswax.conf import HIVE_SERVER_HOST
 
 
 def setup_test_environment():
@@ -153,10 +154,12 @@ def test_dump_config():
   c = make_logged_in_client()
 
   CANARY = "abracadabra"
-  clear = desktop.conf.HTTP_HOST.set_for_testing(CANARY)
+
+  # Depending on the order of the conf.initialize() in settings, the set_for_testing() are not seen in the global settings variable
+  clear = HIVE_SERVER_HOST.set_for_testing(CANARY)
 
   response1 = c.get(reverse('desktop.views.dump_config'))
-  assert_true(CANARY in response1.content)
+  assert_true(CANARY in response1.content, response1.content)
 
   response2 = c.get(reverse('desktop.views.dump_config'), dict(private="true"))
   assert_true(CANARY in response2.content)
@@ -176,7 +179,7 @@ def test_dump_config():
 
   # Malformed port per HUE-674
   CANARY = "asdfoijaoidfjaosdjffjfjaoojosjfiojdosjoidjfoa"
-  clear = desktop.conf.HTTP_PORT.set_for_testing(CANARY)
+  clear = HIVE_SERVER_HOST.set_for_testing(CANARY)
 
   response1 = c.get(reverse('desktop.views.dump_config'))
   assert_true(CANARY in response1.content, response1.content)