diff --git a/gmail/snippet/send mail/send_message_with_attachment.py b/gmail/snippet/send mail/send_message_with_attachment.py deleted file mode 100644 index f375af8a..00000000 --- a/gmail/snippet/send mail/send_message_with_attachment.py +++ /dev/null @@ -1,81 +0,0 @@ -""" -Copyright 2019 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. -""" -# [START gmail_send_message_with_attachment] -from __future__ import print_function - -import base64 -import mimetypes -from email.message import EmailMessage - -import google.auth -from googleapiclient.discovery import build -from googleapiclient.errors import HttpError - - -def gmail_send_message_with_attachment(): - """Create and send an email message with attachment - Print the returned message id - Returns: Message object, including message id - - Load pre-authorized user credentials from the environment. - TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application. - """ - creds, _ = google.auth.default() - - try: - # create gmail api client - service = build('gmail', 'v1', credentials=creds) - mime_message = EmailMessage() - - # headers - mime_message['to'] = 'gduser1@workspacesamples.dev' - mime_message['from'] = 'gduser2@workspacesamples.dev' - mime_message['subject'] = 'sample with attachment' - - # text - mime_message.set_content( - 'Hi, this is automated mail with attachment.' - 'Please do not reply.' - ) - - # attachment - attachment_filename = 'photo.jpg' - # guessing the MIME type - type_subtype, _ = mimetypes.guess_type(attachment_filename) - maintype, subtype = type_subtype.split('/') - - with open(attachment_filename, 'rb') as fp: - attachment_data = fp.read() - mime_message.add_attachment(attachment_data, maintype, subtype) - - # encoded message - encoded_message = base64.urlsafe_b64encode(mime_message.as_bytes()) \ - .decode() - - send_message_request_body = { - 'raw': encoded_message - } - # pylint: disable=E1101 - send_message = (service.users().messages().send - (userId='me', body=send_message_request_body).execute()) - print(F'Message Id: {send_message["id"]}') - except HttpError as error: - print(F'An error occurred: {error}') - send_message = None - return send_message - - -if __name__ == '__main__': - gmail_send_message_with_attachment() -# [END gmail_send_message_with_attachment] diff --git a/gmail/snippet/send mail/test_create_draft.py b/gmail/snippet/send mail/test_create_draft.py new file mode 100644 index 00000000..9f6e813b --- /dev/null +++ b/gmail/snippet/send mail/test_create_draft.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 + +from create_draft import gmail_create_draft + + +class TestCreateDraft(unittest.TestCase): + """Unit test classs for snippet""" + + @classmethod + def test_create_draft(cls): + """Unit test for create draft""" + draft = gmail_create_draft() + cls.assertIsNotNone(cls, draft) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/send mail/test_create_draft_with_attachment.py b/gmail/snippet/send mail/test_create_draft_with_attachment.py new file mode 100644 index 00000000..fcb010cc --- /dev/null +++ b/gmail/snippet/send mail/test_create_draft_with_attachment.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 + +from create_draft_with_attachment import gmail_create_draft_with_attachment + + +class TestCreateDraftWithAttachment(unittest.TestCase): + """Unit test classs for Change snippet""" + + @classmethod + def test_create_draft_with_attachment(cls): + """Test create draft with attachment""" + draft = gmail_create_draft_with_attachment() + cls.assertIsNotNone(cls, draft) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/send mail/test_send_message.py b/gmail/snippet/send mail/test_send_message.py new file mode 100644 index 00000000..2d6264e4 --- /dev/null +++ b/gmail/snippet/send mail/test_send_message.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 + +from send_message import gmail_send_message + + +class TestSendMessage(unittest.TestCase): + """Unit test class for snippet""" + + def test_send_message(self): + """test send message""" + send_message = gmail_send_message() + self.assertIsNotNone(self, send_message) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/send mail/test_send_message_with_attachment.py b/gmail/snippet/send mail/test_send_message_with_attachment.py new file mode 100644 index 00000000..722a15d5 --- /dev/null +++ b/gmail/snippet/send mail/test_send_message_with_attachment.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 + +from send_message_with_attachment import gmail_send_message_with_attachment + + +class TestSendMessageWithAttachment(unittest.TestCase): + """Unit test class for gmail snippet""" + + def test_send_message_with_attachment(self): + """ test send message with attachment""" + send_message = gmail_send_message_with_attachment() + self.assertIsNotNone(self, send_message) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/settings snippets/test_create_filter.py b/gmail/snippet/settings snippets/test_create_filter.py new file mode 100644 index 00000000..b040a683 --- /dev/null +++ b/gmail/snippet/settings snippets/test_create_filter.py @@ -0,0 +1,31 @@ +"""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 + +from create_filter import create_filter + + +class TestCreateFilter(unittest.TestCase): + """Unit test class to implement test case for Snippets""" + + @classmethod + def test_create_file(cls): + """test to create file""" + result = create_filter() + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/settings snippets/test_enable_auto_reply.py b/gmail/snippet/settings snippets/test_enable_auto_reply.py new file mode 100644 index 00000000..c2373dd0 --- /dev/null +++ b/gmail/snippet/settings snippets/test_enable_auto_reply.py @@ -0,0 +1,31 @@ +"""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 + +from enable_auto_reply import enable_auto_reply + + +class TestEnableAutoReply(unittest.TestCase): + """Unit test class for the snippet""" + + @classmethod + def test_enable_auto_reply(cls): + """ test to enable auto reply""" + result = enable_auto_reply() + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/settings snippets/test_enable_forwarding.py b/gmail/snippet/settings snippets/test_enable_forwarding.py new file mode 100644 index 00000000..717f8998 --- /dev/null +++ b/gmail/snippet/settings snippets/test_enable_forwarding.py @@ -0,0 +1,31 @@ +"""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 + +from enable_forwarding import enable_forwarding + + +class TestEnableForwarding(unittest.TestCase): + """Unit test class to test enable forwarding snippet""" + + @classmethod + def test_enable_forwarding(cls): + """test to enable forwarding""" + result = enable_forwarding() + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/settings snippets/test_update_signature.py b/gmail/snippet/settings snippets/test_update_signature.py new file mode 100644 index 00000000..30baaebd --- /dev/null +++ b/gmail/snippet/settings snippets/test_update_signature.py @@ -0,0 +1,31 @@ +"""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 + +from update_signature import update_signature + + +class TestUpdateSignature(unittest.TestCase): + """Unit test class to test Update signature snippet""" + + @classmethod + def test_update_signature(cls): + """ test to update signature""" + result = update_signature() + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/smime snippets/insert_cert_from_csv.py b/gmail/snippet/smime snippets/insert_cert_from_csv.py index 319da91f..a2407cda 100644 --- a/gmail/snippet/smime snippets/insert_cert_from_csv.py +++ b/gmail/snippet/smime snippets/insert_cert_from_csv.py @@ -43,6 +43,7 @@ def insert_cert_from_csv(csv_filename): insert_smime_info.insert_smime_info() else: print(F'Unable to read certificate file for user_id: {user_id}') + return smime_info except (OSError, IOError) as error: print(F'An error occured while reading the CSV file: {error}') diff --git a/gmail/snippet/smime snippets/test_create_smime_info.py b/gmail/snippet/smime snippets/test_create_smime_info.py new file mode 100644 index 00000000..be98ea5b --- /dev/null +++ b/gmail/snippet/smime snippets/test_create_smime_info.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 + +from create_smime_info import create_smime_info + + +class TestCreateSmimeInfo(unittest.TestCase): + """Unit test class to test Snippet""" + + @classmethod + def test_create_smime_info(cls): + """test to create smime info""" + # enter the file and password accordingly + smime_info = create_smime_info(cert_filename='abc', cert_password='abc') + cls.assertIsNotNone(cls, smime_info) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/smime snippets/test_insert_cert_from_csv.py b/gmail/snippet/smime snippets/test_insert_cert_from_csv.py new file mode 100644 index 00000000..c44ab826 --- /dev/null +++ b/gmail/snippet/smime snippets/test_insert_cert_from_csv.py @@ -0,0 +1,31 @@ +"""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 + +from insert_cert_from_csv import insert_cert_from_csv + + +class TestInsertCertFromCsv(unittest.TestCase): + """unittest class for testing the snippetts""" + + @classmethod + def test_insert_cert_from_csv(cls): + """test to insert cert from csv""" + result = insert_cert_from_csv('test.csv') + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/smime snippets/test_insert_smime_info.py b/gmail/snippet/smime snippets/test_insert_smime_info.py new file mode 100644 index 00000000..366e76d7 --- /dev/null +++ b/gmail/snippet/smime snippets/test_insert_smime_info.py @@ -0,0 +1,31 @@ +"""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 + +from insert_smime_info import insert_smime_info + + +class TestInsertSmimeInfo(unittest.TestCase): + """Unit test class for snippet""" + + @classmethod + def test_insert_smime_info(cls): + """test to insert smime info""" + result = insert_smime_info() + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/smime snippets/test_update_smime_cert.py b/gmail/snippet/smime snippets/test_update_smime_cert.py new file mode 100644 index 00000000..70935315 --- /dev/null +++ b/gmail/snippet/smime snippets/test_update_smime_cert.py @@ -0,0 +1,33 @@ +"""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 + +from update_smime_cert import update_smime_cert + + +class TestUpdateSmimeCert(unittest.TestCase): + """Unit test class for snippets""" + + @classmethod + def test_update_smime_cert(cls): + """test update smime cert""" + result = update_smime_cert(user_id='xyz', send_as_email='yzx', + cert_filename='abc', cert_password='abc', + expire_dt='cde') + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/smime snippets/test_update_smime_from_csv.py b/gmail/snippet/smime snippets/test_update_smime_from_csv.py new file mode 100644 index 00000000..d976cf86 --- /dev/null +++ b/gmail/snippet/smime snippets/test_update_smime_from_csv.py @@ -0,0 +1,31 @@ +"""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 + +from update_smime_from_csv import update_smime_from_csv + + +class TestUpdateSmimeFromCsv(unittest.TestCase): + """unit test class for snippets""" + + @classmethod + def test_update_smime_from_csv(cls): + """test to update smime from csv""" + result = update_smime_from_csv(csv_filename='abc') + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/smime snippets/update_smime_from_csv.py b/gmail/snippet/smime snippets/update_smime_from_csv.py index 1d5e45ae..39afa3f7 100644 --- a/gmail/snippet/smime snippets/update_smime_from_csv.py +++ b/gmail/snippet/smime snippets/update_smime_from_csv.py @@ -16,6 +16,7 @@ import update_smime_cert +# pylint: disable-this-line-in-some-way def update_smime_from_csv(csv_filename, expire_dt=None): """Update S/MIME certificates based on the contents of a CSV file. @@ -27,19 +28,20 @@ def update_smime_from_csv(csv_filename, expire_dt=None): expire_dt: DateTime object against which the certificate expiration is compared. If None, uses the current time. """ + ret0 = '' try: with open(csv_filename, 'rb') as cert: csv_reader = csv.reader(cert, delimiter=',') next(csv_reader, None) # skip CSV file header for row in csv_reader: user_id = row[0] - update_smime_cert.update_smime_cert( + ret0 = update_smime_cert.update_smime_cert( user_id, send_as_email=user_id, cert_filename=row[1], cert_password=row[2], expire_dt=expire_dt) - + return ret0 except (OSError, IOError) as error: print(F'An error occured while reading the CSV file: {error}') diff --git a/gmail/snippet/thread/test_thread.py b/gmail/snippet/thread/test_thread.py new file mode 100644 index 00000000..e57b660d --- /dev/null +++ b/gmail/snippet/thread/test_thread.py @@ -0,0 +1,31 @@ +"""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 + +from threads import show_chatty_threads + + +class TestThreads(unittest.TestCase): + """unit test class for snippets""" + + @classmethod + def test_threads(cls): + """to test threads""" + result = show_chatty_threads() + cls.assertIsNotNone(cls, result) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/thread/threads.py b/gmail/snippet/thread/threads.py index 9df8bcd5..bb34f3f3 100644 --- a/gmail/snippet/thread/threads.py +++ b/gmail/snippet/thread/threads.py @@ -33,6 +33,7 @@ def show_chatty_threads(): service = build('gmail', 'v1', credentials=creds) # pylint: disable=maybe-no-member + # pylint: disable:R1710 threads = service.users().threads().list(userId='me').execute().get('threads', []) for thread in threads: tdata = service.users().threads().get(userId='me', id=thread['id']).execute() @@ -48,6 +49,7 @@ def show_chatty_threads(): break if subject: # skip if no Subject line print(F'- {subject}, {nmsgs}') + return threads except HttpError as error: print(F'An error occurred: {error}') diff --git a/slides/snippets/test_slides_copy_presentation.py b/slides/snippets/test_slides_copy_presentation.py new file mode 100644 index 00000000..70d1e260 --- /dev/null +++ b/slides/snippets/test_slides_copy_presentation.py @@ -0,0 +1,33 @@ +""" +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 slides_copy_presentation +from base_test import BaseTest + + +class TestCopyPresentation(BaseTest): + """Unit test for Copy presentation snippet""" + + def test_copy_presentation(self): + """set title for copy presentation""" + presentation_id = self.create_test_presentation() + copy_id = slides_copy_presentation.copy_presentation( + presentation_id, 'My Duplicate Presentation') + self.assertIsNotNone(copy_id) + self.delete_file_on_cleanup(copy_id) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_create_bulleted_text.py b/slides/snippets/test_slides_create_bulleted_text.py new file mode 100644 index 00000000..e3b9c4ab --- /dev/null +++ b/slides/snippets/test_slides_create_bulleted_text.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 +from pprint import pformat + +import slides_create_bulleted_text +from base_test import BaseTest + + +class TestCreateBulletedText(BaseTest): + """Unit test for create_bulleted_text snippet""" + + def test_create_bulleted_text(self): + """create_bulleted_text function""" + 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 = slides_create_bulleted_text.\ + create_bulleted_text(presentation_id, box_id) + self.assertEqual(1, len(response.get('replies')), + msg=pformat(response)) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_create_image.py b/slides/snippets/test_slides_create_image.py new file mode 100644 index 00000000..075041f1 --- /dev/null +++ b/slides/snippets/test_slides_create_image.py @@ -0,0 +1,37 @@ +""" +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 +from pprint import pformat + +import slides_create_image +from base_test import BaseTest + + +class TestCreateTextboxWithText(BaseTest): + """Unit test case for create_image snippet""" + + def test_create_image(self): + """presentation id and page id for create image""" + presentation_id = self.create_test_presentation() + page_id = self.add_slides(presentation_id, 1, 'BLANK')[0] + response = slides_create_image.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)) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_create_presentation.py b/slides/snippets/test_slides_create_presentation.py new file mode 100644 index 00000000..aaa69b24 --- /dev/null +++ b/slides/snippets/test_slides_create_presentation.py @@ -0,0 +1,31 @@ +""" +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 slides_create_presentation +from base_test import BaseTest + + +class TestCreatePresentation(BaseTest): + """Unit test for create presentation snippet""" + + def test_create_presentation(self): + """Set title for create presentation""" + presentation = slides_create_presentation.create_presentation('Title') + self.assertIsNotNone(presentation) + self.delete_file_on_cleanup(presentation.get('presentationId')) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_create_sheets_chart.py b/slides/snippets/test_slides_create_sheets_chart.py new file mode 100644 index 00000000..de8f5e1c --- /dev/null +++ b/slides/snippets/test_slides_create_sheets_chart.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 +from pprint import pformat + +import slides_create_sheets_chart +from base_test import BaseTest + + +class TestCreateSheetsChart(BaseTest): + """Unit test for create_sheets_chart snippet""" + DATA_SPREADSHEET_ID = '17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM' + CHART_ID = 1107320627 + + def test_create_sheets_chart(self): + """create_sheet chart method """ + presentation_id = self.create_test_presentation() + page_id = self.add_slides(presentation_id, 1, 'BLANK')[0] + response = slides_create_sheets_chart. \ + create_sheets_chart(presentation_id, page_id, + self.DATA_SPREADSHEET_ID, + self.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)) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_create_slide.py b/slides/snippets/test_slides_create_slide.py new file mode 100644 index 00000000..eabf36f8 --- /dev/null +++ b/slides/snippets/test_slides_create_slide.py @@ -0,0 +1,35 @@ +""" +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 slides_create_slide +from base_test import BaseTest + + +class TestCreateSlide(BaseTest): + """Unit test for create Slide snippet""" + + def test_create_slide(self): + """pass presentation_id and page_id for creating the slides""" + presentation_id = self.create_test_presentation() + self.add_slides(presentation_id, 3) + page_id = 'my_page_id' + response = slides_create_slide.create_slide(presentation_id, page_id) + self.assertEqual(page_id, + response.get('replies')[0].get('createSlide'). + get('objectId')) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_create_textbox_with_text.py b/slides/snippets/test_slides_create_textbox_with_text.py new file mode 100644 index 00000000..d8e25e18 --- /dev/null +++ b/slides/snippets/test_slides_create_textbox_with_text.py @@ -0,0 +1,37 @@ +""" +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 +from pprint import pformat + +import slides_create_textbox_with_text +from base_test import BaseTest + + +class TestCreateTextboxWithText(BaseTest): + """Unit test for TestCreateTextboxWithText snippet""" + + def test_create_textbox_with_text(self): + """Pass Presentation id and page id """ + presentation_id = self.create_test_presentation() + page_id = self.add_slides(presentation_id, 1, 'BLANK')[0] + response = slides_create_textbox_with_text.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)) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_image_merging.py b/slides/snippets/test_slides_image_merging.py new file mode 100644 index 00000000..116c58ed --- /dev/null +++ b/slides/snippets/test_slides_image_merging.py @@ -0,0 +1,48 @@ +""" +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 +from pprint import pformat + +import slides_image_merging +from base_test import BaseTest + + +class TestTextMerging(BaseTest): + """Unit test for text merging snippet""" + TEMPLATE_PRESENTATION_ID = '10QnVUx1X2qHsL17WUidGpPh_SQhXYx40CgIxaKk8jU4' + DATA_SPREADSHEET_ID = '17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM' + IMAGE_URL = 'https://picsum.photos/200' + CHART_ID = 1107320627 + CUSTOMER_NAME = 'Fake Customer' + + def test_image_merging(self): + """image merging function """ + response = slides_image_merging.image_merging( + self.TEMPLATE_PRESENTATION_ID, + self.IMAGE_URL, + self.CUSTOMER_NAME) + presentation_id = response.get('presentationId') + self.delete_file_on_cleanup(presentation_id) + 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'): + if isinstance(reply, int): + num_replacements += reply.get('replaceAllShapesWithImage') \ + .get('occurrencesChanged') + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_refresh_sheets_chart.py b/slides/snippets/test_slides_refresh_sheets_chart.py new file mode 100644 index 00000000..5fa717af --- /dev/null +++ b/slides/snippets/test_slides_refresh_sheets_chart.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 +from pprint import pformat + +import slides_refresh_sheets_chart +from base_test import BaseTest + + +class TestCreateSheetsChart(BaseTest): + """Unit test for refresh_sheets_chart snippet""" + DATA_SPREADSHEET_ID = '17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM' + CHART_ID = 1107320627 + + def test_refresh_sheets_chart(self): + """ refresh_sheets_chart method """ + 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, + self.DATA_SPREADSHEET_ID, + self.CHART_ID) + response = slides_refresh_sheets_chart.refresh_sheets_chart( + presentation_id, chart_id) + self.assertEqual(1, len(response.get('replies')), + msg=pformat(response)) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_simple_text_replace.py b/slides/snippets/test_slides_simple_text_replace.py new file mode 100644 index 00000000..26334b2c --- /dev/null +++ b/slides/snippets/test_slides_simple_text_replace.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 +from pprint import pformat + +import slides_simple_text_replace +from base_test import BaseTest + + +class TestSimpleTextReplace(BaseTest): + """Unit test for SimpleTextReplace snippet""" + + def test_simple_text_replace(self): + """ test_simple_text_replace function""" + 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 = slides_simple_text_replace.simple_text_replace( + presentation_id, box_id, 'MY NEW TEXT') + self.assertEqual(2, len(response.get('replies')), + msg=pformat(response)) + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_text_merging.py b/slides/snippets/test_slides_text_merging.py new file mode 100644 index 00000000..3eb461b5 --- /dev/null +++ b/slides/snippets/test_slides_text_merging.py @@ -0,0 +1,45 @@ +""" +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 +from pprint import pformat + +import slides_text_merging +from base_test import BaseTest + + +class TestTextMerging(BaseTest): + """Unit test for SimpleTextReplace snippet""" + TEMPLATE_PRESENTATION_ID = '10QnVUx1X2qHsL17WUidGpPh_SQhXYx40CgIxaKk8jU4' + DATA_SPREADSHEET_ID = '17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM' + + def test_text_merging(self): + """ text_merging method """ + + responses = slides_text_merging.text_merging( + self.TEMPLATE_PRESENTATION_ID, + self.DATA_SPREADSHEET_ID) + for response in responses: + presentation_id = response.get('presentationId') + self.delete_file_on_cleanup(presentation_id) + 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') + + +if __name__ == "__main__": + unittest.main() diff --git a/slides/snippets/test_slides_text_style_update.py b/slides/snippets/test_slides_text_style_update.py new file mode 100644 index 00000000..98fd9a57 --- /dev/null +++ b/slides/snippets/test_slides_text_style_update.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 +from pprint import pformat + +import slides_text_style_update +from base_test import BaseTest + + +class TestTextStyleUpdate(BaseTest): + """Unit test for SimpleTextReplace snippet""" + + def test_text_style_update(self): + """ test_text_style_update function""" + 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 = slides_text_style_update.\ + text_style_update(presentation_id, box_id) + self.assertEqual(3, len(response.get('replies')), + msg=pformat(response)) + + +if __name__ == "__main__": + unittest.main()