From 7ce6468d9b8426a3e398b386adccce3a7ab3d5eb Mon Sep 17 00:00:00 2001 From: Paul Makepeace Date: Tue, 26 Apr 2011 19:11:56 -0400 Subject: [PATCH] Add TutorialTestWebScraping (section 6) {1} - {4} --- google/test/test_tutorial.py | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/google/test/test_tutorial.py b/google/test/test_tutorial.py index 5f54485..5eb63fa 100644 --- a/google/test/test_tutorial.py +++ b/google/test/test_tutorial.py @@ -341,7 +341,8 @@ class TutorialTestTransposeFixedNumbeOfRowsIntoColumns( self.assertInResponse('Reorder columns') -class TutorialTestTransposeVariableNumbeOfRowsIntoColumns(refinetest.RefineTestCase): +class TutorialTestTransposeVariableNumbeOfRowsIntoColumns( + refinetest.RefineTestCase): project_file = 'variable-rows.csv' project_file_options = {'split_into_columns': False, 'header_lines': 0} @@ -386,5 +387,41 @@ class TutorialTestTransposeVariableNumbeOfRowsIntoColumns(refinetest.RefineTestC self.assertInResponse('Split 4 cell(s) in column Column') +class TutorialTestWebScraping(refinetest.RefineTestCase): + project_file = 'eli-lilly.csv' + + def test_web_scraping(self): + # Section "6. Web Scraping" + # {1}, {2} + self.project.split_column('key', separator=':') + self.assertInResponse('Split 5409 cell(s) in column key') + self.project.rename_column('key 1', 'page') + self.assertInResponse('Rename column key 1 to page') + self.project.rename_column('key 2', 'top') + self.assertInResponse('Rename column key 2 to top') + self.project.move_column('line', 'end') + self.assertInResponse('Move column line to position 2') + # {3} + self.project.sorting = facet.Sorting([ + {'column': 'page', 'valueType': 'number'}, + {'column': 'top', 'valueType': 'number'}, + ]) + self.project.reorder_rows() + self.assertInResponse('Reorder rows') + first_row = self.project.get_rows(limit=1).rows[0] + self.assertEqual(first_row['page'], 1) + self.assertEqual(first_row['top'], 24) + # {4} + filter_facet = facet.TextFilterFacet('line', 'ahman') + rows = self.project.get_rows(filter_facet).rows + self.assertEqual(len(rows), 1) + self.assertEqual(rows[0]['top'], 106) + filter_facet.query = 'alvarez' + rows = self.project.get_rows().rows + self.assertEqual(len(rows), 2) + self.assertEqual(rows[-1]['top'], 567) + self.project.engine.remove_all() + + if __name__ == '__main__': unittest.main()