Skip to content
Snippets Groups Projects
Commit e68aa938 authored by Alice Heaton's avatar Alice Heaton :speech_balloon:
Browse files

Update tests to match the new table widget functionality.

parent f6392a04
No related branches found
No related tags found
No related merge requests found
from mock import patch
from django.test import TestCase
from hid.widgets.table import TableWidget
......@@ -10,25 +13,45 @@ class TestTableWidget(TestCase):
)
self.assertEqual(context_data['title'], 'table title')
def test_context_data_includes_headers(self):
def test_get_context_data_invokes_api(self):
widget = TableWidget()
context_data = widget.get_context_data(
headers=['header one', 'header two']
)
self.assertEqual(context_data['headers'], [
'header one', 'header two'
])
with patch('hid.widgets.table.transport.items.list') as mock:
widget.get_context_data()
self.assertTrue(mock.called)
def test_context_data_includes_rows(self):
def test_get_context_data_invokes_api_with_filters(self):
widget = TableWidget()
with patch('hid.widgets.table.transport.items.list') as mock:
widget.get_context_data(filters={'a': 'b'})
self.assertEquals(mock.call_args[1], {'a': 'b'})
context_data = widget.get_context_data(
rows=[
['row one, col one', 'row one, col two'],
['row two, col one', 'row two, col two']
]
)
self.assertEqual(context_data['rows'], [
['row one, col one', 'row one, col two'],
['row two, col one', 'row two, col two']
])
def test_get_context_data_limits_rows_as_per_settings(self):
widget = TableWidget()
with patch('hid.widgets.table.transport.items.list') as mock:
mock.return_value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
with patch('hid.widgets.table.ItemTable') as mock_table:
widget.get_context_data(count=3)
processed_rows = mock_table.call_args[0][0]
self.assertEqual(len(processed_rows), 3)
def test_get_context_data_orders_rows_as_per_settings(self):
widget = TableWidget()
with patch('hid.widgets.table.transport.items.list') as mock:
mock.return_value = [{'a': 1}, {'a': 4}, {'a': 2}]
with patch('hid.widgets.table.ItemTable') as mock_table:
widget.get_context_data(order_by='a')
processed_rows = mock_table.call_args[0][0]
self.assertEqual(processed_rows, [
{'a': 1}, {'a': 2}, {'a': 4}
])
def test_get_context_data_orders_row_reverse_as_per_settings(self):
widget = TableWidget()
with patch('hid.widgets.table.transport.items.list') as mock:
mock.return_value = [{'a': 1}, {'a': 4}, {'a': 2}]
with patch('hid.widgets.table.ItemTable') as mock_table:
widget.get_context_data(order_by='-a')
processed_rows = mock_table.call_args[0][0]
self.assertEqual(processed_rows, [
{'a': 4}, {'a': 2}, {'a': 1}
])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment