diff --git a/classroom/snippets/classroom_add_student.py b/classroom/snippets/classroom_add_student.py index 45e27465..a0c67539 100644 --- a/classroom/snippets/classroom_add_student.py +++ b/classroom/snippets/classroom_add_student.py @@ -12,7 +12,7 @@ See the License for the specific language governing permissions and limitations under the License.""" -# [START classroom_add_teacher] +# [START classroom_add_student] from __future__ import print_function import os @@ -79,4 +79,4 @@ def classroom_add_student_new(course_id): if __name__ == '__main__': # Put the course_id of course for which student needs to be added. classroom_add_student_new(478800920837) -# [END classroom_add_teacher] +# [END classroom_add_student] diff --git a/drive/snippets/drive-v3/file_snippet/test_create_folder.py b/drive/snippets/drive-v3/file_snippet/test_create_folder.py new file mode 100644 index 00000000..1cb7bfbd --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_create_folder.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 create_folder + + +class TestCreateFolder(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_create_folder(cls): + """Test create_folder""" + file_id = create_folder.create_folder() + cls.assertIsNotNone(cls, file_id) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_create_shortcut.py b/drive/snippets/drive-v3/file_snippet/test_create_shortcut.py new file mode 100644 index 00000000..2e2f3080 --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_create_shortcut.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 create_shortcut + + +class TestCreateShortcut(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_create_shortcut(cls): + """Test create_folder""" + file_id = create_shortcut.create_shortcut() + cls.assertIsNotNone(cls, file_id) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_download_file.py b/drive/snippets/drive-v3/file_snippet/test_download_file.py new file mode 100644 index 00000000..724b780c --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_download_file.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 download_file + + +class TestDownloadFile(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_download_file(cls): + """Test Download_file""" + # valid file id + real_file_id = '1KuPmvGq8yoYgbfW74OENMCB5H0n_2Jm9' + file = download_file.download_file(real_file_id=real_file_id) + cls.assertNotEqual(cls, 0, len(file)) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_export_pdf.py b/drive/snippets/drive-v3/file_snippet/test_export_pdf.py new file mode 100644 index 00000000..cf0ecb9f --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_export_pdf.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 export_pdf + + +class TestExportPdf(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_export_pdf(cls): + """Test export_pdf""" + # valid file ID + real_file_id = '1zbp8wAyuImX91Jt9mI-CAX_1TqkBLDEDcr2WeXBbKUY' + file = export_pdf.export_pdf(real_file_id=real_file_id) + cls.assertNotEqual(cls, 0, len(file)) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_move_file_to_folder.py b/drive/snippets/drive-v3/file_snippet/test_move_file_to_folder.py new file mode 100644 index 00000000..579bf37f --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_move_file_to_folder.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 move_file_to_folder + + +class TestMoveFileToFolder(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_move_file_to_folder(cls): + """Test move_file_to_folder""" + real_file_id = '1KuPmvGq8yoYgbfW74OENMCB5H0n_2Jm9' + real_folder_id = '1v5eyIbXCr9TZX3eX_44HEExfe7yRj24V' + + update = move_file_to_folder.move_file_to_folder( + real_file_id=real_file_id, real_folder_id=real_folder_id) + cls.assertIsNotNone(cls, 0, len(update)) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_search_file.py b/drive/snippets/drive-v3/file_snippet/test_search_file.py new file mode 100644 index 00000000..964d2a6b --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_search_file.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 search_file + + +class TestSearchFile(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_search_file(cls): + """Test search_file""" + file = search_file.search_file() + cls.assertNotEqual(cls, 0, len(file)) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_share_file.py b/drive/snippets/drive-v3/file_snippet/test_share_file.py new file mode 100644 index 00000000..85392192 --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_share_file.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 share_file + + +class TestShareFile(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_share_file(cls): + """Test share_file""" + real_file_id = '1dUiRSoAQKkM3a4nTPeNQWgiuau1KdQ_l' + real_user = 'gduser1@workspacesamples.dev' + real_domain = 'workspacesamples.dev' + file = share_file.share_file(real_file_id=real_file_id, + real_user=real_user, + real_domain=real_domain) + cls.assertNotEqual(cls, 0, len(file)) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_touch_file.py b/drive/snippets/drive-v3/file_snippet/test_touch_file.py new file mode 100644 index 00000000..cd1f68a4 --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_touch_file.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 re +import unittest +from datetime import datetime + +import touch_file + + +class TestTouchFile(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_touch_file(cls): + """Test touch_file""" + real_file_id = '1KuPmvGq8yoYgbfW74OENMCB5H0n_2Jm9' + now = datetime.utcnow().isoformat() + 'Z' + now = re.sub(r'\d{3}Z', 'Z', now) # Truncate microseconds + modified_time = touch_file.touch_file(real_file_id=real_file_id, + real_timestamp=now) + cls.assertIsNotNone(cls, modified_time) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_upload_basic.py b/drive/snippets/drive-v3/file_snippet/test_upload_basic.py new file mode 100644 index 00000000..3d6c473d --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_upload_basic.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 upload_basic + + +class TestUploadBasic(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_upload_basic(cls): + """Test upload_basic""" + file_id = upload_basic.upload_basic() + cls.assertIsNotNone(cls, file_id) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_upload_revision.py b/drive/snippets/drive-v3/file_snippet/test_upload_revision.py new file mode 100644 index 00000000..88f396e5 --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_upload_revision.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 upload_revision + + +class TestUploadRevision(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_upload_revision(cls): + """Test upload_revision""" + + real_file_id = '1KuPmvGq8yoYgbfW74OENMCB5H0n_2Jm9' + file_id = upload_revision.upload_revision(real_file_id=real_file_id) + cls.assertIsNotNone(cls, file_id) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_upload_to_folder.py b/drive/snippets/drive-v3/file_snippet/test_upload_to_folder.py new file mode 100644 index 00000000..4b129df3 --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_upload_to_folder.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 upload_to_folder + + +class TestUploadToFolder(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_upload_to_folder(cls): + """Test upload_to_folder""" + real_folder_id = '1s0oKEZZXjImNngxHGnY0xed6Mw-tvspu' + file_id = upload_to_folder.upload_to_folder( + real_folder_id=real_folder_id) + cls.assertIsNotNone(cls, file_id) + + +if __name__ == '__main__': + unittest.main() diff --git a/drive/snippets/drive-v3/file_snippet/test_upload_with_conversion.py b/drive/snippets/drive-v3/file_snippet/test_upload_with_conversion.py new file mode 100644 index 00000000..563f5c70 --- /dev/null +++ b/drive/snippets/drive-v3/file_snippet/test_upload_with_conversion.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 upload_with_conversion + + +class TestUploadWithConversion(unittest.TestCase): + """Unit test class for file snippet""" + + @classmethod + def test_upload_to_folder(cls): + """Test upload_with_conversion""" + file_id = upload_with_conversion.upload_with_conversion() + cls.assertIsNotNone(cls, file_id) + + +if __name__ == '__main__': + unittest.main() diff --git a/gmail/snippet/send mail/create_draft.py b/gmail/snippet/send mail/create_draft.py index cb4a4220..8ee16a6c 100644 --- a/gmail/snippet/send mail/create_draft.py +++ b/gmail/snippet/send mail/create_draft.py @@ -19,7 +19,7 @@ from __future__ import print_function import base64 -from email.mime.text import MIMEText +from email.message import EmailMessage import google.auth from googleapiclient.discovery import build @@ -41,16 +41,19 @@ def gmail_create_draft(): # create gmail api client service = build('gmail', 'v1', credentials=creds) - message = MIMEText('This is automated draft mail') + message = EmailMessage() + + message.set_content('This is automated draft mail') + message['To'] = 'gduser1@workspacesamples.dev' message['From'] = 'gduser2@workspacesamples.dev' message['Subject'] = 'Automated draft' + + # encoded message encoded_message = base64.urlsafe_b64encode(message.as_bytes()).decode() create_message = { - 'message': { 'raw': encoded_message - } } # pylint: disable=E1101 draft = service.users().drafts().create(userId="me", diff --git a/gmail/snippet/send mail/create_draft_with_attachment.py b/gmail/snippet/send mail/create_draft_with_attachment.py index d3735215..dfb2ef4c 100644 --- a/gmail/snippet/send mail/create_draft_with_attachment.py +++ b/gmail/snippet/send mail/create_draft_with_attachment.py @@ -13,16 +13,15 @@ limitations under the License. """ # [START gmail_create_draft_with_attachment] - from __future__ import print_function import base64 import mimetypes import os +from email.message import EmailMessage from email.mime.audio import MIMEAudio from email.mime.base import MIMEBase from email.mime.image import MIMEImage -from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import google.auth @@ -44,21 +43,33 @@ def gmail_create_draft_with_attachment(): try: # create gmail api client service = build('gmail', 'v1', credentials=creds) - mime_message = MIMEMultipart() + mime_message = EmailMessage() + + # headers mime_message['To'] = 'gduser1@workspacesamples.dev' mime_message['From'] = 'gduser2@workspacesamples.dev' mime_message['Subject'] = 'sample with attachment' - text_part = MIMEText('Hi, this is automated mail with attachment.' - 'Please do not reply.') - mime_message.attach(text_part) - image_attachment = build_file_part(file='photo.jpg') - mime_message.attach(image_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 = base64.urlsafe_b64encode(mime_message.as_bytes()).decode() create_draft_request_body = { - 'message': { - 'raw': encoded_message - } + 'raw': encoded_message } # pylint: disable=E1101 draft = service.users().drafts().create(userId="me", diff --git a/gmail/snippet/send mail/send_message.py b/gmail/snippet/send mail/send_message.py index 995d1cde..432d2cdb 100644 --- a/gmail/snippet/send mail/send_message.py +++ b/gmail/snippet/send mail/send_message.py @@ -15,7 +15,7 @@ from __future__ import print_function import base64 -from email.mime.text import MIMEText +from email.message import EmailMessage import google.auth from googleapiclient.discovery import build @@ -35,19 +35,20 @@ def gmail_send_message(): try: service = build('gmail', 'v1', credentials=creds) - message = MIMEText('This is automated draft mail') + message = EmailMessage() + + message.set_content('This is automated draft mail') + message['To'] = 'gduser1@workspacesamples.dev' message['From'] = 'gduser2@workspacesamples.dev' message['Subject'] = 'Automated draft' + # encoded message encoded_message = base64.urlsafe_b64encode(message.as_bytes()) \ .decode() create_message = { - 'message': { - - 'raw': encoded_message - } + 'raw': encoded_message } # pylint: disable=E1101 send_message = (service.users().messages().send 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 a8832250..00000000 --- a/gmail/snippet/send mail/send_message_with_attachment.py +++ /dev/null @@ -1,103 +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 -import os -from email.mime.audio import MIMEAudio -from email.mime.base import MIMEBase -from email.mime.image import MIMEImage -from email.mime.multipart import MIMEMultipart -from email.mime.text import MIMEText - -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: - service = build('gmail', 'v1', credentials=creds) - mime_message = MIMEMultipart() - mime_message['to'] = 'gduser1@workspacesamples.dev' - mime_message['from'] = 'gduser2@workspacesamples.dev' - mime_message['subject'] = 'sample with attachment' - text_part = MIMEText('Hi, this is automated mail with attachment.' - 'Please do not reply.') - mime_message.attach(text_part) - image_attachment = build_file_part(file='photo.jpg') - mime_message.attach(image_attachment) - # encoded message - encoded_message = base64.urlsafe_b64encode(mime_message.as_bytes()) \ - .decode() - - send_message_request_body = { - 'message': { - - '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 - - -def build_file_part(file): - """Creates a MIME part for a file. - Args: - file: The path to the file to be attached. - Returns: - A MIME part that can be attached to a message. - """ - content_type, encoding = mimetypes.guess_type(file) - if content_type is None or encoding is not None: - content_type = 'application/octet-stream' - main_type, sub_type = content_type.split('/', 1) - if main_type == 'text': - with open(file, 'rb'): - msg = MIMEText('r', _subtype=sub_type) - elif main_type == 'image': - with open(file, 'rb'): - msg = MIMEImage('r', _subtype=sub_type) - elif main_type == 'audio': - with open(file, 'rb'): - msg = MIMEAudio('r', _subtype=sub_type) - else: - with open(file, 'rb'): - msg = MIMEBase(main_type, sub_type) - msg.set_payload(file.read()) - filename = os.path.basename(file) - msg.add_header('Content-Disposition', 'attachment', filename=filename) - return msg - - -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/sheets/snippets/sheets_append_values.py b/sheets/snippets/sheets_append_values.py index 3a5ffe70..18a24c95 100644 --- a/sheets/snippets/sheets_append_values.py +++ b/sheets/snippets/sheets_append_values.py @@ -14,7 +14,7 @@ limitations under the License. """ -# [START sheets_get_values] +# [START sheets_append_values] from __future__ import print_function import google.auth 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..6003ae10 --- /dev/null +++ b/sheets/snippets/test_sheets_conditional_formatting.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 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..f6aa236a --- /dev/null +++ b/sheets/snippets/test_sheets_create.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_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() diff --git a/slides/snippets/slides_copy_presentation.py b/slides/snippets/slides_copy_presentation.py index 6aa7512b..5b4ad584 100644 --- a/slides/snippets/slides_copy_presentation.py +++ b/slides/snippets/slides_copy_presentation.py @@ -27,7 +27,7 @@ def copy_presentation(presentation_id, copy_title): Creates the copy Presentation the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() diff --git a/slides/snippets/slides_create_bulleted_text.py b/slides/snippets/slides_create_bulleted_text.py index ff2ba8ed..89c88c5c 100644 --- a/slides/snippets/slides_create_bulleted_text.py +++ b/slides/snippets/slides_create_bulleted_text.py @@ -27,7 +27,7 @@ def create_bulleted_text(presentation_id, shape_id): Run create_bulleted_text the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member diff --git a/slides/snippets/slides_create_image.py b/slides/snippets/slides_create_image.py index eade9545..a4b34e75 100644 --- a/slides/snippets/slides_create_image.py +++ b/slides/snippets/slides_create_image.py @@ -27,7 +27,7 @@ def create_image(presentation_id, page_id): Creates images the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() diff --git a/slides/snippets/slides_create_presentation.py b/slides/snippets/slides_create_presentation.py index b6f9c91b..33777e29 100644 --- a/slides/snippets/slides_create_presentation.py +++ b/slides/snippets/slides_create_presentation.py @@ -27,7 +27,7 @@ def create_presentation(title): Creates the Presentation the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member diff --git a/slides/snippets/slides_create_sheets_chart.py b/slides/snippets/slides_create_sheets_chart.py index f1316334..a1f286af 100644 --- a/slides/snippets/slides_create_sheets_chart.py +++ b/slides/snippets/slides_create_sheets_chart.py @@ -28,7 +28,7 @@ def create_sheets_chart(presentation_id, page_id, spreadsheet_id, create_sheets_chart the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member @@ -90,3 +90,5 @@ def create_sheets_chart(presentation_id, page_id, spreadsheet_id, "FIRSTSLIDE", "17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM", "1107320627") + +# [END slides_create_sheets_chart] diff --git a/slides/snippets/slides_create_slide.py b/slides/snippets/slides_create_slide.py index 941cd9f5..8f16e1d2 100644 --- a/slides/snippets/slides_create_slide.py +++ b/slides/snippets/slides_create_slide.py @@ -27,7 +27,7 @@ def create_slide(presentation_id, page_id): Creates the Presentation the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application.\n """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member diff --git a/slides/snippets/slides_create_textbox_with_text.py b/slides/snippets/slides_create_textbox_with_text.py index 57db69d9..2f1e1889 100644 --- a/slides/snippets/slides_create_textbox_with_text.py +++ b/slides/snippets/slides_create_textbox_with_text.py @@ -27,7 +27,7 @@ def create_textbox_with_text(presentation_id, page_id): Creates the textbox with text, the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member diff --git a/slides/snippets/slides_refresh_sheets_chart.py b/slides/snippets/slides_refresh_sheets_chart.py index 3fb83406..4a962eae 100644 --- a/slides/snippets/slides_refresh_sheets_chart.py +++ b/slides/snippets/slides_refresh_sheets_chart.py @@ -27,7 +27,7 @@ def refresh_sheets_chart(presentation_id, presentation_chart_id): refresh_sheets_chart the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member diff --git a/slides/snippets/slides_simple_text_replace.py b/slides/snippets/slides_simple_text_replace.py index bce6dfdd..23acde4c 100644 --- a/slides/snippets/slides_simple_text_replace.py +++ b/slides/snippets/slides_simple_text_replace.py @@ -27,7 +27,7 @@ def simple_text_replace(presentation_id, shape_id, replacement_text): Run simple_text_replace the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member @@ -70,3 +70,5 @@ def simple_text_replace(presentation_id, shape_id, replacement_text): simple_text_replace('10QnVUx1X2qHsL17WUidGpPh_SQhXYx40CgIxaKk8jU4', 'MyTextBox_6', 'GWSpace_now') + +# [END slides_simple_text_replace] diff --git a/slides/snippets/slides_text_merging.py b/slides/snippets/slides_text_merging.py index f0c338fe..310adc3e 100644 --- a/slides/snippets/slides_text_merging.py +++ b/slides/snippets/slides_text_merging.py @@ -27,7 +27,7 @@ def text_merging(template_presentation_id, data_spreadsheet_id): Run Text merging the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member diff --git a/slides/snippets/slides_text_style_update.py b/slides/snippets/slides_text_style_update.py index c82c900a..96b3d40b 100644 --- a/slides/snippets/slides_text_style_update.py +++ b/slides/snippets/slides_text_style_update.py @@ -27,7 +27,7 @@ def text_style_update(presentation_id, shape_id): create_sheets_chart the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity - for guides on implementing OAuth2 for the application.\n" + for guides on implementing OAuth2 for the application. """ creds, _ = google.auth.default() # pylint: disable=maybe-no-member