Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SVCS-426] Update googledrive provider to use googledrive v3 API #276

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions tests/providers/googledrive/fixtures/revisions.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
{
"revision_metadata": {
"modifiedDate": "2015-01-01T16:54:58.929Z",
"md5Checksum": "43c5a01efeaea6bfd0433fa516a0d71f",
"fileSize": "918668",
"lastModifyingUser": {"kind": "drive#user", "permissionId": "07992110234966807597", "emailAddress": "[email protected]", "isAuthenticatedUser": true, "displayName": "Joshua Carp", "picture": {"url": "https://lh3.googleusercontent.com/-ndG-yHyqonM/AAAAAAAAAAI/AAAAAAAAADs/wUR8YhDe3vY/s64/photo.jpg"}},
"selfLink": "https://www.googleapis.com/drive/v2/files/1GwpK7IozbO01RiyC5aPd66v7ShEViqggvT6ur5_pZMFo-ZzQHOgkyoU3ztjf0ytKt0HSdvUg6O2nmoYR/revisions/1DVR6FVQGOSpUrtHjxCKb4-2R0chGVJFG6wVPQwq1o-gay_tqwA",
"lastModifyingUserName": "Joshua Carp",
"downloadUrl": "https://doc-0g-5k-docs.googleusercontent.com/docs/securesc/6l6ti67c1gnej8b4rr55nfimce1282lr/4kr23qf2mtt0g577quhmb7sn41q8t9kl/1424894400000/07992110234966807597/07992110234966807597/1GwpK7IozbO01RiyC5aPd66v7ShEViqggvT6ur5_pZMFo-ZzQHOgkyoU3ztjf0ytKt0HSdvUg6O2nmoYR?rid=1DVR6FVQGOSpUrtHjxCKb4-2R0chGVJFG6wVPQwq1o-gay_tqwA&e=download&gd=true",
"id": "0BxdmnuT5XpqcOGNTWDl3K044Yi83ZU14aDBzSThoRFJEb25jPQ",
"mimeType": "application/pdf",
"id": "1DVR6FVQGOSpUrtHjxCKb4-2R0chGVJFG6wVPQwq1o-gay_tqwA",
"kind": "drive#revision",
"etag": "\"zWM2D6PBtLRQKuDNbaQNSNEy5BE/58C3fd_BFF2TTwuUg7RCveoALHM\"",
"published": false,
"pinned": false
"modifiedTime": "2017-10-12T13:31:17.922Z",
"originalFilename": "xps-13-9343-laptop_Service Manual_en-us.pdf",
"md5Checksum": "53141aa6a986e636bcdcef2ff08beece",
"size": "8604865"
},
"revisions_list": {
"kind": "drive#revisionList",
"etag": "\"zWM2D6PBtLRQKuDNbaQNSNEy5BE/PeANBe5F3yk-YAzsoQO4pYPA5W8\"",
"selfLink": "https://www.googleapis.com/drive/v2/files/1GwpK7IozbO01RiyC5aPd66v7ShEViqggvT6ur5_pZMFo-ZzQHOgkyoU3ztjf0ytKt0HSdvUg6O2nmoYR/revisions",
"items": [
{"selfLink": "https://www.googleapis.com/drive/v2/files/1GwpK7IozbO01RiyC5aPd66v7ShEViqggvT6ur5_pZMFo-ZzQHOgkyoU3ztjf0ytKt0HSdvUg6O2nmoYR/revisions/1DVR6FVQGOSpUrtHjxCKb4-2R0chGVJFG6wVPQwq1o-gay_tqwA", "md5Checksum": "43c5a01efeaea6bfd0433fa516a0d71f", "pinned": false, "etag": "\"zWM2D6PBtLRQKuDNbaQNSNEy5BE/sdQBhqMbZWHR5JnnXwR2jMjJYa4\"", "id": "1DVR6FVQGOSpUrtHjxCKb4-2R0chGVJFG6wVPQwq1o-gay_tqwA", "kind": "drive#revision", "lastModifyingUserName": "Joshua Carp", "mimeType": "application/pdf", "fileSize": "918668", "lastModifyingUser": {"kind": "drive#user", "emailAddress": "[email protected]", "permissionId": "07992110234966807597", "picture": {"url": "https://lh3.googleusercontent.com/-ndG-yHyqonM/AAAAAAAAAAI/AAAAAAAAADs/wUR8YhDe3vY/s64/photo.jpg"}, "displayName": "Joshua Carp", "isAuthenticatedUser": true}, "downloadUrl": "https://doc-0g-5k-docs.googleusercontent.com/docs/securesc/6l6ti67c1gnej8b4rr55nfimce1282lr/nccdohm8rrrqmabek0d1ot5alel2768g/1424959200000/07992110234966807597/07992110234966807597/1GwpK7IozbO01RiyC5aPd66v7ShEViqggvT6ur5_pZMFo-ZzQHOgkyoU3ztjf0ytKt0HSdvUg6O2nmoYR?rid=1DVR6FVQGOSpUrtHjxCKb4-2R0chGVJFG6wVPQwq1o-gay_tqwA&e=download&gd=true", "modifiedDate": "2015-01-01T16:54:58.929Z", "published": false}
"revisions": [
{
"id": "0BxdmnuT5XpqcdFdzM2dtTnB4bnNuUXpmYlZkOUZDV1AvcWFRPQ",
"mimeType": "image/jpeg",
"modifiedTime": "2017-10-16T13:27:10.965Z",
"originalFilename": "sunshine.jpg",
"md5Checksum": "2f7be16736648476f22f08e2e3978d08",
"size": "3782"
}
]
},
"revisions_list_empty":{
"kind": "drive#revisionList",
"etag": "\"zWM2D6PBtLRQKuDNbaQNSNEy5BE/PeANBe5F3yk-YAzsoQO4pYPA5W8\"",
"selfLink": "https://www.googleapis.com/drive/v2/files/1GwpK7IozbO01RiyC5aPd66v7ShEViqggvT6ur5_pZMFo-ZzQHOgkyoU3ztjf0ytKt0HSdvUg6O2nmoYR/revisions",
"items": []
"revisions": []
}
}
386 changes: 117 additions & 269 deletions tests/providers/googledrive/fixtures/root_provider.json

Large diffs are not rendered by default.

599 changes: 180 additions & 419 deletions tests/providers/googledrive/fixtures/sharing.json

Large diffs are not rendered by default.

120 changes: 58 additions & 62 deletions tests/providers/googledrive/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import pytest

import os

import pytest

from waterbutler.providers.googledrive.provider import GoogleDrivePath
from waterbutler.providers.googledrive.provider import GoogleDrivePathPart
from waterbutler.providers.googledrive.metadata import GoogleDriveRevision
from waterbutler.providers.googledrive.metadata import GoogleDriveFileMetadata
from waterbutler.providers.googledrive.metadata import GoogleDriveFolderMetadata
from waterbutler.providers.googledrive.metadata import (GoogleDriveRevision,
GoogleDriveFileMetadata,
GoogleDriveFolderMetadata)

from tests.providers.googledrive.fixtures import(
error_fixtures,
root_provider_fixtures,
revision_fixtures,
sharing_fixtures,
)
from tests.providers.googledrive.fixtures import (error_fixtures, root_provider_fixtures,
revision_fixtures, sharing_fixtures)


@pytest.fixture
Expand All @@ -24,92 +19,93 @@ def basepath():
class TestMetadata:

def test_file_metadata_drive(self, basepath, root_provider_fixtures):
item = root_provider_fixtures['list_file']['items'][0]
path = basepath.child(item['title'])
parsed = GoogleDriveFileMetadata(item, path)
file = root_provider_fixtures['list_file']['files'][0]
path = basepath.child(file['name'])
parsed = GoogleDriveFileMetadata(file, path)

assert parsed.provider == 'googledrive'
assert parsed.id == item['id']
assert path.name == item['title']
assert parsed.name == item['title']
assert parsed.size == item['fileSize']
assert parsed.modified == item['modifiedDate']
assert parsed.content_type == item['mimeType']
assert parsed.id == file['id']
assert path.name == file['name']
assert parsed.name == file['name']
assert parsed.size == file['size']
assert parsed.modified == file['modifiedTime']
assert parsed.content_type == file['mimeType']
assert parsed.extra == {
'revisionId': item['version'],
'webView': item['alternateLink'],
'hashes': {'md5': item['md5Checksum']},
'revisionId': file['version'],
'webView': file['webViewLink'],
'hashes': {'md5': file['md5Checksum']},
}
assert parsed.path == '/' + os.path.join(*[x.raw for x in path.parts])
assert parsed.materialized_path == str(path)
assert parsed.is_google_doc is False
assert parsed.export_name == item['title']
assert parsed.export_name == file['name']

def test_file_metadata_drive_slashes(self, basepath, root_provider_fixtures):
item = root_provider_fixtures['file_forward_slash']
path = basepath.child(item['title'])
parsed = GoogleDriveFileMetadata(item, path)
file = root_provider_fixtures['file_forward_slash']
path = basepath.child(file['name'])
parsed = GoogleDriveFileMetadata(file, path)

assert parsed.provider == 'googledrive'
assert parsed.id == item['id']
assert parsed.name == item['title']
assert parsed.id == file['id']
assert parsed.name == file['name']
assert parsed.name == path.name
assert parsed.size == item['fileSize']
assert parsed.modified == item['modifiedDate']
assert parsed.content_type == item['mimeType']
assert parsed.size == file['size']
assert parsed.modified == file['modifiedTime']
assert parsed.content_type == file['mimeType']
assert parsed.extra == {
'revisionId': item['version'],
'webView': item['alternateLink'],
'hashes': {'md5': item['md5Checksum']},
'revisionId': file['version'],
'webView': file['webViewLink'],
'hashes': {'md5': file['md5Checksum']},
}
assert parsed.path == '/' + os.path.join(*[x.raw for x in path.parts])
assert parsed.materialized_path == str(path)
assert parsed.is_google_doc is False
assert parsed.export_name == item['title']
assert parsed.export_name == file['name']

def test_file_metadata_docs(self, basepath, root_provider_fixtures):
item = root_provider_fixtures['docs_file_metadata']
path = basepath.child(item['title'])
parsed = GoogleDriveFileMetadata(item, path)
file = root_provider_fixtures['docs_file_metadata']
path = basepath.child(file['name'])
parsed = GoogleDriveFileMetadata(file, path)

assert parsed.name == item['title'] + '.gdoc'
assert parsed.name == file['name'] + '.gdoc'
assert parsed.extra == {
'revisionId': item['version'],
'revisionId': file['version'],
'downloadExt': '.docx',
'webView': item['alternateLink'],
'webView': file['webViewLink'],
}
assert parsed.is_google_doc is True
assert parsed.export_name == item['title'] + '.docx'
assert parsed.export_name == file['name'] + '.docx'

def test_folder_metadata(self, root_provider_fixtures):
item = root_provider_fixtures['folder_metadata']
path = GoogleDrivePath('/we/love/you/conrad').child(item['title'], folder=True)
parsed = GoogleDriveFolderMetadata(item, path)
file = root_provider_fixtures['folder_metadata']
path = GoogleDrivePath('/we/love/you/conrad').child(file['name'], folder=True)
parsed = GoogleDriveFolderMetadata(file, path)

assert parsed.provider == 'googledrive'
assert parsed.id == item['id']
assert parsed.name == item['title']
assert parsed.extra == {'revisionId': item['version']}
assert parsed.id == file['id']
assert parsed.name == file['name']
assert parsed.extra == {'revisionId': file['version']}
assert parsed.path == '/' + os.path.join(*[x.raw for x in path.parts]) + '/'
assert parsed.materialized_path == str(path)
assert parsed.export_name == item['title']
assert parsed.export_name == file['name']

def test_folder_metadata_slash(self, root_provider_fixtures):
item = root_provider_fixtures['folder_metadata_forward_slash']
path = GoogleDrivePath('/we/love/you/conrad').child(item['title'], folder=True)
parsed = GoogleDriveFolderMetadata(item, path)
file = root_provider_fixtures['folder_metadata_forward_slash']
path = GoogleDrivePath('/we/love/you/conrad').child(file['name'], folder=True)
parsed = GoogleDriveFolderMetadata(file, path)

assert parsed.provider == 'googledrive'
assert parsed.id == item['id']
assert parsed.name == item['title']
assert parsed.extra == {'revisionId': item['version']}
assert parsed.id == file['id']
assert parsed.name == file['name']
assert parsed.extra == {'revisionId': file['version']}
assert parsed.path == '/' + os.path.join(*[x.raw for x in path.parts]) + '/'
assert parsed.materialized_path == str(path)
assert parsed.export_name == item['title']
assert parsed.export_name == file['name']

def test_revision_metadata(self, revision_fixtures):
item = revision_fixtures['revision_metadata']
parsed = GoogleDriveRevision(item)
revision = revision_fixtures['revision_metadata']
parsed = GoogleDriveRevision(revision)

assert parsed.version_identifier == 'revision'
assert parsed.version == item['id']
assert parsed.modified == item['modifiedDate']
assert parsed.version == revision['id']
assert parsed.modified == revision['modifiedTime']
Loading