Skip to content

Commit 63bbdcd

Browse files
committed
Move forms tests from test_utils -> tests_forms
1 parent a6c71fd commit 63bbdcd

2 files changed

Lines changed: 34 additions & 32 deletions

File tree

tests/test_forms.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from django.test import TestCase
2+
3+
from django_mongodb_extensions.debug_toolbar.panels.mql.forms import MQLAggregateForm
4+
5+
6+
class ConvertDocumentsToTableTests(TestCase):
7+
def setUp(self):
8+
self.form = MQLAggregateForm()
9+
10+
def test_empty_documents(self):
11+
"""Empty document list returns empty rows and headers."""
12+
rows, headers = self.form.convert_documents_to_table([])
13+
self.assertEqual(rows, [])
14+
self.assertEqual(headers, [])
15+
16+
def test_handle_operation_error_format(self):
17+
"""Error return format matches convert_documents_to_table format."""
18+
error = ValueError("Test error")
19+
mql_string = "db.test.aggregate([])"
20+
rows, headers = self.form._handle_operation_error(
21+
error, mql_string, "aggregate"
22+
)
23+
24+
# Should return one row with one cell
25+
self.assertEqual(len(rows), 1)
26+
self.assertEqual(len(rows[0]), 1)
27+
28+
# Cell should be a dict with 'value' and 'is_json' keys
29+
cell = rows[0][0]
30+
self.assertIsInstance(cell["value"], str)
31+
self.assertIs(cell["is_json"], False)
32+
33+
# Should have one header
34+
self.assertEqual(headers[0], "Query Parsing Error")

tests/test_utils.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,8 @@
11
from django.test import TestCase
22

3-
from django_mongodb_extensions.debug_toolbar.panels.mql.forms import MQLAggregateForm
43
from django_mongodb_extensions.debug_toolbar.panels.mql.utils import parse_query_args
54

65

7-
class ConvertDocumentsToTableTests(TestCase):
8-
def setUp(self):
9-
self.form = MQLAggregateForm()
10-
11-
def test_empty_documents(self):
12-
"""Empty document list returns empty rows and headers."""
13-
rows, headers = self.form.convert_documents_to_table([])
14-
self.assertEqual(rows, [])
15-
self.assertEqual(headers, [])
16-
17-
def test_handle_operation_error_format(self):
18-
"""Error return format matches convert_documents_to_table format."""
19-
error = ValueError("Test error")
20-
mql_string = "db.test.aggregate([])"
21-
rows, headers = self.form._handle_operation_error(
22-
error, mql_string, "aggregate"
23-
)
24-
25-
# Should return one row with one cell
26-
self.assertEqual(len(rows), 1)
27-
self.assertEqual(len(rows[0]), 1)
28-
29-
# Cell should be a dict with 'value' and 'is_json' keys
30-
cell = rows[0][0]
31-
self.assertIsInstance(cell["value"], str)
32-
self.assertIs(cell["is_json"], False)
33-
34-
# Should have one header
35-
self.assertEqual(headers[0], "Query Parsing Error")
36-
37-
386
class ParseQueryArgsTests(TestCase):
397
def test_unserializable_args(self):
408
"""None mql_args_json raises ValueError to prevent replaying a different query."""

0 commit comments

Comments
 (0)