Skip to content

Commit 8bba561

Browse files
authored
test: UT for slides (#341)
* Slides UT Added * Slides UT updated * test: added testcase for slide snippets * test: UT for slides
1 parent 2009506 commit 8bba561

12 files changed

Lines changed: 457 additions & 0 deletions
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 slides_copy_presentation
17+
from base_test import BaseTest
18+
19+
20+
class TestCopyPresentation(BaseTest):
21+
"""Unit test for Copy presentation snippet"""
22+
23+
def test_copy_presentation(self):
24+
"""set title for copy presentation"""
25+
presentation_id = self.create_test_presentation()
26+
copy_id = slides_copy_presentation.copy_presentation(
27+
presentation_id, 'My Duplicate Presentation')
28+
self.assertIsNotNone(copy_id)
29+
self.delete_file_on_cleanup(copy_id)
30+
31+
32+
if __name__ == "__main__":
33+
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+
from pprint import pformat
16+
17+
import slides_create_bulleted_text
18+
from base_test import BaseTest
19+
20+
21+
class TestCreateBulletedText(BaseTest):
22+
"""Unit test for create_bulleted_text snippet"""
23+
24+
def test_create_bulleted_text(self):
25+
"""create_bulleted_text function"""
26+
presentation_id = self.create_test_presentation()
27+
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
28+
box_id = self.create_test_textbox(presentation_id, page_id)
29+
response = slides_create_bulleted_text.\
30+
create_bulleted_text(presentation_id, box_id)
31+
self.assertEqual(1, len(response.get('replies')),
32+
msg=pformat(response))
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
from pprint import pformat
16+
17+
import slides_create_image
18+
from base_test import BaseTest
19+
20+
21+
class TestCreateTextboxWithText(BaseTest):
22+
"""Unit test case for create_image snippet"""
23+
24+
def test_create_image(self):
25+
"""presentation id and page id for create image"""
26+
presentation_id = self.create_test_presentation()
27+
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
28+
response = slides_create_image.create_image(presentation_id, page_id)
29+
self.assertEqual(1, len(response.get('replies')),
30+
msg=pformat(response))
31+
image_id = response.get('replies')[0].get(
32+
'createImage').get('objectId')
33+
self.assertIsNotNone(image_id, msg=pformat(response))
34+
35+
36+
if __name__ == "__main__":
37+
unittest.main()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 slides_create_presentation
17+
from base_test import BaseTest
18+
19+
20+
class TestCreatePresentation(BaseTest):
21+
"""Unit test for create presentation snippet"""
22+
23+
def test_create_presentation(self):
24+
"""Set title for create presentation"""
25+
presentation = slides_create_presentation.create_presentation('Title')
26+
self.assertIsNotNone(presentation)
27+
self.delete_file_on_cleanup(presentation.get('presentationId'))
28+
29+
30+
if __name__ == "__main__":
31+
unittest.main()
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+
from pprint import pformat
16+
17+
import slides_create_sheets_chart
18+
from base_test import BaseTest
19+
20+
21+
class TestCreateSheetsChart(BaseTest):
22+
"""Unit test for create_sheets_chart snippet"""
23+
DATA_SPREADSHEET_ID = '17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM'
24+
CHART_ID = 1107320627
25+
26+
def test_create_sheets_chart(self):
27+
"""create_sheet chart method """
28+
presentation_id = self.create_test_presentation()
29+
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
30+
response = slides_create_sheets_chart. \
31+
create_sheets_chart(presentation_id, page_id,
32+
self.DATA_SPREADSHEET_ID,
33+
self.CHART_ID)
34+
self.assertEqual(1, len(response.get('replies')),
35+
msg=pformat(response))
36+
chart_id = response.get('replies')[0].get('createSheetsChart') \
37+
.get('objectId')
38+
self.assertIsNotNone(chart_id, msg=pformat(response))
39+
40+
41+
if __name__ == "__main__":
42+
unittest.main()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 slides_create_slide
17+
from base_test import BaseTest
18+
19+
20+
class TestCreateSlide(BaseTest):
21+
"""Unit test for create Slide snippet"""
22+
23+
def test_create_slide(self):
24+
"""pass presentation_id and page_id for creating the slides"""
25+
presentation_id = self.create_test_presentation()
26+
self.add_slides(presentation_id, 3)
27+
page_id = 'my_page_id'
28+
response = slides_create_slide.create_slide(presentation_id, page_id)
29+
self.assertEqual(page_id,
30+
response.get('replies')[0].get('createSlide').
31+
get('objectId'))
32+
33+
34+
if __name__ == "__main__":
35+
unittest.main()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
from pprint import pformat
16+
17+
import slides_create_textbox_with_text
18+
from base_test import BaseTest
19+
20+
21+
class TestCreateTextboxWithText(BaseTest):
22+
"""Unit test for TestCreateTextboxWithText snippet"""
23+
24+
def test_create_textbox_with_text(self):
25+
"""Pass Presentation id and page id """
26+
presentation_id = self.create_test_presentation()
27+
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
28+
response = slides_create_textbox_with_text.create_textbox_with_text(
29+
presentation_id, page_id)
30+
self.assertEqual(2, len(response.get('replies')),
31+
msg=pformat(response))
32+
box_id = response.get('replies')[0].get('createShape').get('objectId')
33+
self.assertIsNotNone(box_id, msg=pformat(response))
34+
35+
36+
if __name__ == "__main__":
37+
unittest.main()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
from pprint import pformat
16+
17+
import slides_image_merging
18+
from base_test import BaseTest
19+
20+
21+
class TestTextMerging(BaseTest):
22+
"""Unit test for text merging snippet"""
23+
TEMPLATE_PRESENTATION_ID = '10QnVUx1X2qHsL17WUidGpPh_SQhXYx40CgIxaKk8jU4'
24+
DATA_SPREADSHEET_ID = '17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM'
25+
IMAGE_URL = 'https://picsum.photos/200'
26+
CHART_ID = 1107320627
27+
CUSTOMER_NAME = 'Fake Customer'
28+
29+
def test_image_merging(self):
30+
"""image merging function """
31+
response = slides_image_merging.image_merging(
32+
self.TEMPLATE_PRESENTATION_ID,
33+
self.IMAGE_URL,
34+
self.CUSTOMER_NAME)
35+
presentation_id = response.get('presentationId')
36+
self.delete_file_on_cleanup(presentation_id)
37+
self.assertIsNotNone(presentation_id, msg=pformat(response))
38+
self.assertEqual(2, len(response.get('replies')),
39+
msg=pformat(response))
40+
num_replacements = 0
41+
for reply in response.get('replies'):
42+
if isinstance(reply, int):
43+
num_replacements += reply.get('replaceAllShapesWithImage') \
44+
.get('occurrencesChanged')
45+
46+
47+
if __name__ == "__main__":
48+
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+
from pprint import pformat
16+
17+
import slides_refresh_sheets_chart
18+
from base_test import BaseTest
19+
20+
21+
class TestCreateSheetsChart(BaseTest):
22+
"""Unit test for refresh_sheets_chart snippet"""
23+
DATA_SPREADSHEET_ID = '17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM'
24+
CHART_ID = 1107320627
25+
26+
def test_refresh_sheets_chart(self):
27+
""" refresh_sheets_chart method """
28+
presentation_id = self.create_test_presentation()
29+
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
30+
chart_id = self.create_test_sheets_chart(presentation_id,
31+
page_id,
32+
self.DATA_SPREADSHEET_ID,
33+
self.CHART_ID)
34+
response = slides_refresh_sheets_chart.refresh_sheets_chart(
35+
presentation_id, chart_id)
36+
self.assertEqual(1, len(response.get('replies')),
37+
msg=pformat(response))
38+
39+
40+
if __name__ == "__main__":
41+
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+
from pprint import pformat
16+
17+
import slides_simple_text_replace
18+
from base_test import BaseTest
19+
20+
21+
class TestSimpleTextReplace(BaseTest):
22+
"""Unit test for SimpleTextReplace snippet"""
23+
24+
def test_simple_text_replace(self):
25+
""" test_simple_text_replace function"""
26+
presentation_id = self.create_test_presentation()
27+
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
28+
box_id = self.create_test_textbox(presentation_id, page_id)
29+
response = slides_simple_text_replace.simple_text_replace(
30+
presentation_id, box_id, 'MY NEW TEXT')
31+
self.assertEqual(2, len(response.get('replies')),
32+
msg=pformat(response))
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()

0 commit comments

Comments
 (0)