Commits

Luke Plant  committed 366c5c6

Fixed broken error message for incorrect command order, and added test.

Also moved related assertions to the module level.

  • Participants
  • Parent commits 53e0e1b

Comments (0)

Files changed (2)

File semanticeditor/tests.py

         pres2 = {'newcol_p_1': [NEWROW]}
         self.assertRaises(BadStructure, format_html, html2, pres2)
 
+    def test_check_command_order(self):
+        """
+        Check that the user will be prompted if they try to use,
+        for example, a New Column command without a New row
+        """
+        html = "<h1>1</h1>"
+        pres = {'newcol_h1_1':[NEWCOL]}
+        self.assertRaises(BadStructure, format_html, html, pres)
+
     def test_columns_1(self):
         html = "<h1>1</h1><p>para 1</p><h1>2</h1><h1>3</h1>"
         outh = "<div class=\"row columns2\"><div class=\"column firstcolumn\"><div><h1>1</h1><p>para 1</p></div></div><div class=\"column lastcolumn\"><div><h1>2</h1><h1>3</h1></div></div></div>"

File semanticeditor/utils/presentation.py

                     command_level = command.layout_order
 
                     if command_level > current_level + 1:
+                        lowercommand = sorted_commands[command_level-1]
                         raise BadStructure('Section "%(sect)s" has command "%(command)s" '
                                            'but there needs to be a "%(lowercommand)s" '
                                            'command first.' %
                                            dict(sect=si.name,
-                                                command=command_name,
-                                                lowercommand=commands[command_level-1])
+                                                command=command.verbose_name,
+                                                lowercommand=lowercommand.verbose_name)
                                            )
 
                     if command_level <= current_level:
             # structure down.
             current_level += 1
             next_command = sorted_commands[current_level]
-            # Currently index in sorted_commands corresponds to layout_order
-            assert next_command.layout_order == current_level
             layout_container = next_command.layout_structure()
             # Currently this will always produce a command that accepts content
             assert layout_container.accepts_content
 COMMANDS = [NEWROW, NEWCOL, NEWINNERROW, NEWINNERCOL]
 
 sorted_commands = sorted(COMMANDS, key=lambda c: c.layout_order)
+
+for i, c in enumerate(sorted_commands):
+    # Several places that index sorted_commands make this assemption:
+    assert c.layout_order == i