Skip to content

Commit

Permalink
getting tests to work
Browse files Browse the repository at this point in the history
  • Loading branch information
Elyse Weiss authored and Elyse Weiss committed May 29, 2024
1 parent c93dbb7 commit 68c3685
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
20 changes: 17 additions & 3 deletions parsons/google/google_slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,23 @@ def delete_slide(self, presentation_id, slide_number):
`Returns:`
None
"""
slide = self.get_slide(presentation_id, slide_number)
self.client.presentations().pages().delete(
presentationId=presentation_id, pageObjectId=slide["objectId"]
slide_object_id = self.get_slide(presentation_id, slide_number)['objectId']

requests = [
{
'deleteObject': {
'objectId': slide_object_id
}
}
]

# Execute the request
body = {
'requests': requests
}
self.client.presentations().batchUpdate(
presentationId=presentation_id,
body=body
).execute()

return None
Expand Down
11 changes: 8 additions & 3 deletions test/test_google/test_google_drive.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest
import os
from parsons import GoogleDrive
import random
import string

# Test Slides: https://docs.google.com/presentation/d/19I-kicyaJV53KoPNwt77KJL10fHzWFdZ_c2mW4XJaxc

Expand All @@ -22,7 +24,10 @@ def test_get_permissions(self):
def test_share_object(self):

file_id = "19I-kicyaJV53KoPNwt77KJL10fHzWFdZ_c2mW4XJaxc"
email_addresses = ["[email protected]"]
email = ''.join(random.choices(string.ascii_letters, k=10))+"@gmail.com"
email_addresses = [email]

shared = self.gd.share_object(file_id, email_addresses)
self.assertTrue(True, list(set([x in p["permissions"] for x in shared]))[0])
before = self.gd.get_permissions(file_id)['permissions']
self.gd.share_object(file_id, email_addresses)
after = self.gd.get_permissions(file_id)['permissions']
self.assertTrue(True, len(after) > len(before))
30 changes: 15 additions & 15 deletions test/test_google/test_google_slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
# Test Slides: https://docs.google.com/presentation/d/19I-kicyaJV53KoPNwt77KJL10fHzWFdZ_c2mW4XJaxc
slides_id = "19I-kicyaJV53KoPNwt77KJL10fHzWFdZ_c2mW4XJaxc"

@unittest.skipIf(
not os.environ.get("LIVE_TEST"), "Skipping because not running live test"
)
class TestGoogleSlides(unittest.TestCase):
def setUp(self):

self.gs = GoogleSlides()

# we're going to grab our Test Slides and drop all slides beyond #1 & 2
presentation = self.gs.get_presentation(slides_id)
self.presentation_id = presentation["presentationId"]
for i in range(len(presentation["slides"])):
if (i + 1) > 2:
slides = presentation["slides"]
if len(slides)>2:
for i in range(2, len(slides)):
self.gs.delete_slide(slides_id, i + 1)

def test_get_presentation(self):
p = self.gs.get_presentation(slides_id)
self.assertEqual(9144000, p["pageSize"]["width"]["magnitude"])

def test_get_slide(self):
s = self.gs.get_slide(slides_id, 2)
self.assertEqual("g26d1b1fa556_2_0", s["objectId"])
s = self.gs.get_slide(slides_id, 1)
self.assertEqual("p", s["objectId"])

def test_duplicate_slide(self):
# duplicating slide #2 to create 3 slides
Expand All @@ -32,33 +35,30 @@ def test_duplicate_slide(self):
self.assertEqual(3, len(p["slides"]))

def test_replace_slide_text(self):
presentation_id = slides_id
slide_number = 3
self.gs.duplicate_slide(slides_id, 2)
original_text = "Replace Text"
replace_text = "Parsons is Fun"
self.gs.replace_slide_text(
presentation_id, slide_number, original_text, replace_text
slides_id, 3, original_text, replace_text
)

s = self.gs.get_slide(presentation_id, slide_number)
s = self.gs.get_slide(slides_id, 3)
content = s["pageElements"][0]["shape"]["text"]["textElements"][1]["textRun"][
"content"
]
self.assertTrue(True, "Parsons is Fun" in content)

def test_get_slide_images(self):
presentation_id = slides_id
slide_number = 2
img = self.gs.get_slide_images(presentation_id, slide_number)
img = self.gs.get_slide_images(slides_id, 2)
height = img[0]["size"]["height"]["magnitude"]
self.assertEqual(7825, height)
self.assertEqual(22525, height)

def test_replace_slide_image(self):
presentation_id = slides_id
img = self.gs.get_slide_images(presentation_id, 2)
self.gs.duplicate_slide(slides_id, 2)
img = self.gs.get_slide_images(presentation_id, 3)
image_obj = img[0]
new_image_url = "https://media.tenor.com/yxJYCVXImqYAAAAM/westwing-josh.gif"

self.gs.replace_slide_image(presentation_id, 3, image_obj, new_image_url)
img = self.gs.get_slide_images(presentation_id, 3)
self.assertTrue(True, img[0]["image"]["sourceUrl"] == new_image_url)

0 comments on commit 68c3685

Please sign in to comment.