Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #62 from gilesknap/filesystem-search
Browse files Browse the repository at this point in the history
improved test coverage: Shared Folders and empty media
  • Loading branch information
gilesknap authored Mar 4, 2019
2 parents 3ac5798 + 59dd2fb commit 9c3a49d
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 18 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pyyaml = "==4.2b1"
piexif = "*"
python-magic = "*"
gphotos-sync = {path = "."}
coverage = "*"

[dev-packages]
mock = "*"
Expand Down
51 changes: 44 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gphotos/GooglePhotosMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class GooglePhotosMedia(BaseMedia):
def __init__(self, media_json):
def __init__(self, media_json: JSONType):
self.__media_json: JSONType = media_json
self.__uid = None
super(GooglePhotosMedia, self).__init__()
Expand Down
2 changes: 1 addition & 1 deletion test/test_credentials/.gphotos.token
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"access_token": "ya29.GlzBBgBcevw4xzWnasm2YIwQ53CYq0UUbFbGAFz7-8j9U1DBb1sTicGWEsGbKYPT-RL5Cw7KVQg2RJ8VlVEmMmsIJJU9jxGPQijeozLQpDB3qYN100Lcifw7Q7zDOg", "expires_in": 3600, "scope": ["https://www.googleapis.com/auth/photoslibrary.readonly", "https://www.googleapis.com/auth/photoslibrary.sharing"], "token_type": "Bearer", "expires_at": 1551652079.2197618, "refresh_token": "1/HG0feqbbu7FZLjztEbGneV0Jz2aNoiNYuFIHvcZ9MgQ"}
{"access_token": "ya29.GlzCBiCm3BAfkEtz35Qxpl4TMviiALiG0o4y-HsUbVNmse2fdfjKiPHbc39ng0Ih7qggxxtG4dyDqHte6vJa1SOYYmwuj4FNYctjFZ-k3t0RINjRaYzWQal_DG7FCw", "expires_in": 3600, "scope": ["https://www.googleapis.com/auth/photoslibrary.sharing", "https://www.googleapis.com/auth/photoslibrary.readonly"], "token_type": "Bearer", "expires_at": 1551744059.381471, "refresh_token": "1/HG0feqbbu7FZLjztEbGneV0Jz2aNoiNYuFIHvcZ9MgQ"}
19 changes: 10 additions & 9 deletions test/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_sys_whole_library(self):
# Total of 80 media items
db.cur.execute("SELECT COUNT() FROM SyncFiles")
count = db.cur.fetchone()
self.assertEqual(80, count[0])
self.assertEqual(85, count[0])
# with 10 videos
db.cur.execute(
"SELECT COUNT() FROM SyncFiles where MimeType like 'video%'")
Expand All @@ -46,14 +46,15 @@ def test_sys_whole_library(self):
# and 4 albums
db.cur.execute("SELECT COUNT() FROM Albums;")
count = db.cur.fetchone()
self.assertEqual(4, count[0])
self.assertEqual(5, count[0])

# downloaded 10 images in each of the years in the test data
image_years = [2017, 2016, 2015, 2001, 2000, 1998, 1965]
for y in image_years:
image_count = [15, 10, 10, 10, 10, 10, 10]
for year, count in zip(image_years, image_count):
# looking for .jpg .JPG .png .jfif
pat = str(photos_root / str(y) / '*' / '*.[JjpP]*')
self.assertEqual(10, len(sorted(s.root.glob(pat))))
pat = str(photos_root / str(year) / '*' / '*.[JjpP]*')
self.assertEqual(count, len(sorted(s.root.glob(pat))))

# and 10 mp4 for 2017
pat = str(photos_root / '2017' / '*' / '*.mp4')
Expand Down Expand Up @@ -194,19 +195,19 @@ def test_system_retry_download(self):

pat = str(photos_root / '2017' / '??' / '*.[JjpP]*')
files = sorted(s.root.glob(pat))
self.assertEqual(10, len(files))
self.assertEqual(15, len(files))

files[0].unlink()
files = sorted(s.root.glob(pat))
self.assertEqual(9, len(files))
self.assertEqual(14, len(files))

# re-run should not download since file is marked as downloaded
s = ts.SetupDbAndCredentials()
s.test_setup('test_system_retry_download', args=args)
s.gp.start(s.parsed_args)

files = sorted(s.root.glob(pat))
self.assertEqual(9, len(files))
self.assertEqual(14, len(files))

# but adding --retry-download should get us back to 10 files
args.append('--retry-download')
Expand All @@ -215,7 +216,7 @@ def test_system_retry_download(self):
s.gp.start(s.parsed_args)

files = sorted(s.root.glob(pat))
self.assertEqual(10, len(files))
self.assertEqual(15, len(files))

def test_do_delete(self):
s = ts.SetupDbAndCredentials()
Expand Down
20 changes: 20 additions & 0 deletions test/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from requests import exceptions as exc
import piexif
from unittest import TestCase
from gphotos.GoogleAlbumMedia import GoogleAlbumMedia
import json

import gphotos.authorize as auth
from gphotos.LocalFilesMedia import LocalFilesMedia
Expand Down Expand Up @@ -91,3 +93,21 @@ def test_jpg_description2(self):
lfm = LocalFilesMedia(p)
self.dump_exif(p)
self.assertEqual(lfm.description, '')

def test_empty_media(self):
g = GoogleAlbumMedia(json.loads('{"emptyJson":"0"}'))
self.assertEqual(0, g.size)
self.assertEqual('none', g.mime_type)
self.assertEqual('none', g.description)
self.assertEqual(None, g.create_date)
self.assertEqual(None, g.modify_date)
# noinspection PyBroadException
try:
_ = g.url
assert False, "empty album url should throw"
except Exception:
pass
self.assertEquals(Path('') / '', g.full_folder)
g.duplicate_number = 1
self.assertEqual('none (2)', g.filename)

0 comments on commit 9c3a49d

Please sign in to comment.