aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/tests/unit/wqflask/test_server_side.py31
-rw-r--r--wqflask/wqflask/server_side.py16
2 files changed, 39 insertions, 8 deletions
diff --git a/wqflask/tests/unit/wqflask/test_server_side.py b/wqflask/tests/unit/wqflask/test_server_side.py
new file mode 100644
index 00000000..4f91d8ca
--- /dev/null
+++ b/wqflask/tests/unit/wqflask/test_server_side.py
@@ -0,0 +1,31 @@
+import unittest
+
+from wqflask.server_side import ServerSideTable
+
+
+class TestServerSideTableTests(unittest.TestCase):
+ """
+ Test the ServerSideTable class
+
+ test table:
+ first, second, third
+ 'd', 4, 'zz'
+ 'b', 2, 'aa'
+ 'c', 1, 'ss'
+ """
+
+ def test_get_page(self):
+ rows_count = 3
+ table_rows = [
+ {'first': 'd', 'second': 4, 'third': 'zz'},
+ {'first': 'b', 'second': 2, 'third': 'aa'},
+ {'first': 'c', 'second': 1, 'third': 'ss'},
+ ]
+ headers = ['first', 'second', 'third']
+ request_args = {'sEcho': '1', 'iSortCol_0': '1', 'iSortingCols': '1', 'sSortDir_0': 'asc', 'iDisplayStart': '0', 'iDisplayLength': '3'}
+
+ test_page = ServerSideTable(rows_count, table_rows, headers, request_args).get_page()
+ self.assertEqual(test_page['sEcho'], '1')
+ self.assertEqual(test_page['iTotalRecords'], 'nan')
+ self.assertEqual(test_page['iTotalDisplayRecords'], '3')
+ self.assertEqual(test_page['data'], [{'first': 'b', 'second': 2, 'third': 'aa'}, {'first': 'c', 'second': 1, 'third': 'ss'}, {'first': 'd', 'second': 4, 'third': 'zz'}])
diff --git a/wqflask/wqflask/server_side.py b/wqflask/wqflask/server_side.py
index 824b00aa..5f764767 100644
--- a/wqflask/wqflask/server_side.py
+++ b/wqflask/wqflask/server_side.py
@@ -3,7 +3,7 @@
class ServerSideTable(object):
- '''
+ """
This class is used to do server-side processing
on the DataTables table such as paginating, sorting,
filtering(not implemented) etc. This takes the load off
@@ -22,7 +22,7 @@ class ServerSideTable(object):
Have a look at snp_browser_table() function in
wqflask/wqflask/views.py for reference use.
- '''
+ """
def __init__(self, rows_count, table_rows, header_data_names, request_values):
self.request_values = request_values
@@ -36,12 +36,12 @@ class ServerSideTable(object):
self.paginate_rows()
def sort_rows(self):
- '''
+ """
Sorts the rows taking in to account the column (or columns) that the
user has selected.
- '''
+ """
def is_reverse(str_direction):
- ''' Maps the 'desc' and 'asc' words to True or False. '''
+ """ Maps the 'desc' and 'asc' words to True or False. """
return True if str_direction == 'desc' else False
if (self.request_values['iSortCol_0'] != "") and (int(self.request_values['iSortingCols']) > 0):
@@ -54,12 +54,12 @@ class ServerSideTable(object):
reverse=is_reverse(sort_direction))
def paginate_rows(self):
- '''
+ """
Selects a subset of the filtered and sorted data based on if the table
has pagination, the current page and the size of each page.
- '''
+ """
def requires_pagination():
- ''' Check if the table is going to be paginated '''
+ """ Check if the table is going to be paginated """
if self.request_values['iDisplayStart'] != "":
if int(self.request_values['iDisplayLength']) != -1:
return True