From 062f283e6b942b96f406dba694b2ca8d6f6a7d8f Mon Sep 17 00:00:00 2001 From: Paul Makepeace Date: Mon, 25 Apr 2011 15:45:20 -0400 Subject: [PATCH] Add blank_down() and project.has_records (its consequence). Fix unintentional sort in test, and clear sort after reorder_rows(). --- google/refine.py | 9 +++++++++ google/test/test_refine.py | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/google/refine.py b/google/refine.py index 8a610e8..4d7da97 100644 --- a/google/refine.py +++ b/google/refine.py @@ -395,6 +395,7 @@ class RefineProject: self.engine = Engine() self.sorting = Sorting() # following filled in by get_models() + self.has_records = False self.column_order = {} # order of column in UI self.rows_response_factory = None # for parsing get_rows() self.get_models() @@ -426,6 +427,7 @@ class RefineProject: self.column_order[name] = i column_index[name] = column['cellIndex'] self.key_column = column_model['keyColumnName'] + self.has_records = response['recordModel'].get('hasRecords', False) self.rows_response_factory = RowsResponseFactory(column_index) # TODO: implement rest return response @@ -480,6 +482,8 @@ class RefineProject: self.sorting = Sorting(sort_by) response = self.do_json('reorder-rows', {'sorting': self.sorting.as_json()}) + # clear sorting + self.sorting = Sorting() return response def remove_rows(self, facets=None): @@ -557,3 +561,8 @@ class RefineProject: 'columnInsertIndex': column_insert_index, 'onError': on_error}) self.get_models() return response + + def blank_down(self, column): + response = self.do_json('blank-down', {'columnName': column}) + self.get_models() + return response \ No newline at end of file diff --git a/google/test/test_refine.py b/google/test/test_refine.py index 03a1a25..2c9ce73 100644 --- a/google/test/test_refine.py +++ b/google/test/test_refine.py @@ -275,7 +275,7 @@ class TutorialTestDuplicateDetection(RefineTestCase): response = self.project.reorder_rows() self.assertEqual('Reorder rows', response['historyEntry']['description']) - response = self.project.get_rows(sort_by='email') + response = self.project.get_rows() indexes = [r.index for r in response.rows] self.assertEqual(indexes, range(10)) # {10} @@ -284,10 +284,19 @@ class TutorialTestDuplicateDetection(RefineTestCase): self.assertTrue('column email by filling 10 rows' in response['historyEntry']['description']) response = self.project.get_rows() + self.assertEqual(self.project.column_order['email'], 0) # i.e. 1st self.assertEqual(self.project.column_order['count'], 1) # i.e. 2nd counts = [r['count'] for r in response.rows] self.assertEqual(counts, [2, 2, 1, 1, 3, 3, 3, 1, 2, 2]) + # {11} + self.assertFalse(self.project.has_records) + response = self.project.blank_down('email') + self.assertTrue('Blank down 4 cells' in + response['historyEntry']['description']) + self.assertTrue(self.project.has_records) + response = self.project.get_rows() + emails = [1 if r['email'] else 0 for r in response.rows] + self.assertEqual(emails, [1, 0, 1, 1, 1, 0, 0, 1, 1, 0]) - if __name__ == '__main__': unittest.main() \ No newline at end of file