From c3ce6e0f482ebcb71aa4857012b1f118fd6bde0d Mon Sep 17 00:00:00 2001 From: suchawla09 Date: Tue, 14 Jun 2022 15:28:08 +0530 Subject: [PATCH 1/3] Sheets UT Added --- sheets/snippets/test_sheets_append_values.py | 42 +++++++++++++++++++ .../snippets/test_sheets_batch_get_values.py | 38 +++++++++++++++++ sheets/snippets/test_sheets_batch_update.py | 41 ++++++++++++++++++ .../test_sheets_batch_update_values.py | 40 ++++++++++++++++++ .../test_sheets_conditional_formatting.py | 32 ++++++++++++++ sheets/snippets/test_sheets_create.py | 29 +++++++++++++ sheets/snippets/test_sheets_filter_views.py | 30 +++++++++++++ sheets/snippets/test_sheets_get_values.py | 36 ++++++++++++++++ sheets/snippets/test_sheets_pivot_tables.py | 32 ++++++++++++++ sheets/snippets/test_sheets_update_values.py | 38 +++++++++++++++++ 10 files changed, 358 insertions(+) create mode 100644 sheets/snippets/test_sheets_append_values.py create mode 100644 sheets/snippets/test_sheets_batch_get_values.py create mode 100644 sheets/snippets/test_sheets_batch_update.py create mode 100644 sheets/snippets/test_sheets_batch_update_values.py create mode 100644 sheets/snippets/test_sheets_conditional_formatting.py create mode 100644 sheets/snippets/test_sheets_create.py create mode 100644 sheets/snippets/test_sheets_filter_views.py create mode 100644 sheets/snippets/test_sheets_get_values.py create mode 100644 sheets/snippets/test_sheets_pivot_tables.py create mode 100644 sheets/snippets/test_sheets_update_values.py diff --git a/sheets/snippets/test_sheets_append_values.py b/sheets/snippets/test_sheets_append_values.py new file mode 100644 index 00000000..3cdfe1a3 --- /dev/null +++ b/sheets/snippets/test_sheets_append_values.py @@ -0,0 +1,42 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest + +import sheets_append_values +from base_test import BaseTest + + +class Testappendvalues(BaseTest): + """Unit test for append value Sheet snippet""" + + def test_append_values(self): + """test append values function""" + spreadsheet_id = self.create_test_spreadsheet() + self.populate_values(spreadsheet_id) + result = sheets_append_values.append_values(spreadsheet_id, + 'Sheet1', 'USER_ENTERED', [ + ['A', 'B'], + ['C', 'D'] + ]) + self.assertIsNotNone(result) + self.assertEqual('Sheet1!A1:J10', result.get('tableRange')) + updates = result.get('updates') + self.assertEqual('Sheet1!A11:B12', updates.get('updatedRange')) + self.assertEqual(2, updates.get('updatedRows')) + self.assertEqual(2, updates.get('updatedColumns')) + self.assertEqual(4, updates.get('updatedCells')) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_batch_get_values.py b/sheets/snippets/test_sheets_batch_get_values.py new file mode 100644 index 00000000..aa912f3a --- /dev/null +++ b/sheets/snippets/test_sheets_batch_get_values.py @@ -0,0 +1,38 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest + +import sheets_batch_get_values +from base_test import BaseTest + + +class Testgetvalues(BaseTest): + """Unit test class for get value Sheet snippet""" + + def test_batch_get_values(self): + """test batch get values function""" + spreadsheet_id = self.create_test_spreadsheet() + self.populate_values(spreadsheet_id) + result = sheets_batch_get_values.batch_get_values(spreadsheet_id, + ['A1:A3', 'B1:C1']) + self.assertIsNotNone(result) + valueranges = result.get('valueRanges') + self.assertIsNotNone(valueranges) + self.assertEqual(2, len(valueranges)) + values = valueranges[0].get('values') + self.assertEqual(3, len(values)) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_batch_update.py b/sheets/snippets/test_sheets_batch_update.py new file mode 100644 index 00000000..70550ace --- /dev/null +++ b/sheets/snippets/test_sheets_batch_update.py @@ -0,0 +1,41 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest + +import sheets_batch_update +import sheets_create +from base_test import BaseTest + + +class Testbatchupdate(BaseTest): + """Unit test class for Batch update Sheet snippet""" + + def test_batch_update(self): + """test_batch_update function """ + spreadsheet_id = sheets_create.create('Title') + self.populate_values(spreadsheet_id) + response = sheets_batch_update.\ + sheets_batch_update(spreadsheet_id, 'New Title', + 'Hello', 'Goodbye') + self.assertIsNotNone(response) + replies = response.get('replies') + self.assertIsNotNone(replies) + self.assertEqual(2, len(replies)) + find_replace_response = replies[1].get('findReplace') + self.assertIsNotNone(find_replace_response) + self.assertEqual(100, find_replace_response.get('occurrencesChanged')) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_batch_update_values.py b/sheets/snippets/test_sheets_batch_update_values.py new file mode 100644 index 00000000..4701f904 --- /dev/null +++ b/sheets/snippets/test_sheets_batch_update_values.py @@ -0,0 +1,40 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest + +import sheets_batch_update_values +from base_test import BaseTest + + +class Testbatchupdatevalues(BaseTest): + """Unit test for Batch update value Sheet snippet""" + + def test_batch_update_values(self): + """batch updates values""" + spreadsheet_id = self.create_test_spreadsheet() + result = sheets_batch_update_values. \ + batch_update_values(spreadsheet_id, + 'A1:B2', 'USER_ENTERED', [ + ['A', 'B'], + ['C', 'D'] + ]) + self.assertIsNotNone(result) + self.assertEqual(1, len(result.get('responses'))) + self.assertEqual(2, result.get('totalUpdatedRows')) + self.assertEqual(2, result.get('totalUpdatedColumns')) + self.assertEqual(4, result.get('totalUpdatedCells')) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_conditional_formatting.py b/sheets/snippets/test_sheets_conditional_formatting.py new file mode 100644 index 00000000..56d0cfac --- /dev/null +++ b/sheets/snippets/test_sheets_conditional_formatting.py @@ -0,0 +1,32 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest +import sheets_conditional_formatting +from base_test import BaseTest + + +class Testconditionalformatting(BaseTest): + """Unit test for sheets conditional_formatting value Sheet snippet""" + + def test_conditional_formatting(self): + """sheets_conditional_formatting function""" + spreadsheet_id = self.create_test_spreadsheet() + self.populate_values(spreadsheet_id) + response = sheets_conditional_formatting.\ + conditional_formatting(spreadsheet_id) + self.assertEqual(2, len(response.get('replies'))) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_create.py b/sheets/snippets/test_sheets_create.py new file mode 100644 index 00000000..43ada1d4 --- /dev/null +++ b/sheets/snippets/test_sheets_create.py @@ -0,0 +1,29 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest +import sheets_create +from base_test import BaseTest + + +class Testsheetscreate(BaseTest): + """Unit test class for Create Sheet snippet""" + def test_create(self): + """sheet function for Create sheet """ + spreadsheet_id = sheets_create.create('Title') + self.assertIsNotNone(spreadsheet_id) + self.delete_file_on_cleanup(spreadsheet_id) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_filter_views.py b/sheets/snippets/test_sheets_filter_views.py new file mode 100644 index 00000000..4c17c76e --- /dev/null +++ b/sheets/snippets/test_sheets_filter_views.py @@ -0,0 +1,30 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest +import sheets_filter_views +from base_test import BaseTest + + +class Testfilterviews(BaseTest): + """Unit test for sheets conditional_formatting value Sheet snippet""" + + def test_filter_views(self): + """test filter view function""" + spreadsheet_id = self.create_test_spreadsheet() + self.populate_values(spreadsheet_id) + sheets_filter_views.filter_views(spreadsheet_id) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_get_values.py b/sheets/snippets/test_sheets_get_values.py new file mode 100644 index 00000000..329e1739 --- /dev/null +++ b/sheets/snippets/test_sheets_get_values.py @@ -0,0 +1,36 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest + +import sheets_get_values +from base_test import BaseTest + + +class Testgetvalues(BaseTest): + """Unit test class for get value Sheet snippet""" + + def test_get_values(self): + """test_get_values""" + spreadsheet_id = self.create_test_spreadsheet() + self.populate_values(spreadsheet_id) + result = sheets_get_values.get_values(spreadsheet_id, 'A1:C2') + self.assertIsNotNone(result) + values = result.get('values') + self.assertIsNotNone(values) + self.assertEqual(2, len(values)) + self.assertEqual(3, len(values[0])) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_pivot_tables.py b/sheets/snippets/test_sheets_pivot_tables.py new file mode 100644 index 00000000..7f64a0f3 --- /dev/null +++ b/sheets/snippets/test_sheets_pivot_tables.py @@ -0,0 +1,32 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest + +import sheets_pivot_tables +from base_test import BaseTest + + +class Testpivottables(BaseTest): + """Unit test for Pivot tables value Sheet snippet""" + + def test_pivot_tables(self): + """pivot table function""" + spreadsheet_id = self.create_test_spreadsheet() + self.populate_values(spreadsheet_id) + response = sheets_pivot_tables.pivot_tables(spreadsheet_id) + self.assertIsNotNone(response) + + +if __name__ == "__main__": + unittest.main() diff --git a/sheets/snippets/test_sheets_update_values.py b/sheets/snippets/test_sheets_update_values.py new file mode 100644 index 00000000..82efa71d --- /dev/null +++ b/sheets/snippets/test_sheets_update_values.py @@ -0,0 +1,38 @@ +""" +Copyright 2022 Google LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import unittest + +import sheets_update_values +from base_test import BaseTest + + +class Testupdatesvalues(BaseTest): + """Unit test for update value Sheet snippet""" + + def test_update_values(self): + """test updates_values""" + spreadsheet_id = self.create_test_spreadsheet() + result = sheets_update_values.update_values(spreadsheet_id, + 'A1:B2', 'USER_ENTERED', [ + ['A', 'B'], + ['C', 'D'] + ]) + self.assertIsNotNone(result) + self.assertEqual(2, result.get('updatedRows')) + self.assertEqual(2, result.get('updatedColumns')) + self.assertEqual(4, result.get('updatedCells')) + + +if __name__ == "__main__": + unittest.main() From 2db7f441e70db1ab38829fc2e18d2db9f7f06725 Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Thu, 16 Jun 2022 11:14:49 -0600 Subject: [PATCH 2/3] Fix formatting of imports --- sheets/snippets/test_sheets_conditional_formatting.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sheets/snippets/test_sheets_conditional_formatting.py b/sheets/snippets/test_sheets_conditional_formatting.py index 56d0cfac..6003ae10 100644 --- a/sheets/snippets/test_sheets_conditional_formatting.py +++ b/sheets/snippets/test_sheets_conditional_formatting.py @@ -12,6 +12,7 @@ """ import unittest + import sheets_conditional_formatting from base_test import BaseTest From f315afb0039acb95ca189a8a1d7d5cd29426c127 Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Thu, 16 Jun 2022 11:15:04 -0600 Subject: [PATCH 3/3] Fix formatting of imports --- sheets/snippets/test_sheets_create.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sheets/snippets/test_sheets_create.py b/sheets/snippets/test_sheets_create.py index 43ada1d4..f6aa236a 100644 --- a/sheets/snippets/test_sheets_create.py +++ b/sheets/snippets/test_sheets_create.py @@ -12,6 +12,7 @@ """ import unittest + import sheets_create from base_test import BaseTest