Skip to content

Commit 1e236dc

Browse files
RajeshGovosuchawla09sqrrrl
authored
Ut sheets (#327)
* Sheets UT Added * Fix formatting of imports * Fix formatting of imports Co-authored-by: suchawla09 <suchawla@google.com> Co-authored-by: Steve Bazyl <sqrrrl@gmail.com>
1 parent cf73a44 commit 1e236dc

10 files changed

Lines changed: 360 additions & 0 deletions
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_append_values
17+
from base_test import BaseTest
18+
19+
20+
class Testappendvalues(BaseTest):
21+
"""Unit test for append value Sheet snippet"""
22+
23+
def test_append_values(self):
24+
"""test append values function"""
25+
spreadsheet_id = self.create_test_spreadsheet()
26+
self.populate_values(spreadsheet_id)
27+
result = sheets_append_values.append_values(spreadsheet_id,
28+
'Sheet1', 'USER_ENTERED', [
29+
['A', 'B'],
30+
['C', 'D']
31+
])
32+
self.assertIsNotNone(result)
33+
self.assertEqual('Sheet1!A1:J10', result.get('tableRange'))
34+
updates = result.get('updates')
35+
self.assertEqual('Sheet1!A11:B12', updates.get('updatedRange'))
36+
self.assertEqual(2, updates.get('updatedRows'))
37+
self.assertEqual(2, updates.get('updatedColumns'))
38+
self.assertEqual(4, updates.get('updatedCells'))
39+
40+
41+
if __name__ == "__main__":
42+
unittest.main()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_batch_get_values
17+
from base_test import BaseTest
18+
19+
20+
class Testgetvalues(BaseTest):
21+
"""Unit test class for get value Sheet snippet"""
22+
23+
def test_batch_get_values(self):
24+
"""test batch get values function"""
25+
spreadsheet_id = self.create_test_spreadsheet()
26+
self.populate_values(spreadsheet_id)
27+
result = sheets_batch_get_values.batch_get_values(spreadsheet_id,
28+
['A1:A3', 'B1:C1'])
29+
self.assertIsNotNone(result)
30+
valueranges = result.get('valueRanges')
31+
self.assertIsNotNone(valueranges)
32+
self.assertEqual(2, len(valueranges))
33+
values = valueranges[0].get('values')
34+
self.assertEqual(3, len(values))
35+
36+
37+
if __name__ == "__main__":
38+
unittest.main()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_batch_update
17+
import sheets_create
18+
from base_test import BaseTest
19+
20+
21+
class Testbatchupdate(BaseTest):
22+
"""Unit test class for Batch update Sheet snippet"""
23+
24+
def test_batch_update(self):
25+
"""test_batch_update function """
26+
spreadsheet_id = sheets_create.create('Title')
27+
self.populate_values(spreadsheet_id)
28+
response = sheets_batch_update.\
29+
sheets_batch_update(spreadsheet_id, 'New Title',
30+
'Hello', 'Goodbye')
31+
self.assertIsNotNone(response)
32+
replies = response.get('replies')
33+
self.assertIsNotNone(replies)
34+
self.assertEqual(2, len(replies))
35+
find_replace_response = replies[1].get('findReplace')
36+
self.assertIsNotNone(find_replace_response)
37+
self.assertEqual(100, find_replace_response.get('occurrencesChanged'))
38+
39+
40+
if __name__ == "__main__":
41+
unittest.main()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_batch_update_values
17+
from base_test import BaseTest
18+
19+
20+
class Testbatchupdatevalues(BaseTest):
21+
"""Unit test for Batch update value Sheet snippet"""
22+
23+
def test_batch_update_values(self):
24+
"""batch updates values"""
25+
spreadsheet_id = self.create_test_spreadsheet()
26+
result = sheets_batch_update_values. \
27+
batch_update_values(spreadsheet_id,
28+
'A1:B2', 'USER_ENTERED', [
29+
['A', 'B'],
30+
['C', 'D']
31+
])
32+
self.assertIsNotNone(result)
33+
self.assertEqual(1, len(result.get('responses')))
34+
self.assertEqual(2, result.get('totalUpdatedRows'))
35+
self.assertEqual(2, result.get('totalUpdatedColumns'))
36+
self.assertEqual(4, result.get('totalUpdatedCells'))
37+
38+
39+
if __name__ == "__main__":
40+
unittest.main()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_conditional_formatting
17+
from base_test import BaseTest
18+
19+
20+
class Testconditionalformatting(BaseTest):
21+
"""Unit test for sheets conditional_formatting value Sheet snippet"""
22+
23+
def test_conditional_formatting(self):
24+
"""sheets_conditional_formatting function"""
25+
spreadsheet_id = self.create_test_spreadsheet()
26+
self.populate_values(spreadsheet_id)
27+
response = sheets_conditional_formatting.\
28+
conditional_formatting(spreadsheet_id)
29+
self.assertEqual(2, len(response.get('replies')))
30+
31+
32+
if __name__ == "__main__":
33+
unittest.main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_create
17+
from base_test import BaseTest
18+
19+
20+
class Testsheetscreate(BaseTest):
21+
"""Unit test class for Create Sheet snippet"""
22+
def test_create(self):
23+
"""sheet function for Create sheet """
24+
spreadsheet_id = sheets_create.create('Title')
25+
self.assertIsNotNone(spreadsheet_id)
26+
self.delete_file_on_cleanup(spreadsheet_id)
27+
28+
29+
if __name__ == "__main__":
30+
unittest.main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
import sheets_filter_views
16+
from base_test import BaseTest
17+
18+
19+
class Testfilterviews(BaseTest):
20+
"""Unit test for sheets conditional_formatting value Sheet snippet"""
21+
22+
def test_filter_views(self):
23+
"""test filter view function"""
24+
spreadsheet_id = self.create_test_spreadsheet()
25+
self.populate_values(spreadsheet_id)
26+
sheets_filter_views.filter_views(spreadsheet_id)
27+
28+
29+
if __name__ == "__main__":
30+
unittest.main()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_get_values
17+
from base_test import BaseTest
18+
19+
20+
class Testgetvalues(BaseTest):
21+
"""Unit test class for get value Sheet snippet"""
22+
23+
def test_get_values(self):
24+
"""test_get_values"""
25+
spreadsheet_id = self.create_test_spreadsheet()
26+
self.populate_values(spreadsheet_id)
27+
result = sheets_get_values.get_values(spreadsheet_id, 'A1:C2')
28+
self.assertIsNotNone(result)
29+
values = result.get('values')
30+
self.assertIsNotNone(values)
31+
self.assertEqual(2, len(values))
32+
self.assertEqual(3, len(values[0]))
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_pivot_tables
17+
from base_test import BaseTest
18+
19+
20+
class Testpivottables(BaseTest):
21+
"""Unit test for Pivot tables value Sheet snippet"""
22+
23+
def test_pivot_tables(self):
24+
"""pivot table function"""
25+
spreadsheet_id = self.create_test_spreadsheet()
26+
self.populate_values(spreadsheet_id)
27+
response = sheets_pivot_tables.pivot_tables(spreadsheet_id)
28+
self.assertIsNotNone(response)
29+
30+
31+
if __name__ == "__main__":
32+
unittest.main()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Copyright 2022 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import unittest
15+
16+
import sheets_update_values
17+
from base_test import BaseTest
18+
19+
20+
class Testupdatesvalues(BaseTest):
21+
"""Unit test for update value Sheet snippet"""
22+
23+
def test_update_values(self):
24+
"""test updates_values"""
25+
spreadsheet_id = self.create_test_spreadsheet()
26+
result = sheets_update_values.update_values(spreadsheet_id,
27+
'A1:B2', 'USER_ENTERED', [
28+
['A', 'B'],
29+
['C', 'D']
30+
])
31+
self.assertIsNotNone(result)
32+
self.assertEqual(2, result.get('updatedRows'))
33+
self.assertEqual(2, result.get('updatedColumns'))
34+
self.assertEqual(4, result.get('updatedCells'))
35+
36+
37+
if __name__ == "__main__":
38+
unittest.main()

0 commit comments

Comments
 (0)