forked from googleworkspace/python-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_snippets.py
More file actions
152 lines (136 loc) Β· 6.77 KB
/
test_snippets.py
File metadata and controls
152 lines (136 loc) Β· 6.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright 2018 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
from pprint import pformat
from base_test import BaseTest
from slides_snippets import SlidesSnippets
class SnippetsTest(BaseTest):
IMAGE_URL = 'https://www.google.com/images/' \
'branding/googlelogo/2x/googlelogo_color_272x92dp.png'
TEMPLATE_PRESENTATION_ID = '1E7tKQyX8H7zI7F8_v7mNDY5VyHZ3NNcjUQhkGXoITnw'
DATA_SPREADSHEET_ID = '14KaZMq2aCAGt5acV77zaA_Ps8aDt04G7T0ei4KiXLX8'
CHART_ID = 1107320627
CUSTOMER_NAME = 'Fake Customer'
@classmethod
def setUpClass(cls):
super(SnippetsTest, cls).setUpClass()
cls.snippets = SlidesSnippets(
cls.service,
cls.drive_service,
cls.sheets_service,
cls.credentials)
def test_create_presentation(self):
presentation = self.snippets.create_presentation('Title')
self.assertIsNotNone(presentation)
self.delete_file_on_cleanup(presentation.get('presentationId'))
def test_copy_presentation(self):
presentation_id = self.create_test_presentation()
copy_id = self.snippets.copy_presentation(
presentation_id, 'My Duplicate Presentation')
self.assertIsNotNone(copy_id)
self.delete_file_on_cleanup(copy_id)
def test_create_slide(self):
presentation_id = self.create_test_presentation()
self.add_slides(presentation_id, 3)
page_id = 'my_page_id'
response = self.snippets.create_slide(presentation_id, page_id)
self.assertEqual(page_id,
response.get('replies')[0].get('createSlide').get('objectId'))
def test_create_textbox_with_text(self):
presentation_id = self.create_test_presentation()
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
response = self.snippets.create_textbox_with_text(
presentation_id, page_id)
self.assertEqual(2, len(response.get('replies')), msg=pformat(response))
box_id = response.get('replies')[0].get('createShape').get('objectId')
self.assertIsNotNone(box_id, msg=pformat(response))
def test_create_image(self):
presentation_id = self.create_test_presentation()
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
response = self.snippets.create_image(presentation_id, page_id)
self.assertEqual(1, len(response.get('replies')), msg=pformat(response))
image_id = response.get('replies')[0].get('createImage').get('objectId')
self.assertIsNotNone(image_id, msg=pformat(response))
def test_text_merging(self):
responses = self.snippets.text_merging(
SnippetsTest.TEMPLATE_PRESENTATION_ID,
SnippetsTest.DATA_SPREADSHEET_ID)
for response in responses:
presentation_id = response.get('presentationId')
self.assertIsNotNone(presentation_id, msg=pformat(response))
self.assertEqual(3, len(response.get('replies')),
msg=pformat(response))
num_replacements = 0
for reply in response.get('replies'):
num_replacements += reply.get('replaceAllText') \
.get('occurrencesChanged')
self.assertEqual(4, num_replacements, msg=pformat(reply))
self.delete_file_on_cleanup(presentation_id)
def test_image_merging(self):
response = self.snippets.image_merging(
SnippetsTest.TEMPLATE_PRESENTATION_ID,
SnippetsTest.IMAGE_URL,
SnippetsTest.CUSTOMER_NAME)
presentation_id = response.get('presentationId')
self.assertIsNotNone(presentation_id, msg=pformat(response))
self.assertEqual(2, len(response.get('replies')),
msg=pformat(response))
num_replacements = 0
for reply in response.get('replies'):
num_replacements += reply.get('replaceAllShapesWithImage') \
.get('occurrencesChanged')
self.assertEqual(2, num_replacements)
self.delete_file_on_cleanup(presentation_id)
def test_simple_text_replace(self):
presentation_id = self.create_test_presentation()
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
box_id = self.create_test_textbox(presentation_id, page_id)
response = self.snippets.simple_text_replace(
presentation_id, box_id, 'MY NEW TEXT')
self.assertEqual(2, len(response.get('replies')),
msg=pformat(response))
def test_text_style_update(self):
presentation_id = self.create_test_presentation()
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
box_id = self.create_test_textbox(presentation_id, page_id)
response = self.snippets.text_style_update(presentation_id, box_id)
self.assertEqual(3, len(response.get('replies')),
msg=pformat(response))
def test_create_bulleted_text(self):
presentation_id = self.create_test_presentation()
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
box_id = self.create_test_textbox(presentation_id, page_id)
response = self.snippets.create_bulleted_text(presentation_id, box_id)
self.assertEqual(1, len(response.get('replies')),
msg=pformat(response))
def test_create_sheets_chart(self):
presentation_id = self.create_test_presentation()
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
response = self.snippets.create_sheets_chart(presentation_id,
page_id, SnippetsTest.DATA_SPREADSHEET_ID, SnippetsTest.CHART_ID)
self.assertEqual(1, len(response.get('replies')),
msg=pformat(response))
chart_id = response.get('replies')[0].get('createSheetsChart') \
.get('objectId')
self.assertIsNotNone(chart_id, msg=pformat(response))
def test_refresh_sheets_chart(self):
presentation_id = self.create_test_presentation()
page_id = self.add_slides(presentation_id, 1, 'BLANK')[0]
chart_id = self.create_test_sheets_chart(presentation_id,
page_id, SnippetsTest.DATA_SPREADSHEET_ID, SnippetsTest.CHART_ID)
response = self.snippets.refresh_sheets_chart(presentation_id, chart_id)
self.assertEqual(1, len(response.get('replies')),
msg=pformat(response))
if __name__ == '__main__':
unittest.main()