diff --git a/django_dump_die/test_urls.py b/django_dump_die/test_urls.py index 5c9f1bb8f4ef4e14669af9b3a2dd34c612c82cad..f45683d74c6c80087bba9e77ace7e662a2197c56 100644 --- a/django_dump_die/test_urls.py +++ b/django_dump_die/test_urls.py @@ -13,6 +13,7 @@ from .views.test_views import ( complex_type_example__tuple, complex_type_example__list, complex_type_example__dict, + complex_type_example__querydict, complex_type_example__memory_view, complex_type_example__enum, @@ -37,6 +38,7 @@ urlpatterns = [ path('complex/tuple/', complex_type_example__tuple, name='complex__tuple'), path('complex/list/', complex_type_example__list, name='complex__list'), path('complex/dict/', complex_type_example__dict, name='complex__dict'), + path('complex/querydict/', complex_type_example__querydict, name='complex__querydict'), path('complex/memory_view/', complex_type_example__memory_view, name='complex__memory_view'), path('complex/enum/', complex_type_example__enum, name='complex__enum'), diff --git a/django_dump_die/views/example_helpers.py b/django_dump_die/views/example_helpers.py index 21b9ccd49b2b38c778eee779976cd5cc8cde3d65..693f470b6e525650bbde92e7303ef83a48baafad 100644 --- a/django_dump_die/views/example_helpers.py +++ b/django_dump_die/views/example_helpers.py @@ -526,6 +526,13 @@ class dump_complex_types(): # Dump variable. dump(sample_dict) + def dump_querydict(self): + # Generate variables to dump. + sample_querydict = QueryDict('first="A"&second=12&third=True&first="B"&first="C"') + + # Dump variable. + dump(sample_querydict) + def dump_enum(self): # Dump variable. dump(SampleEnum) @@ -582,6 +589,7 @@ class dump_complex_types(): self.dump_tuple() self.dump_list() self.dump_dict() + self.dump_querydict() self.dump_memory_view() self.dump_enum() diff --git a/django_dump_die/views/test_views.py b/django_dump_die/views/test_views.py index 09880d3005c82fac75a7dd1ce2df5a784385e4b3..f5c91fbf65bb8365104d97c2a9f05b73f4520196 100644 --- a/django_dump_die/views/test_views.py +++ b/django_dump_die/views/test_views.py @@ -117,6 +117,27 @@ def complex_type_example__dict(request): return render(request, 'django_dump_die/sample.html', {}) +def complex_type_example__querydict(request): + """Example view, rendering only "complex type" QueryDict object output.""" + + # Import applicable helper functions/classes. + # Imported here so that these are only loaded on view access, and not package initialization. + from .example_helpers import dump_complex_types + + # Output desired dump values. + dump('Displaying example of "complex type" QueryDict object output.') + dump('') + dump_complex_types().dump_querydict() + dump('') + dump('') + + # Force dd to prevent further view parsing. + dd('done') + + # Show that any calls after dd() end up ignored. + return render(request, 'django_dump_die/sample.html', {}) + + def complex_type_example__memory_view(request): """Example view, rendering only "complex type" MemoryView object output.""" diff --git a/tests/test_views/test_complex_type.py b/tests/test_views/test_complex_type.py index 81c3681a5ed73530a639fa2ee8215d2eb0891025..3312b2c0b1ee931862e742121a7e73b01036884a 100644 --- a/tests/test_views/test_complex_type.py +++ b/tests/test_views/test_complex_type.py @@ -682,6 +682,234 @@ class DumpDieComplexTypeTestCase(IntegrationTestCase): content_ends_before="""<span class="string">'done'</span>""", ) + @patch('django_dump_die.templatetags.dump_die._generate_unique') + def test_querydict_display(self, mocked_unique_generation): + """Verify dumping a "querydict" type has expected output.""" + + # Override url, to use testing-specific view, which will only display a single object. + self.url = 'django_dump_die_tests:complex__querydict' + + # Override default "unique" generation logic, for reproduce-able tests. + # This generates enough uniques to guarantee mock does not raise errors. + side_effects = [] + for index in range(5000): + side_effects += [ + (f'data_900{index}', ''), + ] + mocked_unique_generation.side_effect = side_effects + + self.assertGetResponse( + self.url, + expected_title='DD', + expected_header='Django DumpDie', + expected_content=[ + '<hr>', + + # Object opening tags. + """ + <div class="dump-wrapper"> + <span class="dumped_object" title="Dumped Object"> + <span class="dumped_name">sample_querydict</span> + </span>: + <span class="type" title="QueryDict">QueryDict:3</span> + <span class="braces">{</span> + <a + class="arrow-toggle collapsed" + title="[Ctrl+click] Expand all children" + data-toggle="collapse" + data-target=".data_9002" + data-dd-type="type" + data-object-depth="1" + aria-label="Close" + aria-expanded="false" + > + <span class="unique" data-highlight-unique="data_9002">data_9002</span> + <span id="arrow-data_9002" class="arrow arrow-data_9002">â–¶</span> + </a> + <div class="dd-wrapper collapse data_9002 " data-unique="data_9002"> + <ul class="attribute-list"> + <a + class="arrow-toggle show always-show" + title="[Ctrl+click] Expand all children" + data-target=".data_9002-attributes" + data-dd-type="attr" + aria-label="Open/Close" + aria-expanded="" + > + <span class="section_name">Attributes</span> + <span id="arrow-data_9002-attributes" class="arrow"> + </span> + </a> + <div + class="li-wrapper collapse data_9002-attributes show" + data-unique-attributes="data_9002-attributes" + > + """, + + # Object child elements. + """ + <li> + <span class="key" title="Key">'first'</span>: + <span class="type" title="list">list:3</span> + <span class="braces">[</span> + <a + class="arrow-toggle collapsed" + title="[Ctrl+click] Expand all children" + data-toggle="collapse" + data-target=".data_9004" + data-dd-type="type" + data-object-depth="2" + aria-label="Close" + aria-expanded="false" + > + <span class="unique" data-highlight-unique="data_9004">data_9004</span> + <span id="arrow-data_9004" class="arrow arrow-data_9004">â–¶</span> + </a> + <div class="dd-wrapper collapse data_9004 " data-unique="data_9004"> + <ul class="attribute-list"> + <a + class="arrow-toggle show always-show" + title="[Ctrl+click] Expand all children" + data-target=".data_9004-attributes" + data-dd-type="attr" + aria-label="Open/Close" + aria-expanded="" + > + <span class="section_name">Attributes</span> + <span id="arrow-data_9004-attributes" class="arrow"></span> + </a> + <div + class="li-wrapper collapse data_9004-attributes show" + data-unique-attributes="data_9004-attributes" + > + <li> + <span class="index" title="Index">0</span>: + <span class="type" title="str">str</span> <code class="string">'"A"'</code> + </li> + <li> + <span class="index" title="Index">1</span>: + <span class="type" title="str">str</span> <code class="string">'"B"'</code> + </li> + <li> + <span class="index" title="Index">2</span>: + <span class="type" title="str">str</span> <code class="string">'"C"'</code> + </li> + </div> + </ul> + <ul class="attribute-list"></ul> + </div> + <span class="braces">]</span> + </li> + """, + """ + <li> + <span class="key" title="Key">'second'</span>: + <span class="type" title="list">list:1</span> + <span class="braces">[</span> + <a + class="arrow-toggle collapsed" + title="[Ctrl+click] Expand all children" + data-toggle="collapse" + data-target=".data_9008" + data-dd-type="type" + data-object-depth="2" + aria-label="Close" + aria-expanded="false" + > + <span class="unique" data-highlight-unique="data_9008">data_9008</span> + <span id="arrow-data_9008" class="arrow arrow-data_9008">â–¶</span> + </a> + <div class="dd-wrapper collapse data_9008 " data-unique="data_9008"> + <ul class="attribute-list"> + <a + class="arrow-toggle show always-show" + title="[Ctrl+click] Expand all children" + data-target=".data_9008-attributes" + data-dd-type="attr" + aria-label="Open/Close" + aria-expanded="" + > + <span class="section_name">Attributes</span> + <span id="arrow-data_9008-attributes" class="arrow"></span> + </a> + <div + class="li-wrapper collapse data_9008-attributes show" + data-unique-attributes="data_9008-attributes" + > + <li> + <span class="index" title="Index">0</span>: + <span class="type" title="str">str</span> <code class="string">'12'</code> + </li> + </div> + </ul> + <ul class="attribute-list"></ul> + </div> + <span class="braces">]</span> + </li> + """, + """ + <li> + <span class="key" title="Key">'third'</span>: + <span class="type" title="list">list:1</span> + <span class="braces">[</span> + <a + class="arrow-toggle collapsed" + title="[Ctrl+click] Expand all children" + data-toggle="collapse" + data-target=".data_90010" + data-dd-type="type" + data-object-depth="2" + aria-label="Close" + aria-expanded="false" + > + <span class="unique" data-highlight-unique="data_90010">data_90010</span> + <span id="arrow-data_90010" class="arrow arrow-data_90010">â–¶</span> + </a> + <div class="dd-wrapper collapse data_90010 " data-unique="data_90010"> + <ul class="attribute-list"> + <a + class="arrow-toggle show always-show" + title="[Ctrl+click] Expand all children" + data-target=".data_90010-attributes" + data-dd-type="attr" + aria-label="Open/Close" + aria-expanded="" + > + <span class="section_name">Attributes</span> + <span id="arrow-data_90010-attributes" class="arrow"></span> + </a> + <div + class="li-wrapper collapse data_90010-attributes show" + data-unique-attributes="data_90010-attributes" + > + <li> + <span class="index" title="Index">0</span>: + <span class="type" title="str">str</span> <code class="string">'True'</code> + </li> + </div> + </ul> + <ul class="attribute-list"></ul> + </div> + <span class="braces">]</span> + </li> + """, + + # Object closing tags. + """ + </div> + </ul> + <ul class="attribute-list"></ul> + </div> + <span class="braces">}</span> + </div> + """, + + '<hr>', + ], + content_starts_after='Displaying example of "complex type" QueryDict object output.', + content_ends_before="""<span class="string">'done'</span>""", + ) + @patch('django_dump_die.templatetags.dump_die._generate_unique') def test_memory_view_display(self, mocked_unique_generation): """Verify dumping a "memory view" type has expected output."""