Renamed OpenPhoto to Trovebox
This commit is contained in:
parent
57b593d245
commit
6f70330994
30 changed files with 368 additions and 365 deletions
49
README.rst
49
README.rst
|
@ -5,12 +5,13 @@ OpenPhoto/Trovebox Python Library
|
||||||
:alt: Build Status
|
:alt: Build Status
|
||||||
:target: https://travis-ci.org/photo/openphoto-python
|
:target: https://travis-ci.org/photo/openphoto-python
|
||||||
|
|
||||||
.. image:: https://pypip.in/v/openphoto/badge.png
|
.. image:: https://pypip.in/v/trovebox/badge.png
|
||||||
:alt: Python Package Index (PyPI)
|
:alt: Python Package Index (PyPI)
|
||||||
:target: https://pypi.python.org/pypi/openphoto
|
:target: https://pypi.python.org/pypi/trovebox
|
||||||
|
|
||||||
This library works with any `OpenPhoto <https://github.com/photo>`__ server
|
This library works with any Trovebox server, either
|
||||||
(including the `Trovebox <http://trovebox.com>`__ hosted service).
|
`Self-hosted <https://github.com/photo>`__, or using the
|
||||||
|
`Trovebox hosted service<http://trovebox.com>`__).
|
||||||
It provides full access to your photos and metadata, via a simple
|
It provides full access to your photos and metadata, via a simple
|
||||||
Pythonic API.
|
Pythonic API.
|
||||||
|
|
||||||
|
@ -18,11 +19,11 @@ Installation
|
||||||
============
|
============
|
||||||
::
|
::
|
||||||
|
|
||||||
pip install openphoto
|
pip install trovebox
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
=============
|
=============
|
||||||
See the `OpenPhoto/Trovebox API Documentation <https://trovebox.com/documentation>`__
|
See the `Trovebox API Documentation <https://trovebox.com/documentation>`__
|
||||||
for full API documentation, including Python examples.
|
for full API documentation, including Python examples.
|
||||||
|
|
||||||
All development takes place at the `openphoto-python GitHub site <https://github.com/photo/openphoto-python>`__.
|
All development takes place at the `openphoto-python GitHub site <https://github.com/photo/openphoto-python>`__.
|
||||||
|
@ -30,9 +31,9 @@ All development takes place at the `openphoto-python GitHub site <https://github
|
||||||
Credentials
|
Credentials
|
||||||
===========
|
===========
|
||||||
For full access to your photos, you need to create the following config
|
For full access to your photos, you need to create the following config
|
||||||
file in ``~/.config/openphoto/default``::
|
file in ``~/.config/trovebox/default``::
|
||||||
|
|
||||||
# ~/.config/openphoto/default
|
# ~/.config/trovebox/default
|
||||||
host = your.host.com
|
host = your.host.com
|
||||||
consumerKey = your_consumer_key
|
consumerKey = your_consumer_key
|
||||||
consumerSecret = your_consumer_secret
|
consumerSecret = your_consumer_secret
|
||||||
|
@ -52,14 +53,14 @@ Using the library
|
||||||
=================
|
=================
|
||||||
::
|
::
|
||||||
|
|
||||||
from openphoto import OpenPhoto
|
from trovebox import Trovebox
|
||||||
client = OpenPhoto()
|
client = Trovebox()
|
||||||
photos = client.photos.list()
|
photos = client.photos.list()
|
||||||
photos[0].update(tags=["tag1", "tag2"])
|
photos[0].update(tags=["tag1", "tag2"])
|
||||||
print(photos[0].tags)
|
print(photos[0].tags)
|
||||||
|
|
||||||
The OpenPhoto Python class hierarchy mirrors the
|
The Trovebox Python class hierarchy mirrors the
|
||||||
`OpenPhoto/Trovebox API <https://trovebox.com/documentation>`__ endpoint layout.
|
`Trovebox API <https://trovebox.com/documentation>`__ endpoint layout.
|
||||||
For example, the calls in the example above use the following API endpoints:
|
For example, the calls in the example above use the following API endpoints:
|
||||||
|
|
||||||
* ``client.photos.list() -> /photos/list.json``
|
* ``client.photos.list() -> /photos/list.json``
|
||||||
|
@ -72,22 +73,22 @@ You can also access the API at a lower level using GET/POST methods::
|
||||||
|
|
||||||
API Versioning
|
API Versioning
|
||||||
==============
|
==============
|
||||||
It may be useful to lock your application to a particular version of the OpenPhoto API.
|
It may be useful to lock your application to a particular version of the Trovebox API.
|
||||||
This ensures that future API updates won't cause unexpected breakages.
|
This ensures that future API updates won't cause unexpected breakages.
|
||||||
|
|
||||||
To do this, add the optional ``api_version`` parameter when creating the client object::
|
To do this, add the optional ``api_version`` parameter when creating the client object::
|
||||||
|
|
||||||
from openphoto import OpenPhoto
|
from trovebox import Trovebox
|
||||||
client = OpenPhoto(api_version=2)
|
client = Trovebox(api_version=2)
|
||||||
|
|
||||||
Commandline Tool
|
Commandline Tool
|
||||||
================
|
================
|
||||||
You can run commands to the OpenPhoto API from your shell!
|
You can run commands to the Trovebox API from your shell!
|
||||||
|
|
||||||
These are the options you can pass to the shell program::
|
These are the options you can pass to the shell program::
|
||||||
|
|
||||||
--help # Display help text
|
--help # Display help text
|
||||||
-c config_file # Either the name of a config file in ~/.config/openphoto/ or a full path to a config file
|
-c config_file # Either the name of a config file in ~/.config/trovebox/ or a full path to a config file
|
||||||
-h hostname # Overrides config_file for unauthenticated API calls
|
-h hostname # Overrides config_file for unauthenticated API calls
|
||||||
-e endpoint # [default=/photos/list.json]
|
-e endpoint # [default=/photos/list.json]
|
||||||
-X method # [default=GET]
|
-X method # [default=GET]
|
||||||
|
@ -98,9 +99,9 @@ These are the options you can pass to the shell program::
|
||||||
|
|
||||||
Commandline Examples
|
Commandline Examples
|
||||||
--------------------
|
--------------------
|
||||||
Upload a public photo to the host specified in ```~/.config/openphoto/default```::
|
Upload a public photo to the host specified in ```~/.config/trovebox/default```::
|
||||||
|
|
||||||
openphoto -p -X POST -e /photo/upload.json -F 'photo=@/path/to/photo/jpg' -F 'permission=1'
|
trovebox -p -X POST -e /photo/upload.json -F 'photo=@/path/to/photo/jpg' -F 'permission=1'
|
||||||
{
|
{
|
||||||
"code":201,
|
"code":201,
|
||||||
"message":"Photo 1eo uploaded successfully",
|
"message":"Photo 1eo uploaded successfully",
|
||||||
|
@ -112,9 +113,9 @@ Upload a public photo to the host specified in ```~/.config/openphoto/default```
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Get a thumbnail URL from current.openphoto.me (unauthenticated access)::
|
Get a thumbnail URL from current.trovebox.com (unauthenticated access)::
|
||||||
|
|
||||||
openphoto -h current.openphoto.me -p -e /photo/62/view.json -F 'returnSizes=20x20'
|
openphoto -h current.trovebox.com -p -e /photo/62/view.json -F 'returnSizes=20x20'
|
||||||
{
|
{
|
||||||
"code":200,
|
"code":200,
|
||||||
"message":"Photo 62",
|
"message":"Photo 62",
|
||||||
|
@ -125,11 +126,11 @@ Get a thumbnail URL from current.openphoto.me (unauthenticated access)::
|
||||||
],
|
],
|
||||||
...
|
...
|
||||||
...
|
...
|
||||||
"path20x20":"http://current.openphoto.me/photo/62/create/36c0a/20x20.jpg",
|
"path20x20":"http://current.trovebox.com/photo/62/create/36c0a/20x20.jpg",
|
||||||
"pathBase":"http://awesomeness.openphoto.me/base/201203/7ae997-Boracay-Philippines-007.jpg",
|
"pathBase":"http://awesomeness.trovebox.com/base/201203/7ae997-Boracay-Philippines-007.jpg",
|
||||||
"permission":"1",
|
"permission":"1",
|
||||||
"photo20x20":[
|
"photo20x20":[
|
||||||
"http://current.openphoto.me/photo/62/create/36c0a/20x20.jpg",
|
"http://current.trovebox.com/photo/62/create/36c0a/20x20.jpg",
|
||||||
13,
|
13,
|
||||||
20
|
20
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import openphoto.main
|
|
||||||
openphoto.main.main()
|
|
4
bin/trovebox
Executable file
4
bin/trovebox
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import trovebox.main
|
||||||
|
trovebox.main.main()
|
|
@ -1,35 +0,0 @@
|
||||||
from openphoto.openphoto_http import OpenPhotoHttp
|
|
||||||
from openphoto.errors import *
|
|
||||||
from openphoto._version import __version__
|
|
||||||
import openphoto.api_photo
|
|
||||||
import openphoto.api_tag
|
|
||||||
import openphoto.api_album
|
|
||||||
|
|
||||||
LATEST_API_VERSION = 2
|
|
||||||
|
|
||||||
class OpenPhoto(OpenPhotoHttp):
|
|
||||||
"""
|
|
||||||
Client library for OpenPhoto
|
|
||||||
If no parameters are specified, config is loaded from the default
|
|
||||||
location (~/.config/openphoto/default).
|
|
||||||
The config_file parameter is used to specify an alternate config file.
|
|
||||||
If the host parameter is specified, no config file is loaded and
|
|
||||||
OAuth tokens (consumer*, token*) can optionally be specified.
|
|
||||||
All requests will include the api_version path, if specified.
|
|
||||||
This should be used to ensure that your application will continue to work
|
|
||||||
even if the OpenPhoto API is updated to a new revision.
|
|
||||||
"""
|
|
||||||
def __init__(self, config_file=None, host=None,
|
|
||||||
consumer_key='', consumer_secret='',
|
|
||||||
token='', token_secret='',
|
|
||||||
api_version=None):
|
|
||||||
OpenPhotoHttp.__init__(self, config_file, host,
|
|
||||||
consumer_key, consumer_secret,
|
|
||||||
token, token_secret, api_version)
|
|
||||||
|
|
||||||
self.photos = openphoto.api_photo.ApiPhotos(self)
|
|
||||||
self.photo = openphoto.api_photo.ApiPhoto(self)
|
|
||||||
self.tags = openphoto.api_tag.ApiTags(self)
|
|
||||||
self.tag = openphoto.api_tag.ApiTag(self)
|
|
||||||
self.albums = openphoto.api_album.ApiAlbums(self)
|
|
||||||
self.album = openphoto.api_album.ApiAlbum(self)
|
|
|
@ -9,28 +9,28 @@ tput setaf 3
|
||||||
echo
|
echo
|
||||||
echo "Testing latest self-hosted site..."
|
echo "Testing latest self-hosted site..."
|
||||||
tput sgr0
|
tput sgr0
|
||||||
export OPENPHOTO_TEST_CONFIG=test
|
export TROVEBOX_TEST_CONFIG=test
|
||||||
unset OPENPHOTO_TEST_SERVER_API
|
unset TROVEBOX_TEST_SERVER_API
|
||||||
python -m unittest discover --catch tests/functional
|
python -m unittest discover --catch tests/functional
|
||||||
|
|
||||||
# Test server running APIv1 OpenPhoto instance
|
# Test server running APIv1 Trovebox instance
|
||||||
# Install from photo/frontend commit 660b2ab
|
# Install from photo/frontend commit 660b2ab
|
||||||
tput setaf 3
|
tput setaf 3
|
||||||
echo
|
echo
|
||||||
echo "Testing APIv1 self-hosted site..."
|
echo "Testing APIv1 self-hosted site..."
|
||||||
tput sgr0
|
tput sgr0
|
||||||
export OPENPHOTO_TEST_CONFIG=test-apiv1
|
export TROVEBOX_TEST_CONFIG=test-apiv1
|
||||||
export OPENPHOTO_TEST_SERVER_API=1
|
export TROVEBOX_TEST_SERVER_API=1
|
||||||
python -m unittest discover --catch tests/functional
|
python -m unittest discover --catch tests/functional
|
||||||
|
|
||||||
# Test server running v3.0.8 OpenPhoto instance
|
# Test server running v3.0.8 Trovebox instance
|
||||||
# Install from photo/frontend commit e9d81de57b
|
# Install from photo/frontend commit e9d81de57b
|
||||||
tput setaf 3
|
tput setaf 3
|
||||||
echo
|
echo
|
||||||
echo "Testing v3.0.8 self-hosted site..."
|
echo "Testing v3.0.8 self-hosted site..."
|
||||||
tput sgr0
|
tput sgr0
|
||||||
export OPENPHOTO_TEST_CONFIG=test-3.0.8
|
export TROVEBOX_TEST_CONFIG=test-3.0.8
|
||||||
unset OPENPHOTO_TEST_SERVER_API
|
unset TROVEBOX_TEST_SERVER_API
|
||||||
python -m unittest discover --catch tests/functional
|
python -m unittest discover --catch tests/functional
|
||||||
|
|
||||||
# Test account on hosted trovebox.com site
|
# Test account on hosted trovebox.com site
|
||||||
|
@ -38,7 +38,7 @@ tput setaf 3
|
||||||
echo
|
echo
|
||||||
echo "Testing latest hosted site..."
|
echo "Testing latest hosted site..."
|
||||||
tput sgr0
|
tput sgr0
|
||||||
export OPENPHOTO_TEST_CONFIG=test-hosted
|
export TROVEBOX_TEST_CONFIG=test-hosted
|
||||||
unset OPENPHOTO_TEST_SERVER_API
|
unset TROVEBOX_TEST_SERVER_API
|
||||||
python -m unittest discover --catch tests/functional
|
python -m unittest discover --catch tests/functional
|
||||||
|
|
||||||
|
|
17
setup.py
17
setup.py
|
@ -4,11 +4,11 @@ import sys
|
||||||
requires = ['requests', 'requests_oauthlib']
|
requires = ['requests', 'requests_oauthlib']
|
||||||
|
|
||||||
console_script = """[console_scripts]
|
console_script = """[console_scripts]
|
||||||
openphoto = openphoto.main:main
|
trovebox = trovebox.main:main
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# from openphoto._version import __version__
|
# from trovebox._version import __version__
|
||||||
exec(open("openphoto/_version.py").read())
|
exec(open("trovebox/_version.py").read())
|
||||||
|
|
||||||
# Check the Python version
|
# Check the Python version
|
||||||
(major, minor) = sys.version_info[:2]
|
(major, minor) = sys.version_info[:2]
|
||||||
|
@ -23,18 +23,19 @@ try:
|
||||||
}
|
}
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
kw = {'scripts': ['bin/openphoto'],
|
kw = {'scripts': ['bin/trovebox'],
|
||||||
'requires': requires}
|
'requires': requires}
|
||||||
|
|
||||||
setup(name='openphoto',
|
setup(name='trovebox',
|
||||||
version=__version__,
|
version=__version__,
|
||||||
description='The official Python client library for Trovebox/OpenPhoto',
|
description='The official Python client library for the Trovebox photo service',
|
||||||
long_description=open("README.rst").read(),
|
long_description=open("README.rst").read(),
|
||||||
author='Pete Burgers, James Walker',
|
author='Pete Burgers, James Walker',
|
||||||
url='https://github.com/photo/openphoto-python',
|
url='https://github.com/photo/openphoto-python',
|
||||||
packages=['openphoto'],
|
packages=['trovebox'],
|
||||||
data_files=['README.rst'],
|
data_files=['README.rst'],
|
||||||
keywords=['openphoto', 'pyopenphoto', 'openphoto-python', 'trovebox'],
|
keywords=['openphoto', 'pyopenphoto', 'openphoto-python',
|
||||||
|
'trovebox', 'pytrovebox', 'openphoto-trovebox'],
|
||||||
classifiers=['Development Status :: 4 - Beta',
|
classifiers=['Development Status :: 4 - Beta',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
'License :: OSI Approved :: Apache Software License',
|
'License :: OSI Approved :: Apache Software License',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
OpenPhoto/Trovebox Python Testing
|
Trovebox Python Testing
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
###Unit Tests
|
###Unit Tests
|
||||||
|
@ -26,8 +26,8 @@ To run the unit tests against all supported Python versions, use ```tox```:
|
||||||
|
|
||||||
###Functional Tests
|
###Functional Tests
|
||||||
|
|
||||||
The functional tests check that the openphoto-python library interoperates
|
The functional tests check that the Trovebox python library interoperates
|
||||||
correctly with a real OpenPhoto/Trovebox server.
|
correctly with a real Trovebox server.
|
||||||
|
|
||||||
They are slow to run and rely on a stable HTTP connection to a test server.
|
They are slow to run and rely on a stable HTTP connection to a test server.
|
||||||
|
|
||||||
|
|
|
@ -1,34 +1,34 @@
|
||||||
Functional Testing
|
Functional Testing
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
These functional tests check that the openphoto-python library interoperates
|
These functional tests check that the Trovebox python library interoperates
|
||||||
correctly with a real OpenPhoto/Trovebox server.
|
correctly with a real Trovebox server.
|
||||||
|
|
||||||
They are slow to run, and require a stable HTTP connection to a test server.
|
They are slow to run, and require a stable HTTP connection to a test server.
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
<a name="requirements"></a>
|
<a name="requirements"></a>
|
||||||
### Requirements
|
### Requirements
|
||||||
A computer, Python and an empty OpenPhoto/Trovebox test host.
|
A computer, Python and an empty Trovebox test host.
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
<a name="setup"></a>
|
<a name="setup"></a>
|
||||||
### Setting up
|
### Setting up
|
||||||
|
|
||||||
Create a ``~/.config/openphoto/test`` config file containing the following:
|
Create a ``~/.config/trovebox/test`` config file containing the following:
|
||||||
|
|
||||||
# ~/.config/openphoto/test
|
# ~/.config/trovebox/test
|
||||||
host = your.host.com
|
host = your.host.com
|
||||||
consumerKey = your_consumer_key
|
consumerKey = your_consumer_key
|
||||||
consumerSecret = your_consumer_secret
|
consumerSecret = your_consumer_secret
|
||||||
token = your_access_token
|
token = your_access_token
|
||||||
tokenSecret = your_access_token_secret
|
tokenSecret = your_access_token_secret
|
||||||
|
|
||||||
Make sure this is an empty test server, **not a production OpenPhoto server!!!**
|
Make sure this is an empty test server, **not a production Trovebox server!!!**
|
||||||
|
|
||||||
You can specify an alternate test config file with the following environment variable:
|
You can specify an alternate test config file with the following environment variable:
|
||||||
|
|
||||||
export OPENPHOTO_TEST_CONFIG=test2
|
export TROVEBOX_TEST_CONFIG=test2
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
<a name="running"></a>
|
<a name="running"></a>
|
||||||
|
@ -37,28 +37,28 @@ You can specify an alternate test config file with the following environment var
|
||||||
The following instructions are for Python 2.7. You can adapt them for earlier
|
The following instructions are for Python 2.7. You can adapt them for earlier
|
||||||
Python versions using the ``unittest2`` package.
|
Python versions using the ``unittest2`` package.
|
||||||
|
|
||||||
cd /path/to/openphoto-python
|
cd /path/to/trovebox-python
|
||||||
python -m unittest discover -c tests/functional
|
python -m unittest discover -c tests/functional
|
||||||
|
|
||||||
The "-c" lets you stop the tests gracefully with \[CTRL\]-c.
|
The "-c" lets you stop the tests gracefully with \[CTRL\]-c.
|
||||||
|
|
||||||
The easiest way to run a subset of the tests is with the ``nose`` package:
|
The easiest way to run a subset of the tests is with the ``nose`` package:
|
||||||
|
|
||||||
cd /path/to/openphoto-python
|
cd /path/to/trovebox-python
|
||||||
nosetests -v -s --nologcapture tests/functional/test_albums.py:TestAlbums.test_view
|
nosetests -v -s --nologcapture tests/functional/test_albums.py:TestAlbums.test_view
|
||||||
|
|
||||||
All HTTP requests and responses are recorded in the file ``tests.log``.
|
All HTTP requests and responses are recorded in the file ``tests.log``.
|
||||||
|
|
||||||
You can enable more verbose output to stdout with the following environment variable:
|
You can enable more verbose output to stdout with the following environment variable:
|
||||||
|
|
||||||
export OPENPHOTO_TEST_DEBUG=1
|
export TROVEBOX_TEST_DEBUG=1
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
<a name="test_details"></a>
|
<a name="test_details"></a>
|
||||||
### Test Details
|
### Test Details
|
||||||
|
|
||||||
These tests are intended to verify the openphoto-python library.
|
These tests are intended to verify the Trovebox python library.
|
||||||
They don't provide comprehensive testing of the OpenPhoto API,
|
They don't provide comprehensive testing of the Trovebox API,
|
||||||
there are PHP unit tests for that.
|
there are PHP unit tests for that.
|
||||||
|
|
||||||
Each test class is run as follows:
|
Each test class is run as follows:
|
||||||
|
@ -84,11 +84,11 @@ Remove all photos, tags and albums
|
||||||
By default, all currently supported API versions will be tested.
|
By default, all currently supported API versions will be tested.
|
||||||
It's useful to test servers that only support older API versions.
|
It's useful to test servers that only support older API versions.
|
||||||
To restrict the testing to a specific maximum API version, use the
|
To restrict the testing to a specific maximum API version, use the
|
||||||
``OPENPHOTO_TEST_SERVER_API`` environment variable.
|
``TROVEBOX_TEST_SERVER_API`` environment variable.
|
||||||
|
|
||||||
For example, to restrict testing to APIv1 and APIv2:
|
For example, to restrict testing to APIv1 and APIv2:
|
||||||
|
|
||||||
export OPENPHOTO_TEST_SERVER_API=2
|
export TROVEBOX_TEST_SERVER_API=2
|
||||||
|
|
||||||
<a name="full_regression"></a>
|
<a name="full_regression"></a>
|
||||||
### Full Regression Test
|
### Full Regression Test
|
||||||
|
@ -96,7 +96,7 @@ For example, to restrict testing to APIv1 and APIv2:
|
||||||
The ``run_functional_tests`` script runs all functional tests against
|
The ``run_functional_tests`` script runs all functional tests against
|
||||||
all supported API versions.
|
all supported API versions.
|
||||||
|
|
||||||
To use it, you must set up multiple OpenPhoto instances and create the following
|
To use it, you must set up multiple Trovebox instances and create the following
|
||||||
config files containing your credentials:
|
config files containing your credentials:
|
||||||
|
|
||||||
test : Latest self-hosted site (from photo/frontend master branch)
|
test : Latest self-hosted site (from photo/frontend master branch)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class TestAlbums(test_base.TestBase):
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
""" Test that an album can be updated """
|
""" Test that an album can be updated """
|
||||||
# Update the album using the OpenPhoto class,
|
# Update the album using the Trovebox class,
|
||||||
# passing in the album object
|
# passing in the album object
|
||||||
new_name = "New Name"
|
new_name = "New Name"
|
||||||
self.client.album.update(self.albums[0], name=new_name)
|
self.client.album.update(self.albums[0], name=new_name)
|
||||||
|
@ -38,7 +38,7 @@ class TestAlbums(test_base.TestBase):
|
||||||
self.albums = self.client.albums.list()
|
self.albums = self.client.albums.list()
|
||||||
self.assertEqual(self.albums[0].name, new_name)
|
self.assertEqual(self.albums[0].name, new_name)
|
||||||
|
|
||||||
# Update the album using the OpenPhoto class, passing in the album id
|
# Update the album using the Trovebox class, passing in the album id
|
||||||
new_name = "Another New Name"
|
new_name = "Another New Name"
|
||||||
self.client.album.update(self.albums[0].id, name=new_name)
|
self.client.album.update(self.albums[0].id, name=new_name)
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,11 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
|
|
||||||
def get_test_server_api():
|
def get_test_server_api():
|
||||||
return int(os.getenv("OPENPHOTO_TEST_SERVER_API",
|
return int(os.getenv("TROVEBOX_TEST_SERVER_API",
|
||||||
openphoto.LATEST_API_VERSION))
|
trovebox.LATEST_API_VERSION))
|
||||||
|
|
||||||
class TestBase(unittest.TestCase):
|
class TestBase(unittest.TestCase):
|
||||||
TEST_TITLE = "Test Image - delete me!"
|
TEST_TITLE = "Test Image - delete me!"
|
||||||
|
@ -21,8 +21,8 @@ class TestBase(unittest.TestCase):
|
||||||
testcase_name = "(unknown testcase)"
|
testcase_name = "(unknown testcase)"
|
||||||
api_version = None
|
api_version = None
|
||||||
|
|
||||||
config_file = os.getenv("OPENPHOTO_TEST_CONFIG", "test")
|
config_file = os.getenv("TROVEBOX_TEST_CONFIG", "test")
|
||||||
debug = (os.getenv("OPENPHOTO_TEST_DEBUG", "0") == "1")
|
debug = (os.getenv("TROVEBOX_TEST_DEBUG", "0") == "1")
|
||||||
|
|
||||||
def __init__(self, *args, **kwds):
|
def __init__(self, *args, **kwds):
|
||||||
super(TestBase, self).__init__(*args, **kwds)
|
super(TestBase, self).__init__(*args, **kwds)
|
||||||
|
@ -42,7 +42,7 @@ class TestBase(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
print("\nTesting %s v%d" % (cls.testcase_name, cls.api_version))
|
print("\nTesting %s v%d" % (cls.testcase_name, cls.api_version))
|
||||||
|
|
||||||
cls.client = openphoto.OpenPhoto(config_file=cls.config_file,
|
cls.client = trovebox.Trovebox(config_file=cls.config_file,
|
||||||
api_version=cls.api_version)
|
api_version=cls.api_version)
|
||||||
|
|
||||||
if cls.client.photos.list() != []:
|
if cls.client.photos.list() != []:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
from tests.functional import test_base
|
from tests.functional import test_base
|
||||||
|
|
||||||
class TestFramework(test_base.TestBase):
|
class TestFramework(test_base.TestBase):
|
||||||
|
@ -16,8 +16,8 @@ class TestFramework(test_base.TestBase):
|
||||||
"""
|
"""
|
||||||
API v0 has a special hello world message
|
API v0 has a special hello world message
|
||||||
"""
|
"""
|
||||||
client = openphoto.OpenPhoto(config_file=self.config_file,
|
client = trovebox.Trovebox(config_file=self.config_file,
|
||||||
api_version=0)
|
api_version=0)
|
||||||
result = client.get("hello.json")
|
result = client.get("hello.json")
|
||||||
self.assertEqual(result['message'],
|
self.assertEqual(result['message'],
|
||||||
"Hello, world! This is version zero of the API!")
|
"Hello, world! This is version zero of the API!")
|
||||||
|
@ -28,8 +28,8 @@ class TestFramework(test_base.TestBase):
|
||||||
For all API versions >0, we get a generic hello world message
|
For all API versions >0, we get a generic hello world message
|
||||||
"""
|
"""
|
||||||
for api_version in range(1, test_base.get_test_server_api() + 1):
|
for api_version in range(1, test_base.get_test_server_api() + 1):
|
||||||
client = openphoto.OpenPhoto(config_file=self.config_file,
|
client = trovebox.Trovebox(config_file=self.config_file,
|
||||||
api_version=api_version)
|
api_version=api_version)
|
||||||
result = client.get("hello.json")
|
result = client.get("hello.json")
|
||||||
self.assertEqual(result['message'], "Hello, world!")
|
self.assertEqual(result['message'], "Hello, world!")
|
||||||
self.assertEqual(result['result']['__route__'],
|
self.assertEqual(result['result']['__route__'],
|
||||||
|
@ -40,8 +40,8 @@ class TestFramework(test_base.TestBase):
|
||||||
If the API version is unspecified,
|
If the API version is unspecified,
|
||||||
we get a generic hello world message.
|
we get a generic hello world message.
|
||||||
"""
|
"""
|
||||||
client = openphoto.OpenPhoto(config_file=self.config_file,
|
client = trovebox.Trovebox(config_file=self.config_file,
|
||||||
api_version=None)
|
api_version=None)
|
||||||
result = client.get("hello.json")
|
result = client.get("hello.json")
|
||||||
self.assertEqual(result['message'], "Hello, world!")
|
self.assertEqual(result['message'], "Hello, world!")
|
||||||
self.assertEqual(result['result']['__route__'], "/hello.json")
|
self.assertEqual(result['result']['__route__'], "/hello.json")
|
||||||
|
@ -51,7 +51,8 @@ class TestFramework(test_base.TestBase):
|
||||||
If the API version is unsupported, we should get an error
|
If the API version is unsupported, we should get an error
|
||||||
(ValueError, since the returned 404 HTML page is not valid JSON)
|
(ValueError, since the returned 404 HTML page is not valid JSON)
|
||||||
"""
|
"""
|
||||||
client = openphoto.OpenPhoto(config_file=self.config_file,
|
version = trovebox.LATEST_API_VERSION + 1
|
||||||
api_version=openphoto.LATEST_API_VERSION + 1)
|
client = trovebox.Trovebox(config_file=self.config_file,
|
||||||
with self.assertRaises(openphoto.OpenPhoto404Error):
|
api_version=version)
|
||||||
|
with self.assertRaises(trovebox.Trovebox404Error):
|
||||||
client.get("hello.json")
|
client.get("hello.json")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
from tests.functional import test_base
|
from tests.functional import test_base
|
||||||
|
|
||||||
class TestPhotos(test_base.TestBase):
|
class TestPhotos(test_base.TestBase):
|
||||||
|
@ -8,9 +8,9 @@ class TestPhotos(test_base.TestBase):
|
||||||
|
|
||||||
def test_delete_upload(self):
|
def test_delete_upload(self):
|
||||||
""" Test photo deletion and upload """
|
""" Test photo deletion and upload """
|
||||||
# Delete one photo using the OpenPhoto class, passing in the id
|
# Delete one photo using the Trovebox class, passing in the id
|
||||||
self.assertTrue(self.client.photo.delete(self.photos[0].id))
|
self.assertTrue(self.client.photo.delete(self.photos[0].id))
|
||||||
# Delete one photo using the OpenPhoto class, passing in the object
|
# Delete one photo using the Trovebox class, passing in the object
|
||||||
self.assertTrue(self.client.photo.delete(self.photos[1]))
|
self.assertTrue(self.client.photo.delete(self.photos[1]))
|
||||||
# And another using the Photo object directly
|
# And another using the Photo object directly
|
||||||
self.assertTrue(self.photos[2].delete())
|
self.assertTrue(self.photos[2].delete())
|
||||||
|
@ -49,7 +49,7 @@ class TestPhotos(test_base.TestBase):
|
||||||
|
|
||||||
def test_edit(self):
|
def test_edit(self):
|
||||||
""" Check that the edit request returns an HTML form """
|
""" Check that the edit request returns an HTML form """
|
||||||
# Test using the OpenPhoto class
|
# Test using the Trovebox class
|
||||||
html = self.client.photo.edit(self.photos[0])
|
html = self.client.photo.edit(self.photos[0])
|
||||||
self.assertIn("<form", html.lower())
|
self.assertIn("<form", html.lower())
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class TestPhotos(test_base.TestBase):
|
||||||
def test_upload_duplicate(self):
|
def test_upload_duplicate(self):
|
||||||
""" Ensure that duplicate photos are rejected """
|
""" Ensure that duplicate photos are rejected """
|
||||||
# Attempt to upload a duplicate
|
# Attempt to upload a duplicate
|
||||||
with self.assertRaises(openphoto.OpenPhotoDuplicateError):
|
with self.assertRaises(trovebox.TroveboxDuplicateError):
|
||||||
self.client.photo.upload("tests/data/test_photo1.jpg",
|
self.client.photo.upload("tests/data/test_photo1.jpg",
|
||||||
title=self.TEST_TITLE)
|
title=self.TEST_TITLE)
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class TestPhotos(test_base.TestBase):
|
||||||
photo = self.photos[0]
|
photo = self.photos[0]
|
||||||
self.assertNotEqual(photo.title, title)
|
self.assertNotEqual(photo.title, title)
|
||||||
|
|
||||||
# Add the title to a photo using the OpenPhoto class
|
# Add the title to a photo using the Trovebox class
|
||||||
ret_val = self.client.photo.update(photo, title=title)
|
ret_val = self.client.photo.update(photo, title=title)
|
||||||
|
|
||||||
# Check that it's there
|
# Check that it's there
|
||||||
|
@ -117,7 +117,7 @@ class TestPhotos(test_base.TestBase):
|
||||||
self.assertFalse(hasattr(photo, "path9x9"))
|
self.assertFalse(hasattr(photo, "path9x9"))
|
||||||
self.assertFalse(hasattr(photo, "path19x19"))
|
self.assertFalse(hasattr(photo, "path19x19"))
|
||||||
|
|
||||||
# View at a particular size using the OpenPhoto class
|
# View at a particular size using the Trovebox class
|
||||||
photo = self.client.photo.view(photo, returnSizes="9x9")
|
photo = self.client.photo.view(photo, returnSizes="9x9")
|
||||||
self.assertTrue(hasattr(photo, "path9x9"))
|
self.assertTrue(hasattr(photo, "path9x9"))
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ class TestTags(test_base.TestBase):
|
||||||
"since there are no fields that can be updated")
|
"since there are no fields that can be updated")
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
""" Test that a tag can be updated """
|
""" Test that a tag can be updated """
|
||||||
# Update the tag using the OpenPhoto class, passing in the tag object
|
# Update the tag using the Trovebox class, passing in the tag object
|
||||||
owner = "test1@openphoto.me"
|
owner = "test1@trovebox.com"
|
||||||
ret_val = self.client.tag.update(self.tags[0], owner=owner)
|
ret_val = self.client.tag.update(self.tags[0], owner=owner)
|
||||||
|
|
||||||
# Check that the tag is updated
|
# Check that the tag is updated
|
||||||
|
@ -61,8 +61,8 @@ class TestTags(test_base.TestBase):
|
||||||
self.assertEqual(self.tags[0].owner, owner)
|
self.assertEqual(self.tags[0].owner, owner)
|
||||||
self.assertEqual(ret_val.owner, owner)
|
self.assertEqual(ret_val.owner, owner)
|
||||||
|
|
||||||
# Update the tag using the OpenPhoto class, passing in the tag id
|
# Update the tag using the Trovebox class, passing in the tag id
|
||||||
owner = "test2@openphoto.me"
|
owner = "test2@trovebox.com"
|
||||||
ret_val = self.client.tag.update(self.TEST_TAG, owner=owner)
|
ret_val = self.client.tag.update(self.TEST_TAG, owner=owner)
|
||||||
|
|
||||||
# Check that the tag is updated
|
# Check that the tag is updated
|
||||||
|
@ -71,7 +71,7 @@ class TestTags(test_base.TestBase):
|
||||||
self.assertEqual(ret_val.owner, owner)
|
self.assertEqual(ret_val.owner, owner)
|
||||||
|
|
||||||
# Update the tag using the Tag object directly
|
# Update the tag using the Tag object directly
|
||||||
owner = "test3@openphoto.me"
|
owner = "test3@trovebox.com"
|
||||||
ret_val = self.tags[0].update(owner=owner)
|
ret_val = self.tags[0].update(owner=owner)
|
||||||
|
|
||||||
# Check that the tag is updated
|
# Check that the tag is updated
|
||||||
|
|
|
@ -5,7 +5,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
|
|
||||||
class TestAlbums(unittest.TestCase):
|
class TestAlbums(unittest.TestCase):
|
||||||
test_host = "test.example.com"
|
test_host = "test.example.com"
|
||||||
|
@ -18,8 +18,8 @@ class TestAlbums(unittest.TestCase):
|
||||||
"name": "Album 2",
|
"name": "Album 2",
|
||||||
"totalRows": 2}]
|
"totalRows": 2}]
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host)
|
self.client = trovebox.Trovebox(host=self.test_host)
|
||||||
self.test_albums = [openphoto.objects.Album(self.client, album)
|
self.test_albums = [trovebox.objects.Album(self.client, album)
|
||||||
for album in self.test_albums_dict]
|
for album in self.test_albums_dict]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -27,7 +27,7 @@ class TestAlbums(unittest.TestCase):
|
||||||
return {"message": message, "code": code, "result": result}
|
return {"message": message, "code": code, "result": result}
|
||||||
|
|
||||||
class TestAlbumsList(TestAlbums):
|
class TestAlbumsList(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_albums_list(self, mock_get):
|
def test_albums_list(self, mock_get):
|
||||||
"""Check that the album list is returned correctly"""
|
"""Check that the album list is returned correctly"""
|
||||||
mock_get.return_value = self._return_value(self.test_albums_dict)
|
mock_get.return_value = self._return_value(self.test_albums_dict)
|
||||||
|
@ -39,7 +39,7 @@ class TestAlbumsList(TestAlbums):
|
||||||
self.assertEqual(result[1].id, "2")
|
self.assertEqual(result[1].id, "2")
|
||||||
self.assertEqual(result[1].name, "Album 2")
|
self.assertEqual(result[1].name, "Album 2")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_albums_list_returns_cover_photos(self, mock_get):
|
def test_albums_list_returns_cover_photos(self, mock_get):
|
||||||
"""Check that the album list returns cover photo objects"""
|
"""Check that the album list returns cover photo objects"""
|
||||||
mock_get.return_value = self._return_value(self.test_albums_dict)
|
mock_get.return_value = self._return_value(self.test_albums_dict)
|
||||||
|
@ -56,7 +56,7 @@ class TestAlbumsList(TestAlbums):
|
||||||
self.assertEqual(result[1].cover.tags, ["tag3", "tag4"])
|
self.assertEqual(result[1].cover.tags, ["tag3", "tag4"])
|
||||||
|
|
||||||
class TestAlbumCreate(TestAlbums):
|
class TestAlbumCreate(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_create(self, mock_post):
|
def test_album_create(self, mock_post):
|
||||||
"""Check that an album can be created"""
|
"""Check that an album can be created"""
|
||||||
mock_post.return_value = self._return_value(self.test_albums_dict[0])
|
mock_post.return_value = self._return_value(self.test_albums_dict[0])
|
||||||
|
@ -69,7 +69,7 @@ class TestAlbumCreate(TestAlbums):
|
||||||
self.assertEqual(result.cover.tags, ["tag1", "tag2"])
|
self.assertEqual(result.cover.tags, ["tag1", "tag2"])
|
||||||
|
|
||||||
class TestAlbumDelete(TestAlbums):
|
class TestAlbumDelete(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_delete(self, mock_post):
|
def test_album_delete(self, mock_post):
|
||||||
"""Check that an album can be deleted"""
|
"""Check that an album can be deleted"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -77,7 +77,7 @@ class TestAlbumDelete(TestAlbums):
|
||||||
mock_post.assert_called_with("/album/1/delete.json")
|
mock_post.assert_called_with("/album/1/delete.json")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_delete_id(self, mock_post):
|
def test_album_delete_id(self, mock_post):
|
||||||
"""Check that an album can be deleted using its ID"""
|
"""Check that an album can be deleted using its ID"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -85,14 +85,14 @@ class TestAlbumDelete(TestAlbums):
|
||||||
mock_post.assert_called_with("/album/1/delete.json")
|
mock_post.assert_called_with("/album/1/delete.json")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_delete_failure(self, mock_post):
|
def test_album_delete_failure(self, mock_post):
|
||||||
"""Check that an exception is raised if an album cannot be deleted"""
|
"""Check that an exception is raised if an album cannot be deleted"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.album.delete(self.test_albums[0])
|
self.client.album.delete(self.test_albums[0])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_object_delete(self, mock_post):
|
def test_album_object_delete(self, mock_post):
|
||||||
"""Check that an album can be deleted using the album object directly"""
|
"""Check that an album can be deleted using the album object directly"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -104,76 +104,76 @@ class TestAlbumDelete(TestAlbums):
|
||||||
self.assertEqual(album.id, None)
|
self.assertEqual(album.id, None)
|
||||||
self.assertEqual(album.name, None)
|
self.assertEqual(album.name, None)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_object_delete_failure(self, mock_post):
|
def test_album_object_delete_failure(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that an exception is raised if an album cannot be deleted
|
Check that an exception is raised if an album cannot be deleted
|
||||||
when using the album object directly
|
when using the album object directly
|
||||||
"""
|
"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.test_albums[0].delete()
|
self.test_albums[0].delete()
|
||||||
|
|
||||||
class TestAlbumForm(TestAlbums):
|
class TestAlbumForm(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_form(self, _):
|
def test_album_form(self, _):
|
||||||
""" If album.form gets implemented, write a test! """
|
""" If album.form gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.album.form(self.test_albums[0])
|
self.client.album.form(self.test_albums[0])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_form_id(self, _):
|
def test_album_form_id(self, _):
|
||||||
""" If album.form gets implemented, write a test! """
|
""" If album.form gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.album.form("1")
|
self.client.album.form("1")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_object_form(self, _):
|
def test_album_object_form(self, _):
|
||||||
""" If album.form gets implemented, write a test! """
|
""" If album.form gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.test_albums[0].form()
|
self.test_albums[0].form()
|
||||||
|
|
||||||
class TestAlbumAddPhotos(TestAlbums):
|
class TestAlbumAddPhotos(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_add_photos(self, _):
|
def test_album_add_photos(self, _):
|
||||||
""" If album.add_photos gets implemented, write a test! """
|
""" If album.add_photos gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.album.add_photos(self.test_albums[0], ["Photo Objects"])
|
self.client.album.add_photos(self.test_albums[0], ["Photo Objects"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_add_photos_id(self, _):
|
def test_album_add_photos_id(self, _):
|
||||||
""" If album.add_photos gets implemented, write a test! """
|
""" If album.add_photos gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.album.add_photos("1", ["Photo Objects"])
|
self.client.album.add_photos("1", ["Photo Objects"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_object_add_photos(self, _):
|
def test_album_object_add_photos(self, _):
|
||||||
""" If album.add_photos gets implemented, write a test! """
|
""" If album.add_photos gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.test_albums[0].add_photos(["Photo Objects"])
|
self.test_albums[0].add_photos(["Photo Objects"])
|
||||||
|
|
||||||
class TestAlbumRemovePhotos(TestAlbums):
|
class TestAlbumRemovePhotos(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_remove_photos(self, _):
|
def test_album_remove_photos(self, _):
|
||||||
""" If album.remove_photos gets implemented, write a test! """
|
""" If album.remove_photos gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.album.remove_photos(self.test_albums[0],
|
self.client.album.remove_photos(self.test_albums[0],
|
||||||
["Photo Objects"])
|
["Photo Objects"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_remove_photos_id(self, _):
|
def test_album_remove_photos_id(self, _):
|
||||||
""" If album.remove_photos gets implemented, write a test! """
|
""" If album.remove_photos gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.album.remove_photos("1", ["Photo Objects"])
|
self.client.album.remove_photos("1", ["Photo Objects"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_object_remove_photos(self, _):
|
def test_album_object_remove_photos(self, _):
|
||||||
""" If album.remove_photos gets implemented, write a test! """
|
""" If album.remove_photos gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.test_albums[0].remove_photos(["Photo Objects"])
|
self.test_albums[0].remove_photos(["Photo Objects"])
|
||||||
|
|
||||||
class TestAlbumUpdate(TestAlbums):
|
class TestAlbumUpdate(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_update(self, mock_post):
|
def test_album_update(self, mock_post):
|
||||||
"""Check that an album can be updated"""
|
"""Check that an album can be updated"""
|
||||||
mock_post.return_value = self._return_value(self.test_albums_dict[1])
|
mock_post.return_value = self._return_value(self.test_albums_dict[1])
|
||||||
|
@ -184,7 +184,7 @@ class TestAlbumUpdate(TestAlbums):
|
||||||
self.assertEqual(result.cover.id, "2b")
|
self.assertEqual(result.cover.id, "2b")
|
||||||
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_update_id(self, mock_post):
|
def test_album_update_id(self, mock_post):
|
||||||
"""Check that an album can be updated using its ID"""
|
"""Check that an album can be updated using its ID"""
|
||||||
mock_post.return_value = self._return_value(self.test_albums_dict[1])
|
mock_post.return_value = self._return_value(self.test_albums_dict[1])
|
||||||
|
@ -195,7 +195,7 @@ class TestAlbumUpdate(TestAlbums):
|
||||||
self.assertEqual(result.cover.id, "2b")
|
self.assertEqual(result.cover.id, "2b")
|
||||||
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_album_object_update(self, mock_post):
|
def test_album_object_update(self, mock_post):
|
||||||
"""Check that an album can be updated using the album object directly"""
|
"""Check that an album can be updated using the album object directly"""
|
||||||
mock_post.return_value = self._return_value(self.test_albums_dict[1])
|
mock_post.return_value = self._return_value(self.test_albums_dict[1])
|
||||||
|
@ -208,7 +208,7 @@ class TestAlbumUpdate(TestAlbums):
|
||||||
self.assertEqual(album.cover.tags, ["tag3", "tag4"])
|
self.assertEqual(album.cover.tags, ["tag3", "tag4"])
|
||||||
|
|
||||||
class TestAlbumView(TestAlbums):
|
class TestAlbumView(TestAlbums):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_album_view(self, mock_get):
|
def test_album_view(self, mock_get):
|
||||||
"""Check that an album can be viewed"""
|
"""Check that an album can be viewed"""
|
||||||
mock_get.return_value = self._return_value(self.test_albums_dict[1])
|
mock_get.return_value = self._return_value(self.test_albums_dict[1])
|
||||||
|
@ -219,7 +219,7 @@ class TestAlbumView(TestAlbums):
|
||||||
self.assertEqual(result.cover.id, "2b")
|
self.assertEqual(result.cover.id, "2b")
|
||||||
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_album_view_id(self, mock_get):
|
def test_album_view_id(self, mock_get):
|
||||||
"""Check that an album can be viewed using its ID"""
|
"""Check that an album can be viewed using its ID"""
|
||||||
mock_get.return_value = self._return_value(self.test_albums_dict[1])
|
mock_get.return_value = self._return_value(self.test_albums_dict[1])
|
||||||
|
@ -230,7 +230,7 @@ class TestAlbumView(TestAlbums):
|
||||||
self.assertEqual(result.cover.id, "2b")
|
self.assertEqual(result.cover.id, "2b")
|
||||||
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
self.assertEqual(result.cover.tags, ["tag3", "tag4"])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_album_object_view(self, mock_get):
|
def test_album_object_view(self, mock_get):
|
||||||
"""Check that an album can be viewed using the album object directly"""
|
"""Check that an album can be viewed using the album object directly"""
|
||||||
mock_get.return_value = self._return_value(self.test_albums_dict[1])
|
mock_get.return_value = self._return_value(self.test_albums_dict[1])
|
||||||
|
|
|
@ -11,8 +11,8 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
from openphoto.main import main
|
from trovebox.main import main
|
||||||
|
|
||||||
class TestException(Exception):
|
class TestException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -23,53 +23,53 @@ def raise_exception(_):
|
||||||
class TestCli(unittest.TestCase):
|
class TestCli(unittest.TestCase):
|
||||||
test_file = os.path.join("tests", "unit", "data", "test_file.txt")
|
test_file = os.path.join("tests", "unit", "data", "test_file.txt")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
def test_defaults(self, _, mock_openphoto):
|
def test_defaults(self, _, mock_trovebox):
|
||||||
"""Check that the default behaviour is correct"""
|
"""Check that the default behaviour is correct"""
|
||||||
get = mock_openphoto.return_value.get
|
get = mock_trovebox.return_value.get
|
||||||
main([])
|
main([])
|
||||||
mock_openphoto.assert_called_with(config_file=None)
|
mock_trovebox.assert_called_with(config_file=None)
|
||||||
get.assert_called_with("/photos/list.json", process_response=False)
|
get.assert_called_with("/photos/list.json", process_response=False)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
def test_config(self, _, mock_openphoto):
|
def test_config(self, _, mock_trovebox):
|
||||||
"""Check that a config file can be specified"""
|
"""Check that a config file can be specified"""
|
||||||
main(["--config=test"])
|
main(["--config=test"])
|
||||||
mock_openphoto.assert_called_with(config_file="test")
|
mock_trovebox.assert_called_with(config_file="test")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
def test_get(self, mock_stdout, mock_openphoto):
|
def test_get(self, mock_stdout, mock_trovebox):
|
||||||
"""Check that the get operation is working"""
|
"""Check that the get operation is working"""
|
||||||
get = mock_openphoto.return_value.get
|
get = mock_trovebox.return_value.get
|
||||||
get.return_value = "Result"
|
get.return_value = "Result"
|
||||||
main(["-X", "GET", "-h", "test_host", "-e", "test_endpoint", "-F",
|
main(["-X", "GET", "-h", "test_host", "-e", "test_endpoint", "-F",
|
||||||
"field1=1", "-F", "field2=2"])
|
"field1=1", "-F", "field2=2"])
|
||||||
mock_openphoto.assert_called_with(host="test_host")
|
mock_trovebox.assert_called_with(host="test_host")
|
||||||
get.assert_called_with("test_endpoint", field1="1", field2="2",
|
get.assert_called_with("test_endpoint", field1="1", field2="2",
|
||||||
process_response=False)
|
process_response=False)
|
||||||
self.assertEqual(mock_stdout.getvalue(), "Result\n")
|
self.assertEqual(mock_stdout.getvalue(), "Result\n")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
def test_post(self, mock_stdout, mock_openphoto):
|
def test_post(self, mock_stdout, mock_trovebox):
|
||||||
"""Check that the post operation is working"""
|
"""Check that the post operation is working"""
|
||||||
post = mock_openphoto.return_value.post
|
post = mock_trovebox.return_value.post
|
||||||
post.return_value = "Result"
|
post.return_value = "Result"
|
||||||
main(["-X", "POST", "-h", "test_host", "-e", "test_endpoint", "-F",
|
main(["-X", "POST", "-h", "test_host", "-e", "test_endpoint", "-F",
|
||||||
"field1=1", "-F", "field2=2"])
|
"field1=1", "-F", "field2=2"])
|
||||||
mock_openphoto.assert_called_with(host="test_host")
|
mock_trovebox.assert_called_with(host="test_host")
|
||||||
post.assert_called_with("test_endpoint", field1="1", field2="2",
|
post.assert_called_with("test_endpoint", field1="1", field2="2",
|
||||||
files={}, process_response=False)
|
files={}, process_response=False)
|
||||||
self.assertEqual(mock_stdout.getvalue(), "Result\n")
|
self.assertEqual(mock_stdout.getvalue(), "Result\n")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
def test_post_files(self, _, mock_openphoto):
|
def test_post_files(self, _, mock_trovebox):
|
||||||
"""Check that files are posted correctly"""
|
"""Check that files are posted correctly"""
|
||||||
post = mock_openphoto.return_value.post
|
post = mock_trovebox.return_value.post
|
||||||
main(["-X", "POST", "-F", "photo=@%s" % self.test_file])
|
main(["-X", "POST", "-F", "photo=@%s" % self.test_file])
|
||||||
# It's not possible to directly compare the file object,
|
# It's not possible to directly compare the file object,
|
||||||
# so check it manually
|
# so check it manually
|
||||||
|
@ -104,7 +104,7 @@ class TestCli(unittest.TestCase):
|
||||||
mock_stdout.getvalue())
|
mock_stdout.getvalue())
|
||||||
self.assertIn("To get your credentials", mock_stdout.getvalue())
|
self.assertIn("To get your credentials", mock_stdout.getvalue())
|
||||||
|
|
||||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
def test_verbose(self, mock_stdout, _):
|
def test_verbose(self, mock_stdout, _):
|
||||||
"""Check that the verbose option is working"""
|
"""Check that the verbose option is working"""
|
||||||
|
@ -112,11 +112,11 @@ class TestCli(unittest.TestCase):
|
||||||
self.assertIn("Method: GET", mock_stdout.getvalue())
|
self.assertIn("Method: GET", mock_stdout.getvalue())
|
||||||
self.assertIn("Endpoint: /photos/list.json", mock_stdout.getvalue())
|
self.assertIn("Endpoint: /photos/list.json", mock_stdout.getvalue())
|
||||||
|
|
||||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
def test_pretty_print(self, mock_stdout, mock_openphoto):
|
def test_pretty_print(self, mock_stdout, mock_trovebox):
|
||||||
"""Check that the pretty-print option is working"""
|
"""Check that the pretty-print option is working"""
|
||||||
get = mock_openphoto.return_value.get
|
get = mock_trovebox.return_value.get
|
||||||
get.return_value = '{"test":1}'
|
get.return_value = '{"test":1}'
|
||||||
main(["-p"])
|
main(["-p"])
|
||||||
self.assertEqual(mock_stdout.getvalue(), '{\n "test":1\n}\n')
|
self.assertEqual(mock_stdout.getvalue(), '{\n "test":1\n}\n')
|
||||||
|
@ -125,5 +125,5 @@ class TestCli(unittest.TestCase):
|
||||||
def test_version(self, mock_stdout):
|
def test_version(self, mock_stdout):
|
||||||
"""Check that the version string is correctly printed"""
|
"""Check that the version string is correctly printed"""
|
||||||
main(["--version"])
|
main(["--version"])
|
||||||
self.assertEqual(mock_stdout.getvalue(), openphoto.__version__ + "\n")
|
self.assertEqual(mock_stdout.getvalue(), trovebox.__version__ + "\n")
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,10 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from openphoto import OpenPhoto
|
from trovebox import Trovebox
|
||||||
|
|
||||||
CONFIG_HOME_PATH = os.path.join("tests", "config")
|
CONFIG_HOME_PATH = os.path.join("tests", "config")
|
||||||
CONFIG_PATH = os.path.join(CONFIG_HOME_PATH, "openphoto")
|
CONFIG_PATH = os.path.join(CONFIG_HOME_PATH, "trovebox")
|
||||||
|
|
||||||
class TestConfig(unittest.TestCase):
|
class TestConfig(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -41,7 +41,7 @@ class TestConfig(unittest.TestCase):
|
||||||
def test_default_config(self):
|
def test_default_config(self):
|
||||||
""" Ensure the default config is loaded """
|
""" Ensure the default config is loaded """
|
||||||
self.create_config("default", "Test Default Host")
|
self.create_config("default", "Test Default Host")
|
||||||
client = OpenPhoto()
|
client = Trovebox()
|
||||||
config = client.config
|
config = client.config
|
||||||
self.assertEqual(client.host, "Test Default Host")
|
self.assertEqual(client.host, "Test Default Host")
|
||||||
self.assertEqual(config.consumer_key, "default_consumer_key")
|
self.assertEqual(config.consumer_key, "default_consumer_key")
|
||||||
|
@ -53,7 +53,7 @@ class TestConfig(unittest.TestCase):
|
||||||
""" Ensure a custom config can be loaded """
|
""" Ensure a custom config can be loaded """
|
||||||
self.create_config("default", "Test Default Host")
|
self.create_config("default", "Test Default Host")
|
||||||
self.create_config("custom", "Test Custom Host")
|
self.create_config("custom", "Test Custom Host")
|
||||||
client = OpenPhoto(config_file="custom")
|
client = Trovebox(config_file="custom")
|
||||||
config = client.config
|
config = client.config
|
||||||
self.assertEqual(client.host, "Test Custom Host")
|
self.assertEqual(client.host, "Test Custom Host")
|
||||||
self.assertEqual(config.consumer_key, "custom_consumer_key")
|
self.assertEqual(config.consumer_key, "custom_consumer_key")
|
||||||
|
@ -65,7 +65,7 @@ class TestConfig(unittest.TestCase):
|
||||||
""" Ensure a full custom config path can be loaded """
|
""" Ensure a full custom config path can be loaded """
|
||||||
self.create_config("path", "Test Path Host")
|
self.create_config("path", "Test Path Host")
|
||||||
full_path = os.path.abspath(CONFIG_PATH)
|
full_path = os.path.abspath(CONFIG_PATH)
|
||||||
client = OpenPhoto(config_file=os.path.join(full_path, "path"))
|
client = Trovebox(config_file=os.path.join(full_path, "path"))
|
||||||
config = client.config
|
config = client.config
|
||||||
self.assertEqual(client.host, "Test Path Host")
|
self.assertEqual(client.host, "Test Path Host")
|
||||||
self.assertEqual(config.consumer_key, "path_consumer_key")
|
self.assertEqual(config.consumer_key, "path_consumer_key")
|
||||||
|
@ -76,7 +76,7 @@ class TestConfig(unittest.TestCase):
|
||||||
def test_host_override(self):
|
def test_host_override(self):
|
||||||
""" Ensure that specifying a host overrides the default config """
|
""" Ensure that specifying a host overrides the default config """
|
||||||
self.create_config("default", "Test Default Host")
|
self.create_config("default", "Test Default Host")
|
||||||
client = OpenPhoto(host="host_override")
|
client = Trovebox(host="host_override")
|
||||||
config = client.config
|
config = client.config
|
||||||
self.assertEqual(config.host, "host_override")
|
self.assertEqual(config.host, "host_override")
|
||||||
self.assertEqual(config.consumer_key, "")
|
self.assertEqual(config.consumer_key, "")
|
||||||
|
@ -87,14 +87,14 @@ class TestConfig(unittest.TestCase):
|
||||||
def test_missing_config_files(self):
|
def test_missing_config_files(self):
|
||||||
""" Ensure that missing config files raise exceptions """
|
""" Ensure that missing config files raise exceptions """
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(IOError):
|
||||||
OpenPhoto()
|
Trovebox()
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(IOError):
|
||||||
OpenPhoto(config_file="custom")
|
Trovebox(config_file="custom")
|
||||||
|
|
||||||
def test_host_and_config_file(self):
|
def test_host_and_config_file(self):
|
||||||
""" It's not valid to specify both a host and a config_file """
|
""" It's not valid to specify both a host and a config_file """
|
||||||
self.create_config("custom", "Test Custom Host")
|
self.create_config("custom", "Test Custom Host")
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
OpenPhoto(config_file="custom", host="host_override")
|
Trovebox(config_file="custom", host="host_override")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
|
|
||||||
class TestHttp(unittest.TestCase):
|
class TestHttp(unittest.TestCase):
|
||||||
test_host = "test.example.com"
|
test_host = "test.example.com"
|
||||||
|
@ -24,8 +24,8 @@ class TestHttp(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host,
|
self.client = trovebox.Trovebox(host=self.test_host,
|
||||||
**self.test_oauth)
|
**self.test_oauth)
|
||||||
|
|
||||||
def _register_uri(self, method, uri=test_uri, data=None, body=None,
|
def _register_uri(self, method, uri=test_uri, data=None, body=None,
|
||||||
**kwds):
|
**kwds):
|
||||||
|
@ -78,7 +78,7 @@ class TestHttp(unittest.TestCase):
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_get_without_oauth(self):
|
def test_get_without_oauth(self):
|
||||||
"""Check that the get method works without OAuth parameters"""
|
"""Check that the get method works without OAuth parameters"""
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host)
|
self.client = trovebox.Trovebox(host=self.test_host)
|
||||||
self._register_uri(httpretty.GET)
|
self._register_uri(httpretty.GET)
|
||||||
response = self.client.get(self.test_endpoint)
|
response = self.client.get(self.test_endpoint)
|
||||||
self.assertNotIn("authorization", self._last_request().headers)
|
self.assertNotIn("authorization", self._last_request().headers)
|
||||||
|
@ -87,9 +87,9 @@ class TestHttp(unittest.TestCase):
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_post_without_oauth(self):
|
def test_post_without_oauth(self):
|
||||||
"""Check that the post method fails without OAuth parameters"""
|
"""Check that the post method fails without OAuth parameters"""
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host)
|
self.client = trovebox.Trovebox(host=self.test_host)
|
||||||
self._register_uri(httpretty.POST)
|
self._register_uri(httpretty.POST)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.post(self.test_endpoint)
|
self.client.post(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -110,9 +110,9 @@ class TestHttp(unittest.TestCase):
|
||||||
def test_get_parameter_processing(self):
|
def test_get_parameter_processing(self):
|
||||||
"""Check that the parameter processing function is working"""
|
"""Check that the parameter processing function is working"""
|
||||||
self._register_uri(httpretty.GET)
|
self._register_uri(httpretty.GET)
|
||||||
photo = openphoto.objects.Photo(None, {"id": "photo_id"})
|
photo = trovebox.objects.Photo(None, {"id": "photo_id"})
|
||||||
album = openphoto.objects.Album(None, {"id": "album_id"})
|
album = trovebox.objects.Album(None, {"id": "album_id"})
|
||||||
tag = openphoto.objects.Tag(None, {"id": "tag_id"})
|
tag = trovebox.objects.Tag(None, {"id": "tag_id"})
|
||||||
self.client.get(self.test_endpoint,
|
self.client.get(self.test_endpoint,
|
||||||
photo=photo, album=album, tag=tag,
|
photo=photo, album=album, tag=tag,
|
||||||
list_=[photo, album, tag],
|
list_=[photo, album, tag],
|
||||||
|
@ -129,7 +129,7 @@ class TestHttp(unittest.TestCase):
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_get_with_api_version(self):
|
def test_get_with_api_version(self):
|
||||||
"""Check that an API version can be specified for the get method"""
|
"""Check that an API version can be specified for the get method"""
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host, api_version=1)
|
self.client = trovebox.Trovebox(host=self.test_host, api_version=1)
|
||||||
self._register_uri(httpretty.GET,
|
self._register_uri(httpretty.GET,
|
||||||
uri="http://%s/v1/%s" % (self.test_host,
|
uri="http://%s/v1/%s" % (self.test_host,
|
||||||
self.test_endpoint))
|
self.test_endpoint))
|
||||||
|
@ -138,8 +138,8 @@ class TestHttp(unittest.TestCase):
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_post_with_api_version(self):
|
def test_post_with_api_version(self):
|
||||||
"""Check that an API version can be specified for the post method"""
|
"""Check that an API version can be specified for the post method"""
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host, api_version=1,
|
self.client = trovebox.Trovebox(host=self.test_host, api_version=1,
|
||||||
**self.test_oauth)
|
**self.test_oauth)
|
||||||
self._register_uri(httpretty.POST,
|
self._register_uri(httpretty.POST,
|
||||||
uri="http://%s/v1/%s" % (self.test_host,
|
uri="http://%s/v1/%s" % (self.test_host,
|
||||||
self.test_endpoint))
|
self.test_endpoint))
|
||||||
|
|
|
@ -11,7 +11,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
|
|
||||||
class TestHttpErrors(unittest.TestCase):
|
class TestHttpErrors(unittest.TestCase):
|
||||||
test_host = "test.example.com"
|
test_host = "test.example.com"
|
||||||
|
@ -26,8 +26,8 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
"token_secret": "dummy"}
|
"token_secret": "dummy"}
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host,
|
self.client = trovebox.Trovebox(host=self.test_host,
|
||||||
**self.test_oauth)
|
**self.test_oauth)
|
||||||
|
|
||||||
def _register_uri(self, method, uri=test_uri,
|
def _register_uri(self, method, uri=test_uri,
|
||||||
data=None, body=None, status=200, **kwds):
|
data=None, body=None, status=200, **kwds):
|
||||||
|
@ -48,7 +48,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
to raise an exception
|
to raise an exception
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.GET, status=500)
|
self._register_uri(httpretty.GET, status=500)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.get(self.test_endpoint)
|
self.client.get(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -58,7 +58,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
to raise an exception
|
to raise an exception
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.POST, status=500)
|
self._register_uri(httpretty.POST, status=500)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.post(self.test_endpoint)
|
self.client.post(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -68,7 +68,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
to raise a 404 exception
|
to raise a 404 exception
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.GET, status=404)
|
self._register_uri(httpretty.GET, status=404)
|
||||||
with self.assertRaises(openphoto.OpenPhoto404Error):
|
with self.assertRaises(trovebox.Trovebox404Error):
|
||||||
self.client.get(self.test_endpoint)
|
self.client.get(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -78,7 +78,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
to raise a 404 exception
|
to raise a 404 exception
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.POST, status=404)
|
self._register_uri(httpretty.POST, status=404)
|
||||||
with self.assertRaises(openphoto.OpenPhoto404Error):
|
with self.assertRaises(trovebox.Trovebox404Error):
|
||||||
self.client.post(self.test_endpoint)
|
self.client.post(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -108,7 +108,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
even with an error status is returned
|
even with an error status is returned
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.GET, body="Invalid JSON", status=500)
|
self._register_uri(httpretty.GET, body="Invalid JSON", status=500)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.get(self.test_endpoint)
|
self.client.get(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -118,7 +118,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
even with an error status is returned
|
even with an error status is returned
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.POST, body="Invalid JSON", status=500)
|
self._register_uri(httpretty.POST, body="Invalid JSON", status=500)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.post(self.test_endpoint)
|
self.client.post(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -128,7 +128,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
even with a 404 status is returned
|
even with a 404 status is returned
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.GET, body="Invalid JSON", status=404)
|
self._register_uri(httpretty.GET, body="Invalid JSON", status=404)
|
||||||
with self.assertRaises(openphoto.OpenPhoto404Error):
|
with self.assertRaises(trovebox.Trovebox404Error):
|
||||||
self.client.get(self.test_endpoint)
|
self.client.get(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -138,7 +138,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
even with a 404 status is returned
|
even with a 404 status is returned
|
||||||
"""
|
"""
|
||||||
self._register_uri(httpretty.POST, body="Invalid JSON", status=404)
|
self._register_uri(httpretty.POST, body="Invalid JSON", status=404)
|
||||||
with self.assertRaises(openphoto.OpenPhoto404Error):
|
with self.assertRaises(trovebox.Trovebox404Error):
|
||||||
self.client.post(self.test_endpoint)
|
self.client.post(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -149,7 +149,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
data = {"message": "This photo already exists", "code": 409}
|
data = {"message": "This photo already exists", "code": 409}
|
||||||
self._register_uri(httpretty.GET, data=data, status=409)
|
self._register_uri(httpretty.GET, data=data, status=409)
|
||||||
with self.assertRaises(openphoto.OpenPhotoDuplicateError):
|
with self.assertRaises(trovebox.TroveboxDuplicateError):
|
||||||
self.client.get(self.test_endpoint)
|
self.client.get(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
@ -160,7 +160,7 @@ class TestHttpErrors(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
data = {"message": "This photo already exists", "code": 409}
|
data = {"message": "This photo already exists", "code": 409}
|
||||||
self._register_uri(httpretty.POST, data=data, status=409)
|
self._register_uri(httpretty.POST, data=data, status=409)
|
||||||
with self.assertRaises(openphoto.OpenPhotoDuplicateError):
|
with self.assertRaises(trovebox.TroveboxDuplicateError):
|
||||||
self.client.post(self.test_endpoint)
|
self.client.post(self.test_endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
|
|
@ -7,7 +7,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
|
|
||||||
class TestPhotos(unittest.TestCase):
|
class TestPhotos(unittest.TestCase):
|
||||||
test_host = "test.example.com"
|
test_host = "test.example.com"
|
||||||
|
@ -17,8 +17,8 @@ class TestPhotos(unittest.TestCase):
|
||||||
{"id": "2b", "tags": ["tag3", "tag4"],
|
{"id": "2b", "tags": ["tag3", "tag4"],
|
||||||
"totalPages": 1, "totalRows": 2}]
|
"totalPages": 1, "totalRows": 2}]
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host)
|
self.client = trovebox.Trovebox(host=self.test_host)
|
||||||
self.test_photos = [openphoto.objects.Photo(self.client, photo)
|
self.test_photos = [trovebox.objects.Photo(self.client, photo)
|
||||||
for photo in self.test_photos_dict]
|
for photo in self.test_photos_dict]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -26,7 +26,7 @@ class TestPhotos(unittest.TestCase):
|
||||||
return {"message": message, "code": code, "result": result}
|
return {"message": message, "code": code, "result": result}
|
||||||
|
|
||||||
class TestPhotosList(TestPhotos):
|
class TestPhotosList(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photos_list(self, mock_get):
|
def test_photos_list(self, mock_get):
|
||||||
"""Check that the photo list is returned correctly"""
|
"""Check that the photo list is returned correctly"""
|
||||||
mock_get.return_value = self._return_value(self.test_photos_dict)
|
mock_get.return_value = self._return_value(self.test_photos_dict)
|
||||||
|
@ -40,7 +40,7 @@ class TestPhotosList(TestPhotos):
|
||||||
self.assertEqual(result[1].tags, ["tag3", "tag4"])
|
self.assertEqual(result[1].tags, ["tag3", "tag4"])
|
||||||
|
|
||||||
class TestPhotosUpdate(TestPhotos):
|
class TestPhotosUpdate(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photos_update(self, mock_post):
|
def test_photos_update(self, mock_post):
|
||||||
"""Check that multiple photos can be updated"""
|
"""Check that multiple photos can be updated"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -49,7 +49,7 @@ class TestPhotosUpdate(TestPhotos):
|
||||||
ids=["1a", "2b"], title="Test")
|
ids=["1a", "2b"], title="Test")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photos_update_ids(self, mock_post):
|
def test_photos_update_ids(self, mock_post):
|
||||||
"""Check that multiple photos can be updated using their IDs"""
|
"""Check that multiple photos can be updated using their IDs"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -58,18 +58,18 @@ class TestPhotosUpdate(TestPhotos):
|
||||||
ids=["1a", "2b"], title="Test")
|
ids=["1a", "2b"], title="Test")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photos_update_failure(self, mock_post):
|
def test_photos_update_failure(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that an exception is raised if multiple photos
|
Check that an exception is raised if multiple photos
|
||||||
cannot be updated
|
cannot be updated
|
||||||
"""
|
"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.photos.update(self.test_photos, title="Test")
|
self.client.photos.update(self.test_photos, title="Test")
|
||||||
|
|
||||||
class TestPhotosDelete(TestPhotos):
|
class TestPhotosDelete(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photos_delete(self, mock_post):
|
def test_photos_delete(self, mock_post):
|
||||||
"""Check that multiple photos can be deleted"""
|
"""Check that multiple photos can be deleted"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -77,7 +77,7 @@ class TestPhotosDelete(TestPhotos):
|
||||||
mock_post.assert_called_with("/photos/delete.json", ids=["1a", "2b"])
|
mock_post.assert_called_with("/photos/delete.json", ids=["1a", "2b"])
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photos_delete_ids(self, mock_post):
|
def test_photos_delete_ids(self, mock_post):
|
||||||
"""Check that multiple photos can be deleted using their IDs"""
|
"""Check that multiple photos can be deleted using their IDs"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -85,18 +85,18 @@ class TestPhotosDelete(TestPhotos):
|
||||||
mock_post.assert_called_with("/photos/delete.json", ids=["1a", "2b"])
|
mock_post.assert_called_with("/photos/delete.json", ids=["1a", "2b"])
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photos_delete_failure(self, mock_post):
|
def test_photos_delete_failure(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that an exception is raised if multiple photos
|
Check that an exception is raised if multiple photos
|
||||||
cannot be deleted
|
cannot be deleted
|
||||||
"""
|
"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.photos.delete(self.test_photos)
|
self.client.photos.delete(self.test_photos)
|
||||||
|
|
||||||
class TestPhotoDelete(TestPhotos):
|
class TestPhotoDelete(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_delete(self, mock_post):
|
def test_photo_delete(self, mock_post):
|
||||||
"""Check that a photo can be deleted"""
|
"""Check that a photo can be deleted"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -104,7 +104,7 @@ class TestPhotoDelete(TestPhotos):
|
||||||
mock_post.assert_called_with("/photo/1a/delete.json")
|
mock_post.assert_called_with("/photo/1a/delete.json")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_delete_id(self, mock_post):
|
def test_photo_delete_id(self, mock_post):
|
||||||
"""Check that a photo can be deleted using its ID"""
|
"""Check that a photo can be deleted using its ID"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -112,14 +112,14 @@ class TestPhotoDelete(TestPhotos):
|
||||||
mock_post.assert_called_with("/photo/1a/delete.json")
|
mock_post.assert_called_with("/photo/1a/delete.json")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_delete_failure(self, mock_post):
|
def test_photo_delete_failure(self, mock_post):
|
||||||
"""Check that an exception is raised if a photo cannot be deleted"""
|
"""Check that an exception is raised if a photo cannot be deleted"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.photo.delete(self.test_photos[0])
|
self.client.photo.delete(self.test_photos[0])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_object_delete(self, mock_post):
|
def test_photo_object_delete(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that a photo can be deleted when using
|
Check that a photo can be deleted when using
|
||||||
|
@ -133,18 +133,18 @@ class TestPhotoDelete(TestPhotos):
|
||||||
self.assertEqual(photo.get_fields(), {})
|
self.assertEqual(photo.get_fields(), {})
|
||||||
self.assertEqual(photo.id, None)
|
self.assertEqual(photo.id, None)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_object_delete_failure(self, mock_post):
|
def test_photo_object_delete_failure(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that an exception is raised if a photo cannot be deleted
|
Check that an exception is raised if a photo cannot be deleted
|
||||||
when using the photo object directly
|
when using the photo object directly
|
||||||
"""
|
"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.test_photos[0].delete()
|
self.test_photos[0].delete()
|
||||||
|
|
||||||
class TestPhotoEdit(TestPhotos):
|
class TestPhotoEdit(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_edit(self, mock_get):
|
def test_photo_edit(self, mock_get):
|
||||||
"""Check that a the photo edit endpoint is working"""
|
"""Check that a the photo edit endpoint is working"""
|
||||||
mock_get.return_value = self._return_value({"markup": "<form/>"})
|
mock_get.return_value = self._return_value({"markup": "<form/>"})
|
||||||
|
@ -152,7 +152,7 @@ class TestPhotoEdit(TestPhotos):
|
||||||
mock_get.assert_called_with("/photo/1a/edit.json")
|
mock_get.assert_called_with("/photo/1a/edit.json")
|
||||||
self.assertEqual(result, "<form/>")
|
self.assertEqual(result, "<form/>")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_edit_id(self, mock_get):
|
def test_photo_edit_id(self, mock_get):
|
||||||
"""Check that a the photo edit endpoint is working when using an ID"""
|
"""Check that a the photo edit endpoint is working when using an ID"""
|
||||||
mock_get.return_value = self._return_value({"markup": "<form/>"})
|
mock_get.return_value = self._return_value({"markup": "<form/>"})
|
||||||
|
@ -160,7 +160,7 @@ class TestPhotoEdit(TestPhotos):
|
||||||
mock_get.assert_called_with("/photo/1a/edit.json")
|
mock_get.assert_called_with("/photo/1a/edit.json")
|
||||||
self.assertEqual(result, "<form/>")
|
self.assertEqual(result, "<form/>")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_object_edit(self, mock_get):
|
def test_photo_object_edit(self, mock_get):
|
||||||
"""
|
"""
|
||||||
Check that a the photo edit endpoint is working
|
Check that a the photo edit endpoint is working
|
||||||
|
@ -172,45 +172,45 @@ class TestPhotoEdit(TestPhotos):
|
||||||
self.assertEqual(result, "<form/>")
|
self.assertEqual(result, "<form/>")
|
||||||
|
|
||||||
class TestPhotoReplace(TestPhotos):
|
class TestPhotoReplace(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_replace(self, _):
|
def test_photo_replace(self, _):
|
||||||
""" If photo.replace gets implemented, write a test! """
|
""" If photo.replace gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.photo.replace(self.test_photos[0], self.test_file)
|
self.client.photo.replace(self.test_photos[0], self.test_file)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_replace_id(self, _):
|
def test_photo_replace_id(self, _):
|
||||||
""" If photo.replace gets implemented, write a test! """
|
""" If photo.replace gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.photo.replace("1a", self.test_file)
|
self.client.photo.replace("1a", self.test_file)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_object_replace(self, _):
|
def test_photo_object_replace(self, _):
|
||||||
""" If photo.replace gets implemented, write a test! """
|
""" If photo.replace gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.test_photos[0].replace(self.test_file)
|
self.test_photos[0].replace(self.test_file)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_replace_encoded(self, _):
|
def test_photo_replace_encoded(self, _):
|
||||||
""" If photo.replace_encoded gets implemented, write a test! """
|
""" If photo.replace_encoded gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.photo.replace_encoded(self.test_photos[0],
|
self.client.photo.replace_encoded(self.test_photos[0],
|
||||||
self.test_file)
|
self.test_file)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_replace_encoded_id(self, _):
|
def test_photo_replace_encoded_id(self, _):
|
||||||
""" If photo.replace_encoded gets implemented, write a test! """
|
""" If photo.replace_encoded gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.photo.replace_encoded("1a", self.test_file)
|
self.client.photo.replace_encoded("1a", self.test_file)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_object_replace_encoded(self, _):
|
def test_photo_object_replace_encoded(self, _):
|
||||||
""" If photo.replace_encoded gets implemented, write a test! """
|
""" If photo.replace_encoded gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.test_photos[0].replace_encoded(photo_file=self.test_file)
|
self.test_photos[0].replace_encoded(photo_file=self.test_file)
|
||||||
|
|
||||||
class TestPhotoUpdate(TestPhotos):
|
class TestPhotoUpdate(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_update(self, mock_post):
|
def test_photo_update(self, mock_post):
|
||||||
"""Check that a photo can be updated"""
|
"""Check that a photo can be updated"""
|
||||||
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
||||||
|
@ -218,7 +218,7 @@ class TestPhotoUpdate(TestPhotos):
|
||||||
mock_post.assert_called_with("/photo/1a/update.json", title="Test")
|
mock_post.assert_called_with("/photo/1a/update.json", title="Test")
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_update_id(self, mock_post):
|
def test_photo_update_id(self, mock_post):
|
||||||
"""Check that a photo can be updated using its ID"""
|
"""Check that a photo can be updated using its ID"""
|
||||||
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
||||||
|
@ -226,7 +226,7 @@ class TestPhotoUpdate(TestPhotos):
|
||||||
mock_post.assert_called_with("/photo/1a/update.json", title="Test")
|
mock_post.assert_called_with("/photo/1a/update.json", title="Test")
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_object_update(self, mock_post):
|
def test_photo_object_update(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that a photo can be updated
|
Check that a photo can be updated
|
||||||
|
@ -239,7 +239,7 @@ class TestPhotoUpdate(TestPhotos):
|
||||||
self.assertEqual(photo.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(photo.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
class TestPhotoView(TestPhotos):
|
class TestPhotoView(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_view(self, mock_get):
|
def test_photo_view(self, mock_get):
|
||||||
"""Check that a photo can be viewed"""
|
"""Check that a photo can be viewed"""
|
||||||
mock_get.return_value = self._return_value(self.test_photos_dict[1])
|
mock_get.return_value = self._return_value(self.test_photos_dict[1])
|
||||||
|
@ -248,7 +248,7 @@ class TestPhotoView(TestPhotos):
|
||||||
mock_get.assert_called_with("/photo/1a/view.json", returnSizes="20x20")
|
mock_get.assert_called_with("/photo/1a/view.json", returnSizes="20x20")
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_view_id(self, mock_get):
|
def test_photo_view_id(self, mock_get):
|
||||||
"""Check that a photo can be viewed using its ID"""
|
"""Check that a photo can be viewed using its ID"""
|
||||||
mock_get.return_value = self._return_value(self.test_photos_dict[1])
|
mock_get.return_value = self._return_value(self.test_photos_dict[1])
|
||||||
|
@ -256,7 +256,7 @@ class TestPhotoView(TestPhotos):
|
||||||
mock_get.assert_called_with("/photo/1a/view.json", returnSizes="20x20")
|
mock_get.assert_called_with("/photo/1a/view.json", returnSizes="20x20")
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_object_view(self, mock_get):
|
def test_photo_object_view(self, mock_get):
|
||||||
"""
|
"""
|
||||||
Check that a photo can be viewed
|
Check that a photo can be viewed
|
||||||
|
@ -269,7 +269,7 @@ class TestPhotoView(TestPhotos):
|
||||||
self.assertEqual(photo.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(photo.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
class TestPhotoUpload(TestPhotos):
|
class TestPhotoUpload(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_upload(self, mock_post):
|
def test_photo_upload(self, mock_post):
|
||||||
"""Check that a photo can be uploaded"""
|
"""Check that a photo can be uploaded"""
|
||||||
mock_post.return_value = self._return_value(self.test_photos_dict[0])
|
mock_post.return_value = self._return_value(self.test_photos_dict[0])
|
||||||
|
@ -284,7 +284,7 @@ class TestPhotoUpload(TestPhotos):
|
||||||
self.assertIn("photo", files)
|
self.assertIn("photo", files)
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[0])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[0])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_upload_encoded(self, mock_post):
|
def test_photo_upload_encoded(self, mock_post):
|
||||||
"""Check that a photo can be uploaded using Base64 encoding"""
|
"""Check that a photo can be uploaded using Base64 encoding"""
|
||||||
mock_post.return_value = self._return_value(self.test_photos_dict[0])
|
mock_post.return_value = self._return_value(self.test_photos_dict[0])
|
||||||
|
@ -296,26 +296,26 @@ class TestPhotoUpload(TestPhotos):
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[0])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[0])
|
||||||
|
|
||||||
class TestPhotoDynamicUrl(TestPhotos):
|
class TestPhotoDynamicUrl(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_dynamic_url(self, _):
|
def test_photo_dynamic_url(self, _):
|
||||||
""" If photo.dynamic_url gets implemented, write a test! """
|
""" If photo.dynamic_url gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.photo.dynamic_url(self.test_photos[0])
|
self.client.photo.dynamic_url(self.test_photos[0])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_dynamic_url_id(self, _):
|
def test_photo_dynamic_url_id(self, _):
|
||||||
""" If photo.dynamic_url gets implemented, write a test! """
|
""" If photo.dynamic_url gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.client.photo.dynamic_url("1a")
|
self.client.photo.dynamic_url("1a")
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_object_dynamic_url(self, _):
|
def test_photo_object_dynamic_url(self, _):
|
||||||
""" If photo.dynamic_url gets implemented, write a test! """
|
""" If photo.dynamic_url gets implemented, write a test! """
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
self.test_photos[0].dynamic_url()
|
self.test_photos[0].dynamic_url()
|
||||||
|
|
||||||
class TestPhotoNextPrevious(TestPhotos):
|
class TestPhotoNextPrevious(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_next_previous(self, mock_get):
|
def test_photo_next_previous(self, mock_get):
|
||||||
"""Check that the next/previous photos are returned"""
|
"""Check that the next/previous photos are returned"""
|
||||||
mock_get.return_value = self._return_value(
|
mock_get.return_value = self._return_value(
|
||||||
|
@ -328,7 +328,7 @@ class TestPhotoNextPrevious(TestPhotos):
|
||||||
self.assertEqual(result["previous"][0].get_fields(),
|
self.assertEqual(result["previous"][0].get_fields(),
|
||||||
self.test_photos_dict[1])
|
self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_next_previous_id(self, mock_get):
|
def test_photo_next_previous_id(self, mock_get):
|
||||||
"""
|
"""
|
||||||
Check that the next/previous photos are returned
|
Check that the next/previous photos are returned
|
||||||
|
@ -344,7 +344,7 @@ class TestPhotoNextPrevious(TestPhotos):
|
||||||
self.assertEqual(result["previous"][0].get_fields(),
|
self.assertEqual(result["previous"][0].get_fields(),
|
||||||
self.test_photos_dict[1])
|
self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_object_next_previous(self, mock_get):
|
def test_photo_object_next_previous(self, mock_get):
|
||||||
"""
|
"""
|
||||||
Check that the next/previous photos are returned
|
Check that the next/previous photos are returned
|
||||||
|
@ -360,7 +360,7 @@ class TestPhotoNextPrevious(TestPhotos):
|
||||||
self.assertEqual(result["previous"][0].get_fields(),
|
self.assertEqual(result["previous"][0].get_fields(),
|
||||||
self.test_photos_dict[1])
|
self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_next(self, mock_get):
|
def test_photo_next(self, mock_get):
|
||||||
"""Check that the next photos are returned"""
|
"""Check that the next photos are returned"""
|
||||||
mock_get.return_value = self._return_value(
|
mock_get.return_value = self._return_value(
|
||||||
|
@ -371,7 +371,7 @@ class TestPhotoNextPrevious(TestPhotos):
|
||||||
self.test_photos_dict[0])
|
self.test_photos_dict[0])
|
||||||
self.assertNotIn("previous", result)
|
self.assertNotIn("previous", result)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_previous(self, mock_get):
|
def test_photo_previous(self, mock_get):
|
||||||
"""Check that the previous photos are returned"""
|
"""Check that the previous photos are returned"""
|
||||||
mock_get.return_value = self._return_value(
|
mock_get.return_value = self._return_value(
|
||||||
|
@ -382,7 +382,7 @@ class TestPhotoNextPrevious(TestPhotos):
|
||||||
self.test_photos_dict[1])
|
self.test_photos_dict[1])
|
||||||
self.assertNotIn("next", result)
|
self.assertNotIn("next", result)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_photo_multiple_next_previous(self, mock_get):
|
def test_photo_multiple_next_previous(self, mock_get):
|
||||||
"""Check that multiple next/previous photos are returned"""
|
"""Check that multiple next/previous photos are returned"""
|
||||||
mock_get.return_value = self._return_value(
|
mock_get.return_value = self._return_value(
|
||||||
|
@ -400,7 +400,7 @@ class TestPhotoNextPrevious(TestPhotos):
|
||||||
self.test_photos_dict[1])
|
self.test_photos_dict[1])
|
||||||
|
|
||||||
class TestPhotoTransform(TestPhotos):
|
class TestPhotoTransform(TestPhotos):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_transform(self, mock_post):
|
def test_photo_transform(self, mock_post):
|
||||||
"""Check that a photo can be transformed"""
|
"""Check that a photo can be transformed"""
|
||||||
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
||||||
|
@ -408,7 +408,7 @@ class TestPhotoTransform(TestPhotos):
|
||||||
mock_post.assert_called_with("/photo/1a/transform.json", rotate="90")
|
mock_post.assert_called_with("/photo/1a/transform.json", rotate="90")
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_transform_id(self, mock_post):
|
def test_photo_transform_id(self, mock_post):
|
||||||
"""Check that a photo can be transformed using its ID"""
|
"""Check that a photo can be transformed using its ID"""
|
||||||
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
mock_post.return_value = self._return_value(self.test_photos_dict[1])
|
||||||
|
@ -416,7 +416,7 @@ class TestPhotoTransform(TestPhotos):
|
||||||
mock_post.assert_called_with("/photo/1a/transform.json", rotate="90")
|
mock_post.assert_called_with("/photo/1a/transform.json", rotate="90")
|
||||||
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
self.assertEqual(result.get_fields(), self.test_photos_dict[1])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_object_transform(self, mock_post):
|
def test_photo_object_transform(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that a photo can be transformed
|
Check that a photo can be transformed
|
||||||
|
|
|
@ -5,7 +5,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
|
|
||||||
class TestTags(unittest.TestCase):
|
class TestTags(unittest.TestCase):
|
||||||
test_host = "test.example.com"
|
test_host = "test.example.com"
|
||||||
|
@ -14,8 +14,8 @@ class TestTags(unittest.TestCase):
|
||||||
{"count": 5, "id":"tag2"}]
|
{"count": 5, "id":"tag2"}]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = openphoto.OpenPhoto(host=self.test_host)
|
self.client = trovebox.Trovebox(host=self.test_host)
|
||||||
self.test_tags = [openphoto.objects.Tag(self.client, tag)
|
self.test_tags = [trovebox.objects.Tag(self.client, tag)
|
||||||
for tag in self.test_tags_dict]
|
for tag in self.test_tags_dict]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -23,7 +23,7 @@ class TestTags(unittest.TestCase):
|
||||||
return {"message": message, "code": code, "result": result}
|
return {"message": message, "code": code, "result": result}
|
||||||
|
|
||||||
class TestTagsList(TestTags):
|
class TestTagsList(TestTags):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'get')
|
@mock.patch.object(trovebox.Trovebox, 'get')
|
||||||
def test_tags_list(self, mock_get):
|
def test_tags_list(self, mock_get):
|
||||||
"""Check that the the tag list is returned correctly"""
|
"""Check that the the tag list is returned correctly"""
|
||||||
mock_get.return_value = self._return_value(self.test_tags_dict)
|
mock_get.return_value = self._return_value(self.test_tags_dict)
|
||||||
|
@ -36,7 +36,7 @@ class TestTagsList(TestTags):
|
||||||
self.assertEqual(result[1].count, 5)
|
self.assertEqual(result[1].count, 5)
|
||||||
|
|
||||||
class TestTagDelete(TestTags):
|
class TestTagDelete(TestTags):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_delete(self, mock_post):
|
def test_tag_delete(self, mock_post):
|
||||||
"""Check that a tag can be deleted"""
|
"""Check that a tag can be deleted"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -44,7 +44,7 @@ class TestTagDelete(TestTags):
|
||||||
mock_post.assert_called_with("/tag/tag1/delete.json")
|
mock_post.assert_called_with("/tag/tag1/delete.json")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_delete_id(self, mock_post):
|
def test_tag_delete_id(self, mock_post):
|
||||||
"""Check that a tag can be deleted using its ID"""
|
"""Check that a tag can be deleted using its ID"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -52,14 +52,14 @@ class TestTagDelete(TestTags):
|
||||||
mock_post.assert_called_with("/tag/tag1/delete.json")
|
mock_post.assert_called_with("/tag/tag1/delete.json")
|
||||||
self.assertEqual(result, True)
|
self.assertEqual(result, True)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_delete_failure(self, mock_post):
|
def test_tag_delete_failure(self, mock_post):
|
||||||
"""Check that an exception is raised if a tag cannot be deleted"""
|
"""Check that an exception is raised if a tag cannot be deleted"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.client.tag.delete(self.test_tags[0])
|
self.client.tag.delete(self.test_tags[0])
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_object_delete(self, mock_post):
|
def test_tag_object_delete(self, mock_post):
|
||||||
"""Check that a tag can be deleted when using the tag object directly"""
|
"""Check that a tag can be deleted when using the tag object directly"""
|
||||||
mock_post.return_value = self._return_value(True)
|
mock_post.return_value = self._return_value(True)
|
||||||
|
@ -70,18 +70,18 @@ class TestTagDelete(TestTags):
|
||||||
self.assertEqual(tag.get_fields(), {})
|
self.assertEqual(tag.get_fields(), {})
|
||||||
self.assertEqual(tag.id, None)
|
self.assertEqual(tag.id, None)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_object_delete_failure(self, mock_post):
|
def test_tag_object_delete_failure(self, mock_post):
|
||||||
"""
|
"""
|
||||||
Check that an exception is raised if a tag cannot be deleted
|
Check that an exception is raised if a tag cannot be deleted
|
||||||
when using the tag object directly
|
when using the tag object directly
|
||||||
"""
|
"""
|
||||||
mock_post.return_value = self._return_value(False)
|
mock_post.return_value = self._return_value(False)
|
||||||
with self.assertRaises(openphoto.OpenPhotoError):
|
with self.assertRaises(trovebox.TroveboxError):
|
||||||
self.test_tags[0].delete()
|
self.test_tags[0].delete()
|
||||||
|
|
||||||
class TestTagUpdate(TestTags):
|
class TestTagUpdate(TestTags):
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_update(self, mock_post):
|
def test_tag_update(self, mock_post):
|
||||||
"""Check that a tag can be updated"""
|
"""Check that a tag can be updated"""
|
||||||
mock_post.return_value = self._return_value(self.test_tags_dict[1])
|
mock_post.return_value = self._return_value(self.test_tags_dict[1])
|
||||||
|
@ -90,7 +90,7 @@ class TestTagUpdate(TestTags):
|
||||||
self.assertEqual(result.id, "tag2")
|
self.assertEqual(result.id, "tag2")
|
||||||
self.assertEqual(result.count, 5)
|
self.assertEqual(result.count, 5)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_update_id(self, mock_post):
|
def test_tag_update_id(self, mock_post):
|
||||||
"""Check that a tag can be updated using its ID"""
|
"""Check that a tag can be updated using its ID"""
|
||||||
mock_post.return_value = self._return_value(self.test_tags_dict[1])
|
mock_post.return_value = self._return_value(self.test_tags_dict[1])
|
||||||
|
@ -99,7 +99,7 @@ class TestTagUpdate(TestTags):
|
||||||
self.assertEqual(result.id, "tag2")
|
self.assertEqual(result.id, "tag2")
|
||||||
self.assertEqual(result.count, 5)
|
self.assertEqual(result.count, 5)
|
||||||
|
|
||||||
@mock.patch.object(openphoto.OpenPhoto, 'post')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_tag_object_update(self, mock_post):
|
def test_tag_object_update(self, mock_post):
|
||||||
"""Check that a tag can be updated when using the tag object directly"""
|
"""Check that a tag can be updated when using the tag object directly"""
|
||||||
mock_post.return_value = self._return_value(self.test_tags_dict[1])
|
mock_post.return_value = self._return_value(self.test_tags_dict[1])
|
||||||
|
|
35
trovebox/__init__.py
Normal file
35
trovebox/__init__.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
from .http import Http
|
||||||
|
from .errors import *
|
||||||
|
from ._version import __version__
|
||||||
|
from . import api_photo
|
||||||
|
from . import api_tag
|
||||||
|
from . import api_album
|
||||||
|
|
||||||
|
LATEST_API_VERSION = 2
|
||||||
|
|
||||||
|
class Trovebox(Http):
|
||||||
|
"""
|
||||||
|
Client library for Trovebox
|
||||||
|
If no parameters are specified, config is loaded from the default
|
||||||
|
location (~/.config/trovebox/default).
|
||||||
|
The config_file parameter is used to specify an alternate config file.
|
||||||
|
If the host parameter is specified, no config file is loaded and
|
||||||
|
OAuth tokens (consumer*, token*) can optionally be specified.
|
||||||
|
All requests will include the api_version path, if specified.
|
||||||
|
This should be used to ensure that your application will continue to work
|
||||||
|
even if the Trovebox API is updated to a new revision.
|
||||||
|
"""
|
||||||
|
def __init__(self, config_file=None, host=None,
|
||||||
|
consumer_key='', consumer_secret='',
|
||||||
|
token='', token_secret='',
|
||||||
|
api_version=None):
|
||||||
|
Http.__init__(self, config_file, host,
|
||||||
|
consumer_key, consumer_secret,
|
||||||
|
token, token_secret, api_version)
|
||||||
|
|
||||||
|
self.photos = api_photo.ApiPhotos(self)
|
||||||
|
self.photo = api_photo.ApiPhoto(self)
|
||||||
|
self.tags = api_tag.ApiTags(self)
|
||||||
|
self.tag = api_tag.ApiTag(self)
|
||||||
|
self.albums = api_album.ApiAlbums(self)
|
||||||
|
self.album = api_album.ApiAlbum(self)
|
|
@ -1,4 +1,4 @@
|
||||||
from openphoto.objects import Album
|
from .objects import Album
|
||||||
|
|
||||||
class ApiAlbums:
|
class ApiAlbums:
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
|
@ -23,7 +23,7 @@ class ApiAlbum:
|
||||||
"""
|
"""
|
||||||
Delete an album.
|
Delete an album.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises an OpenPhotoError if not.
|
Raises an TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
if not isinstance(album, Album):
|
if not isinstance(album, Album):
|
||||||
album = Album(self._client, {"id": album})
|
album = Album(self._client, {"id": album})
|
|
@ -1,8 +1,8 @@
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from openphoto.errors import OpenPhotoError
|
from .errors import TroveboxError
|
||||||
import openphoto.openphoto_http
|
from . import http
|
||||||
from openphoto.objects import Photo
|
from .objects import Photo
|
||||||
|
|
||||||
def extract_ids(photos):
|
def extract_ids(photos):
|
||||||
"""
|
"""
|
||||||
|
@ -24,31 +24,31 @@ class ApiPhotos:
|
||||||
def list(self, **kwds):
|
def list(self, **kwds):
|
||||||
""" Returns a list of Photo objects """
|
""" Returns a list of Photo objects """
|
||||||
photos = self._client.get("/photos/list.json", **kwds)["result"]
|
photos = self._client.get("/photos/list.json", **kwds)["result"]
|
||||||
photos = openphoto.openphoto_http.result_to_list(photos)
|
photos = http.result_to_list(photos)
|
||||||
return [Photo(self._client, photo) for photo in photos]
|
return [Photo(self._client, photo) for photo in photos]
|
||||||
|
|
||||||
def update(self, photos, **kwds):
|
def update(self, photos, **kwds):
|
||||||
"""
|
"""
|
||||||
Updates a list of photos.
|
Updates a list of photos.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises OpenPhotoError if not.
|
Raises TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
ids = extract_ids(photos)
|
ids = extract_ids(photos)
|
||||||
if not self._client.post("/photos/update.json", ids=ids,
|
if not self._client.post("/photos/update.json", ids=ids,
|
||||||
**kwds)["result"]:
|
**kwds)["result"]:
|
||||||
raise OpenPhotoError("Update response returned False")
|
raise TroveboxError("Update response returned False")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def delete(self, photos, **kwds):
|
def delete(self, photos, **kwds):
|
||||||
"""
|
"""
|
||||||
Deletes a list of photos.
|
Deletes a list of photos.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises OpenPhotoError if not.
|
Raises TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
ids = extract_ids(photos)
|
ids = extract_ids(photos)
|
||||||
if not self._client.post("/photos/delete.json", ids=ids,
|
if not self._client.post("/photos/delete.json", ids=ids,
|
||||||
**kwds)["result"]:
|
**kwds)["result"]:
|
||||||
raise OpenPhotoError("Delete response returned False")
|
raise TroveboxError("Delete response returned False")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class ApiPhoto:
|
class ApiPhoto:
|
||||||
|
@ -59,7 +59,7 @@ class ApiPhoto:
|
||||||
"""
|
"""
|
||||||
Delete a photo.
|
Delete a photo.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises an OpenPhotoError if not.
|
Raises an TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
if not isinstance(photo, Photo):
|
if not isinstance(photo, Photo):
|
||||||
photo = Photo(self._client, {"id": photo})
|
photo = Photo(self._client, {"id": photo})
|
|
@ -1,4 +1,4 @@
|
||||||
from openphoto.objects import Tag
|
from .objects import Tag
|
||||||
|
|
||||||
class ApiTags:
|
class ApiTags:
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
|
@ -24,7 +24,7 @@ class ApiTag:
|
||||||
"""
|
"""
|
||||||
Delete a tag.
|
Delete a tag.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises an OpenPhotoError if not.
|
Raises an TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
if not isinstance(tag, Tag):
|
if not isinstance(tag, Tag):
|
||||||
tag = Tag(self._client, {"id": tag})
|
tag = Tag(self._client, {"id": tag})
|
|
@ -41,7 +41,7 @@ def get_config_path(config_file):
|
||||||
config_path = os.path.join(os.getenv('HOME'), ".config")
|
config_path = os.path.join(os.getenv('HOME'), ".config")
|
||||||
if not config_file:
|
if not config_file:
|
||||||
config_file = "default"
|
config_file = "default"
|
||||||
return os.path.join(config_path, "openphoto", config_file)
|
return os.path.join(config_path, "trovebox", config_file)
|
||||||
|
|
||||||
def read_config(config_path):
|
def read_config(config_path):
|
||||||
"""
|
"""
|
|
@ -1,12 +1,12 @@
|
||||||
class OpenPhotoError(Exception):
|
class TroveboxError(Exception):
|
||||||
""" Indicates that an OpenPhoto operation failed """
|
""" Indicates that an Trovebox operation failed """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class OpenPhotoDuplicateError(OpenPhotoError):
|
class TroveboxDuplicateError(TroveboxError):
|
||||||
""" Indicates that an upload operation failed due to a duplicate photo """
|
""" Indicates that an upload operation failed due to a duplicate photo """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class OpenPhoto404Error(Exception):
|
class Trovebox404Error(Exception):
|
||||||
"""
|
"""
|
||||||
Indicates that an Http 404 error code was received
|
Indicates that an Http 404 error code was received
|
||||||
(resource not found)
|
(resource not found)
|
|
@ -8,9 +8,9 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urlparse import urlunparse # Python2
|
from urlparse import urlunparse # Python2
|
||||||
|
|
||||||
from openphoto.objects import OpenPhotoObject
|
from .objects import TroveboxObject
|
||||||
from openphoto.errors import *
|
from .errors import *
|
||||||
from openphoto.config import Config
|
from .config import Config
|
||||||
|
|
||||||
if sys.version < '3':
|
if sys.version < '3':
|
||||||
TEXT_TYPE = unicode
|
TEXT_TYPE = unicode
|
||||||
|
@ -20,24 +20,24 @@ else:
|
||||||
DUPLICATE_RESPONSE = {"code": 409,
|
DUPLICATE_RESPONSE = {"code": 409,
|
||||||
"message": "This photo already exists"}
|
"message": "This photo already exists"}
|
||||||
|
|
||||||
class OpenPhotoHttp:
|
class Http:
|
||||||
"""
|
"""
|
||||||
Base class to handle HTTP requests to an OpenPhoto server.
|
Base class to handle HTTP requests to an Trovebox server.
|
||||||
If no parameters are specified, config is loaded from the default
|
If no parameters are specified, config is loaded from the default
|
||||||
location (~/.config/openphoto/default).
|
location (~/.config/trovebox/default).
|
||||||
The config_file parameter is used to specify an alternate config file.
|
The config_file parameter is used to specify an alternate config file.
|
||||||
If the host parameter is specified, no config file is loaded and
|
If the host parameter is specified, no config file is loaded and
|
||||||
OAuth tokens (consumer*, token*) can optionally be specified.
|
OAuth tokens (consumer*, token*) can optionally be specified.
|
||||||
All requests will include the api_version path, if specified.
|
All requests will include the api_version path, if specified.
|
||||||
This should be used to ensure that your application will continue to work
|
This should be used to ensure that your application will continue to work
|
||||||
even if the OpenPhoto API is updated to a new revision.
|
even if the Trovebox API is updated to a new revision.
|
||||||
"""
|
"""
|
||||||
def __init__(self, config_file=None, host=None,
|
def __init__(self, config_file=None, host=None,
|
||||||
consumer_key='', consumer_secret='',
|
consumer_key='', consumer_secret='',
|
||||||
token='', token_secret='', api_version=None):
|
token='', token_secret='', api_version=None):
|
||||||
self._api_version = api_version
|
self._api_version = api_version
|
||||||
|
|
||||||
self._logger = logging.getLogger("openphoto")
|
self._logger = logging.getLogger("trovebox")
|
||||||
|
|
||||||
self.config = Config(config_file, host,
|
self.config = Config(config_file, host,
|
||||||
consumer_key, consumer_secret,
|
consumer_key, consumer_secret,
|
||||||
|
@ -55,7 +55,7 @@ class OpenPhotoHttp:
|
||||||
Performs an HTTP GET from the specified endpoint (API path),
|
Performs an HTTP GET from the specified endpoint (API path),
|
||||||
passing parameters if given.
|
passing parameters if given.
|
||||||
The api_version is prepended to the endpoint,
|
The api_version is prepended to the endpoint,
|
||||||
if it was specified when the OpenPhoto object was created.
|
if it was specified when the Trovebox object was created.
|
||||||
|
|
||||||
Returns the decoded JSON dictionary, and raises exceptions if an
|
Returns the decoded JSON dictionary, and raises exceptions if an
|
||||||
error code is received.
|
error code is received.
|
||||||
|
@ -98,7 +98,7 @@ class OpenPhotoHttp:
|
||||||
Performs an HTTP POST to the specified endpoint (API path),
|
Performs an HTTP POST to the specified endpoint (API path),
|
||||||
passing parameters if given.
|
passing parameters if given.
|
||||||
The api_version is prepended to the endpoint,
|
The api_version is prepended to the endpoint,
|
||||||
if it was specified when the OpenPhoto object was created.
|
if it was specified when the Trovebox object was created.
|
||||||
|
|
||||||
Returns the decoded JSON dictionary, and raises exceptions if an
|
Returns the decoded JSON dictionary, and raises exceptions if an
|
||||||
error code is received.
|
error code is received.
|
||||||
|
@ -112,7 +112,7 @@ class OpenPhotoHttp:
|
||||||
url = urlunparse(('http', self.host, endpoint, '', '', ''))
|
url = urlunparse(('http', self.host, endpoint, '', '', ''))
|
||||||
|
|
||||||
if not self.config.consumer_key:
|
if not self.config.consumer_key:
|
||||||
raise OpenPhotoError("Cannot issue POST without OAuth tokens")
|
raise TroveboxError("Cannot issue POST without OAuth tokens")
|
||||||
|
|
||||||
auth = requests_oauthlib.OAuth1(self.config.consumer_key,
|
auth = requests_oauthlib.OAuth1(self.config.consumer_key,
|
||||||
self.config.consumer_secret,
|
self.config.consumer_secret,
|
||||||
|
@ -152,7 +152,7 @@ class OpenPhotoHttp:
|
||||||
processed_params = {}
|
processed_params = {}
|
||||||
for key, value in params.items():
|
for key, value in params.items():
|
||||||
# Extract IDs from objects
|
# Extract IDs from objects
|
||||||
if isinstance(value, OpenPhotoObject):
|
if isinstance(value, TroveboxObject):
|
||||||
value = value.id
|
value = value.id
|
||||||
|
|
||||||
# Ensure value is UTF-8 encoded
|
# Ensure value is UTF-8 encoded
|
||||||
|
@ -165,7 +165,7 @@ class OpenPhotoHttp:
|
||||||
new_list = list(value)
|
new_list = list(value)
|
||||||
# Extract IDs from objects in the list
|
# Extract IDs from objects in the list
|
||||||
for i, item in enumerate(new_list):
|
for i, item in enumerate(new_list):
|
||||||
if isinstance(item, OpenPhotoObject):
|
if isinstance(item, TroveboxObject):
|
||||||
new_list[i] = item.id
|
new_list[i] = item.id
|
||||||
# Convert list to string
|
# Convert list to string
|
||||||
value = ','.join([str(item) for item in new_list])
|
value = ','.join([str(item) for item in new_list])
|
||||||
|
@ -184,28 +184,28 @@ class OpenPhotoHttp:
|
||||||
Raises an exception if an invalid response code is received.
|
Raises an exception if an invalid response code is received.
|
||||||
"""
|
"""
|
||||||
if response.status_code == 404:
|
if response.status_code == 404:
|
||||||
raise OpenPhoto404Error("HTTP Error %d: %s" %
|
raise Trovebox404Error("HTTP Error %d: %s" %
|
||||||
(response.status_code, response.reason))
|
(response.status_code, response.reason))
|
||||||
try:
|
try:
|
||||||
json_response = response.json()
|
json_response = response.json()
|
||||||
code = json_response["code"]
|
code = json_response["code"]
|
||||||
message = json_response["message"]
|
message = json_response["message"]
|
||||||
except (ValueError, KeyError):
|
except (ValueError, KeyError):
|
||||||
# Response wasn't OpenPhoto JSON - check the HTTP status code
|
# Response wasn't Trovebox JSON - check the HTTP status code
|
||||||
if 200 <= response.status_code < 300:
|
if 200 <= response.status_code < 300:
|
||||||
# Status code was valid, so just reraise the exception
|
# Status code was valid, so just reraise the exception
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
raise OpenPhotoError("HTTP Error %d: %s" %
|
raise TroveboxError("HTTP Error %d: %s" %
|
||||||
(response.status_code, response.reason))
|
(response.status_code, response.reason))
|
||||||
|
|
||||||
if 200 <= code < 300:
|
if 200 <= code < 300:
|
||||||
return json_response
|
return json_response
|
||||||
elif (code == DUPLICATE_RESPONSE["code"] and
|
elif (code == DUPLICATE_RESPONSE["code"] and
|
||||||
DUPLICATE_RESPONSE["message"] in message):
|
DUPLICATE_RESPONSE["message"] in message):
|
||||||
raise OpenPhotoDuplicateError("Code %d: %s" % (code, message))
|
raise TroveboxDuplicateError("Code %d: %s" % (code, message))
|
||||||
else:
|
else:
|
||||||
raise OpenPhotoError("Code %d: %s" % (code, message))
|
raise TroveboxError("Code %d: %s" % (code, message))
|
||||||
|
|
||||||
def result_to_list(result):
|
def result_to_list(result):
|
||||||
""" Handle the case where the result contains no items """
|
""" Handle the case where the result contains no items """
|
|
@ -4,7 +4,7 @@ import sys
|
||||||
import json
|
import json
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import openphoto
|
import trovebox
|
||||||
|
|
||||||
CONFIG_ERROR = """
|
CONFIG_ERROR = """
|
||||||
You must create a configuration file with the following contents:
|
You must create a configuration file with the following contents:
|
||||||
|
@ -29,7 +29,7 @@ def main(args=sys.argv[1:]):
|
||||||
parser.add_option('-c', '--config', help="Configuration file to use",
|
parser.add_option('-c', '--config', help="Configuration file to use",
|
||||||
action='store', type='string', dest='config_file')
|
action='store', type='string', dest='config_file')
|
||||||
parser.add_option('-h', '-H', '--host',
|
parser.add_option('-h', '-H', '--host',
|
||||||
help=("Hostname of the OpenPhoto server "
|
help=("Hostname of the Trovebox server "
|
||||||
"(overrides config_file)"),
|
"(overrides config_file)"),
|
||||||
action='store', type='string', dest='host')
|
action='store', type='string', dest='host')
|
||||||
parser.add_option('-X', help="Method to use (GET or POST)",
|
parser.add_option('-X', help="Method to use (GET or POST)",
|
||||||
|
@ -56,7 +56,7 @@ def main(args=sys.argv[1:]):
|
||||||
return
|
return
|
||||||
|
|
||||||
if options.version:
|
if options.version:
|
||||||
print(openphoto.__version__)
|
print(trovebox.__version__)
|
||||||
return
|
return
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
|
@ -70,10 +70,10 @@ def main(args=sys.argv[1:]):
|
||||||
|
|
||||||
# Host option overrides config file settings
|
# Host option overrides config file settings
|
||||||
if options.host:
|
if options.host:
|
||||||
client = openphoto.OpenPhoto(host=options.host)
|
client = trovebox.Trovebox(host=options.host)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
client = openphoto.OpenPhoto(config_file=options.config_file)
|
client = trovebox.Trovebox(config_file=options.config_file)
|
||||||
except IOError as error:
|
except IOError as error:
|
||||||
print(error)
|
print(error)
|
||||||
print(CONFIG_ERROR)
|
print(CONFIG_ERROR)
|
||||||
|
@ -108,7 +108,7 @@ def main(args=sys.argv[1:]):
|
||||||
def extract_files(params):
|
def extract_files(params):
|
||||||
"""
|
"""
|
||||||
Extract filenames from the "photo" parameter, so they can be uploaded, returning (updated_params, files).
|
Extract filenames from the "photo" parameter, so they can be uploaded, returning (updated_params, files).
|
||||||
Uses the same technique as openphoto-php:
|
Uses the same technique as the Trovebox PHP commandline tool:
|
||||||
* Filename can only be in the "photo" parameter
|
* Filename can only be in the "photo" parameter
|
||||||
* Filename must be prefixed with "@"
|
* Filename must be prefixed with "@"
|
||||||
* Filename must exist
|
* Filename must exist
|
|
@ -3,14 +3,14 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib import quote # Python2
|
from urllib import quote # Python2
|
||||||
|
|
||||||
from openphoto.errors import OpenPhotoError
|
from .errors import TroveboxError
|
||||||
|
|
||||||
class OpenPhotoObject:
|
class TroveboxObject:
|
||||||
""" Base object supporting the storage of custom fields as attributes """
|
""" Base object supporting the storage of custom fields as attributes """
|
||||||
def __init__(self, openphoto, json_dict):
|
def __init__(self, trovebox, json_dict):
|
||||||
self.id = None
|
self.id = None
|
||||||
self.name = None
|
self.name = None
|
||||||
self._openphoto = openphoto
|
self._trovebox = trovebox
|
||||||
self._json_dict = json_dict
|
self._json_dict = json_dict
|
||||||
self._set_fields(json_dict)
|
self._set_fields(json_dict)
|
||||||
|
|
||||||
|
@ -54,24 +54,24 @@ class OpenPhotoObject:
|
||||||
return self._json_dict
|
return self._json_dict
|
||||||
|
|
||||||
|
|
||||||
class Photo(OpenPhotoObject):
|
class Photo(TroveboxObject):
|
||||||
def delete(self, **kwds):
|
def delete(self, **kwds):
|
||||||
"""
|
"""
|
||||||
Delete this photo.
|
Delete this photo.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises an OpenPhotoError if not.
|
Raises an TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
result = self._openphoto.post("/photo/%s/delete.json" %
|
result = self._trovebox.post("/photo/%s/delete.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
if not result:
|
if not result:
|
||||||
raise OpenPhotoError("Delete response returned False")
|
raise TroveboxError("Delete response returned False")
|
||||||
self._delete_fields()
|
self._delete_fields()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def edit(self, **kwds):
|
def edit(self, **kwds):
|
||||||
""" Returns an HTML form to edit the photo """
|
""" Returns an HTML form to edit the photo """
|
||||||
result = self._openphoto.get("/photo/%s/edit.json" %
|
result = self._trovebox.get("/photo/%s/edit.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
return result["markup"]
|
return result["markup"]
|
||||||
|
|
||||||
def replace(self, photo_file, **kwds):
|
def replace(self, photo_file, **kwds):
|
||||||
|
@ -82,8 +82,8 @@ class Photo(OpenPhotoObject):
|
||||||
|
|
||||||
def update(self, **kwds):
|
def update(self, **kwds):
|
||||||
""" Update this photo with the specified parameters """
|
""" Update this photo with the specified parameters """
|
||||||
new_dict = self._openphoto.post("/photo/%s/update.json" %
|
new_dict = self._trovebox.post("/photo/%s/update.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
self._replace_fields(new_dict)
|
self._replace_fields(new_dict)
|
||||||
|
|
||||||
def view(self, **kwds):
|
def view(self, **kwds):
|
||||||
|
@ -91,8 +91,8 @@ class Photo(OpenPhotoObject):
|
||||||
Used to view the photo at a particular size.
|
Used to view the photo at a particular size.
|
||||||
Updates the photo's fields with the response.
|
Updates the photo's fields with the response.
|
||||||
"""
|
"""
|
||||||
new_dict = self._openphoto.get("/photo/%s/view.json" %
|
new_dict = self._trovebox.get("/photo/%s/view.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
self._replace_fields(new_dict)
|
self._replace_fields(new_dict)
|
||||||
|
|
||||||
def dynamic_url(self, **kwds):
|
def dynamic_url(self, **kwds):
|
||||||
|
@ -103,7 +103,7 @@ class Photo(OpenPhotoObject):
|
||||||
Returns a dict containing the next and previous photo lists
|
Returns a dict containing the next and previous photo lists
|
||||||
(there may be more than one next/previous photo returned).
|
(there may be more than one next/previous photo returned).
|
||||||
"""
|
"""
|
||||||
result = self._openphoto.get("/photo/%s/nextprevious.json" %
|
result = self._trovebox.get("/photo/%s/nextprevious.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
value = {}
|
value = {}
|
||||||
if "next" in result:
|
if "next" in result:
|
||||||
|
@ -113,7 +113,7 @@ class Photo(OpenPhotoObject):
|
||||||
|
|
||||||
value["next"] = []
|
value["next"] = []
|
||||||
for photo in result["next"]:
|
for photo in result["next"]:
|
||||||
value["next"].append(Photo(self._openphoto, photo))
|
value["next"].append(Photo(self._trovebox, photo))
|
||||||
|
|
||||||
if "previous" in result:
|
if "previous" in result:
|
||||||
# Workaround for APIv1
|
# Workaround for APIv1
|
||||||
|
@ -122,7 +122,7 @@ class Photo(OpenPhotoObject):
|
||||||
|
|
||||||
value["previous"] = []
|
value["previous"] = []
|
||||||
for photo in result["previous"]:
|
for photo in result["previous"]:
|
||||||
value["previous"].append(Photo(self._openphoto, photo))
|
value["previous"].append(Photo(self._trovebox, photo))
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -131,65 +131,65 @@ class Photo(OpenPhotoObject):
|
||||||
Performs transformation specified in **kwds
|
Performs transformation specified in **kwds
|
||||||
Example: transform(rotate=90)
|
Example: transform(rotate=90)
|
||||||
"""
|
"""
|
||||||
new_dict = self._openphoto.post("/photo/%s/transform.json" %
|
new_dict = self._trovebox.post("/photo/%s/transform.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
|
|
||||||
# APIv1 doesn't return the transformed photo (frontend issue #955)
|
# APIv1 doesn't return the transformed photo (frontend issue #955)
|
||||||
if isinstance(new_dict, bool):
|
if isinstance(new_dict, bool):
|
||||||
new_dict = self._openphoto.get("/photo/%s/view.json" %
|
new_dict = self._trovebox.get("/photo/%s/view.json" %
|
||||||
self.id)["result"]
|
self.id)["result"]
|
||||||
|
|
||||||
self._replace_fields(new_dict)
|
self._replace_fields(new_dict)
|
||||||
|
|
||||||
class Tag(OpenPhotoObject):
|
class Tag(TroveboxObject):
|
||||||
def delete(self, **kwds):
|
def delete(self, **kwds):
|
||||||
"""
|
"""
|
||||||
Delete this tag.
|
Delete this tag.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises an OpenPhotoError if not.
|
Raises an TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
result = self._openphoto.post("/tag/%s/delete.json" %
|
result = self._trovebox.post("/tag/%s/delete.json" %
|
||||||
quote(self.id), **kwds)["result"]
|
quote(self.id), **kwds)["result"]
|
||||||
if not result:
|
if not result:
|
||||||
raise OpenPhotoError("Delete response returned False")
|
raise TroveboxError("Delete response returned False")
|
||||||
self._delete_fields()
|
self._delete_fields()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update(self, **kwds):
|
def update(self, **kwds):
|
||||||
""" Update this tag with the specified parameters """
|
""" Update this tag with the specified parameters """
|
||||||
new_dict = self._openphoto.post("/tag/%s/update.json" % quote(self.id),
|
new_dict = self._trovebox.post("/tag/%s/update.json" % quote(self.id),
|
||||||
**kwds)["result"]
|
**kwds)["result"]
|
||||||
self._replace_fields(new_dict)
|
self._replace_fields(new_dict)
|
||||||
|
|
||||||
|
|
||||||
class Album(OpenPhotoObject):
|
class Album(TroveboxObject):
|
||||||
def __init__(self, openphoto, json_dict):
|
def __init__(self, trovebox, json_dict):
|
||||||
self.photos = None
|
self.photos = None
|
||||||
self.cover = None
|
self.cover = None
|
||||||
OpenPhotoObject.__init__(self, openphoto, json_dict)
|
TroveboxObject.__init__(self, trovebox, json_dict)
|
||||||
self._update_fields_with_objects()
|
self._update_fields_with_objects()
|
||||||
|
|
||||||
def _update_fields_with_objects(self):
|
def _update_fields_with_objects(self):
|
||||||
""" Convert dict fields into objects, where appropriate """
|
""" Convert dict fields into objects, where appropriate """
|
||||||
# Update the cover with a photo object
|
# Update the cover with a photo object
|
||||||
if isinstance(self.cover, dict):
|
if isinstance(self.cover, dict):
|
||||||
self.cover = Photo(self._openphoto, self.cover)
|
self.cover = Photo(self._trovebox, self.cover)
|
||||||
# Update the photo list with photo objects
|
# Update the photo list with photo objects
|
||||||
if isinstance(self.photos, list):
|
if isinstance(self.photos, list):
|
||||||
for i, photo in enumerate(self.photos):
|
for i, photo in enumerate(self.photos):
|
||||||
if isinstance(photo, dict):
|
if isinstance(photo, dict):
|
||||||
self.photos[i] = Photo(self._openphoto, photo)
|
self.photos[i] = Photo(self._trovebox, photo)
|
||||||
|
|
||||||
def delete(self, **kwds):
|
def delete(self, **kwds):
|
||||||
"""
|
"""
|
||||||
Delete this album.
|
Delete this album.
|
||||||
Returns True if successful.
|
Returns True if successful.
|
||||||
Raises an OpenPhotoError if not.
|
Raises an TroveboxError if not.
|
||||||
"""
|
"""
|
||||||
result = self._openphoto.post("/album/%s/delete.json" %
|
result = self._trovebox.post("/album/%s/delete.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
if not result:
|
if not result:
|
||||||
raise OpenPhotoError("Delete response returned False")
|
raise TroveboxError("Delete response returned False")
|
||||||
self._delete_fields()
|
self._delete_fields()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -204,12 +204,12 @@ class Album(OpenPhotoObject):
|
||||||
|
|
||||||
def update(self, **kwds):
|
def update(self, **kwds):
|
||||||
""" Update this album with the specified parameters """
|
""" Update this album with the specified parameters """
|
||||||
new_dict = self._openphoto.post("/album/%s/update.json" %
|
new_dict = self._trovebox.post("/album/%s/update.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
|
|
||||||
# APIv1 doesn't return the updated album (frontend issue #937)
|
# APIv1 doesn't return the updated album (frontend issue #937)
|
||||||
if isinstance(new_dict, bool):
|
if isinstance(new_dict, bool):
|
||||||
new_dict = self._openphoto.get("/album/%s/view.json" %
|
new_dict = self._trovebox.get("/album/%s/view.json" %
|
||||||
self.id)["result"]
|
self.id)["result"]
|
||||||
|
|
||||||
self._replace_fields(new_dict)
|
self._replace_fields(new_dict)
|
||||||
|
@ -220,7 +220,7 @@ class Album(OpenPhotoObject):
|
||||||
Requests the full contents of the album.
|
Requests the full contents of the album.
|
||||||
Updates the album's fields with the response.
|
Updates the album's fields with the response.
|
||||||
"""
|
"""
|
||||||
result = self._openphoto.get("/album/%s/view.json" %
|
result = self._trovebox.get("/album/%s/view.json" %
|
||||||
self.id, **kwds)["result"]
|
self.id, **kwds)["result"]
|
||||||
self._replace_fields(result)
|
self._replace_fields(result)
|
||||||
self._update_fields_with_objects()
|
self._update_fields_with_objects()
|
Loading…
Add table
Add a link
Reference in a new issue