forked from czervenka/gapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports subset of file Drive API. Note that upload methods (insert, patch, update) are not yet supported.
- Loading branch information
Showing
4 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from .client import ApiService | ||
import calendar | ||
import tasks | ||
import drive | ||
|
||
|
||
class Api(object): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2013 Lukas Marek <lukas.marek@gmail.com> | ||
# | ||
# 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. | ||
# | ||
__author__ = 'Lukas Marek <lukas.marek@gmail.com>' | ||
|
||
|
||
from .client import ApiService, ApiResource | ||
|
||
|
||
class Service(ApiService): | ||
|
||
_base_url = 'https://www.googleapis.com/drive/v2' | ||
_default_scope = 'https://www.googleapis.com/auth/drive' | ||
|
||
@property | ||
def _resources(self): | ||
return [Files, Revisions, Changes, About] | ||
|
||
ApiService._services['drive'] = Service | ||
|
||
|
||
class Files(ApiResource): | ||
_name = 'files' | ||
_methods = 'list', 'get', 'insert', 'update', 'patch', 'delete', 'touch', 'trash', 'untrash' | ||
_base_path = '/files' | ||
|
||
def _api_touch(self, id, **kwargs): | ||
return self._service.fetch(self._get_item_url({'id': id}) + '/touch', method='POST', params=kwargs) | ||
|
||
def _api_trash(self, id, **kwargs): | ||
return self._service.fetch(self._get_item_url({'id': id}) + '/trash', method='POST', params=kwargs) | ||
|
||
def _api_untrash(self, id, **kwargs): | ||
return self._service.fetch(self._get_item_url({'id': id}) + '/untrash', method='POST', params=kwargs) | ||
|
||
|
||
class Revisions(ApiResource): | ||
_name = 'revisions' | ||
_methods = 'get', 'list', 'patch', 'update' | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(Revisions, self).__init__(*args, **kwargs) | ||
self.file_id = None | ||
|
||
@property | ||
def _base_path(self): | ||
if self.file_id is None: | ||
raise ValueError('Unknown file_id!') | ||
return '/files/%s/revisions' % self.file_id | ||
|
||
|
||
class About(ApiResource): | ||
_name = 'about' | ||
_methods = ['get'] | ||
_base_path = '/about' | ||
|
||
def _api_get(self, **kwargs): | ||
return self._service.fetch(self._get_item_url({}), method='GET', params=kwargs) | ||
|
||
|
||
|
||
|
||
class Changes(ApiResource): | ||
_name = 'changes' | ||
_methods = 'get', 'list' | ||
_base_path = '/changes' | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[nosetests] | ||
with-gae=NOSE_WITH_GAE | ||
with-gae=true | ||
verbosity=3 | ||
with-isolation=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from unittest import TestCase | ||
from mock import patch | ||
import mock | ||
from nose import with_setup | ||
|
||
|
||
__author__ = 'krtek' | ||
|
||
KEY = """INSERT KEY HERE""" | ||
EMAIL = 'xxx@developer.gserviceaccount.com' | ||
IMPERSONATE = 'admin@d22.myapps.cz' | ||
|
||
|
||
def get_gae_mock_memcache(): | ||
memcache = mock.MagicMock() | ||
memcache.get, memcache.set = mock.MagicMock(), mock.MagicMock() | ||
memcache.get.return_value = None | ||
return memcache | ||
|
||
class TestDrive(TestCase): | ||
|
||
def setUp(self): | ||
from gapi import Api | ||
self.api = Api(['drive'],EMAIL , KEY, IMPERSONATE) | ||
|
||
@patch('google.appengine.api.memcache', get_gae_mock_memcache()) | ||
def test_drive_list(self): | ||
files = self.api.drive.files.list()['items'] | ||
self.assertGreater(len(files), 0) | ||
|
||
@patch('google.appengine.api.memcache', get_gae_mock_memcache()) | ||
def test_drive_touch(self): | ||
file = self.api.drive.files.list()['items'][0] | ||
self.api.drive.files.touch(file['id']) | ||
|
||
@patch('google.appengine.api.memcache', get_gae_mock_memcache()) | ||
def test_trash(self): | ||
file = self.api.drive.files.list()['items'][0] | ||
self.api.drive.files.trash(file['id']) | ||
self.api.drive.files.untrash(file['id']) | ||
|
||
@patch('google.appengine.api.memcache', get_gae_mock_memcache()) | ||
def test_revisions(self): | ||
file = self.api.drive.files.list()['items'][0] | ||
revs_api = self.api.drive.revisions | ||
revs_api.file_id = file['id'] | ||
self.assertGreater(len(revs_api.list()), 0) | ||
|
||
@patch('google.appengine.api.memcache', get_gae_mock_memcache()) | ||
def test_revisions_empty_file_id(self): | ||
self.assertRaises(ValueError, self.api.drive.revisions.list) | ||
|
||
@patch('google.appengine.api.memcache', get_gae_mock_memcache()) | ||
def test_changes(self): | ||
self.assertEquals(self.api.drive.changes.list(), 'x') | ||
changes = self.api.drive.changes.list()['items'] | ||
self.assertGreater(0, changes) | ||
self.api.drive.changes.get(changes[0]['id']) | ||
|
||
@patch('google.appengine.api.memcache', get_gae_mock_memcache()) | ||
def test_about(self): | ||
self.assertGreater(self.api.drive.about.get(), 0) | ||
|
||
|
||
|
||
|
||
|