Skip to content

Commit

Permalink
add test infrastructure and switch to MIT license
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Jan 1, 2017
1 parent a67ab4d commit 975d5d2
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 378 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ report.html
!.gitkeep
!.travis.yml
!src/pycloud
.cache
.eggs
.tox
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
graft src/collective
graft src/pycloud
graft docs
include *.rst
global-exclude *.pyc
global-exclude *.py[co]
339 changes: 0 additions & 339 deletions docs/LICENSE.GPL

This file was deleted.

31 changes: 19 additions & 12 deletions docs/LICENSE.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
collective.foo Copyright 2017, b'Tom Gross'
The MIT License

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
Copyright (c) 2017 Tom Gross

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
====================
collective.foo
pycloud
====================

User documentation
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ force_single_line = True
lines_after_imports = 2
line_length = 200
not_skip = __init__.py

[aliass]
test=tox
12 changes: 5 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
name='pycloud',
version='1.0a1',
description="A client library for pCloud",
long_description=long_description,
long_description='', #long_description,
# Get more from https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Environment :: Web Environment",
"Programming Language :: Python",
"Programming Language :: Python :: 3.5",
"Operating System :: OS Independent",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"License :: OSI Approved :: MIT License",
],
keywords='Python pCloud REST',
author='Tom Gross',
author_email='[email protected]',
url='https://pypi.python.org/pypi/pycloud',
license='GPL version 2',
license='MIT',
packages=find_packages('src', exclude=['ez_setup']),
package_dir={'': 'src'},
include_package_data=True,
Expand All @@ -38,10 +40,6 @@
'requests',
'setuptools',
],
extras_require={
'test': [
],
},
entry_points={
'console_scripts': [
'pycloud-cli = pycloud.api:main',
Expand Down
56 changes: 39 additions & 17 deletions src/pycloud/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from hashlib import sha1

import argparse
import requests
from hashlib import sha1
import sys


def main():
Expand All @@ -22,35 +24,55 @@ def __init__(self, username, password):
self.password = password.encode('utf-8')
self.auth_token = self.get_auth_token()

def _do_request(self, method, authenticate=True, **kw):
if authenticate:
params = {'auth': self.auth_token}
else:
params = {}
params.update(kw)
resp = requests.get(self.endpoint + method, params=params)
return resp.json()


# Authentication
def getdigest(self):
resp = requests.get(self.endpoint + 'getdigest')
return bytes(resp.json()['digest'], 'utf-8')
resp = self._do_request('getdigest', authenticate=False)
return bytes(resp['digest'], 'utf-8')

def get_auth_token(self):
digest = self.getdigest()
passworddigest = sha1(
self.password +
bytes(sha1(self.username).hexdigest(), 'utf-8') +
digest)
resp = requests.get(self.endpoint + 'userinfo',
params={'getauth': 1,
'logout': 1,
'username': self.username,
'digest': digest,
'passworddigest': passworddigest.hexdigest()}
)
return resp.json()['auth']
params={'getauth': 1,
'logout': 1,
'username': self.username,
'digest': digest,
'passworddigest': passworddigest.hexdigest()}
resp = self._do_request('userinfo', authenticate=False, **params)
return resp['auth']

# Folders
def listfolder(self, path=None, folderid=0):
params = {'auth': self.auth_token}
if path is not None:
def createfolder(self, path=None, folderid=0, name=''):
pass

def listfolder(self, path=None, folderid=None):
params = {}
if folderid is not None:
params['folderid'] = folderid
elif path is not None:
params['path'] = path
else:
params['folderid'] = folderid
resp = requests.get(self.endpoint + 'listfolder', params=params)
return resp.json()
raise('Either `folderid` or `path` must be specified!')
api_method = sys._getframe().f_code.co_name
return self._do_request(method, **params)

def renamefolder(self):
print(sys._getframe().f_code.co_name)

deletefolder = listfolder
deletefolderrecursive = listfolder


if __name__ == '__main__':
Expand Down
Empty file removed src/pycloud/tests/__init__.py
Empty file.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/pycloud/tests/test_validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#

class TestPathIdentifier(object):

def test_validiate(self):
assert 1 == 1
37 changes: 37 additions & 0 deletions src/pycloud/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from decorator import decorator

def validate_folder_identifier():
"""A decorator that tests whether `path` or `folderid` has been specified.
Usage:
@validate_folder_identifier
def foo(path=None, folderid=None, c=None):
pass
"""
def _validate_folder_identifier(func):
"""The actual decorator"""
signature_params = _get_arg_spec(func, required_params)

def wrapped(f, *args, **kwargs):
"""The wrapped function"""
if folderid is not None:
params['folderid'] = folderid
elif path is not None:
params['path'] = path
else:
raise ValueError('Either `folderid` or `path` must be specified!')
supplied_args = _get_supplied_args(signature_params, args, kwargs)

missing = [p for p in required_params if p not in supplied_args]
if len(missing):
raise MissingParameterError(
'Missing required parameter(s): {0}'.format(
', '.join(missing))
)

return f(*args, **kwargs)

return decorator(wrapped, func)

return _validate_folder_identifier

1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest >= 2.8
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[testenv]
deps =
-rtest_requirements.txt
commands = py.test
usedevelop = True

0 comments on commit 975d5d2

Please sign in to comment.