Fix action/create endpoint.

This commit is contained in:
sneakypete81 2013-09-02 21:19:34 +01:00
parent 17e73f9666
commit 6293a81d39
4 changed files with 65 additions and 45 deletions

View file

@ -3,15 +3,21 @@ try:
except ImportError: except ImportError:
import unittest import unittest
import trovebox
from tests.functional import test_base from tests.functional import test_base
class TestActions(test_base.TestBase): class TestActions(test_base.TestBase):
testcase_name = "action API" testcase_name = "action API"
# TODO: Enable this test (and write more) once the Actions API is working. def test_create_view_delete(self):
# Currently always returns: """ Create an action on a photo, view it, then delete it """
# "Could not find route /action/create.json from /action/create.json" # Create and check that the action exists
@unittest.expectedFailure action = self.client.action.create(target=self.photos[0], type="comment", name="test")
def test_create_delete(self): action_id = action.id
""" Create an action on a photo, then delete it """ self.assertEqual(self.client.action.view(action_id).name, "test")
action = self.client.action.create(target=self.photos[0])
# Delete and check that the action is gone
action.delete()
with self.assertRaises(trovebox.TroveboxError):
self.client.action.view(action_id)

View file

@ -14,10 +14,12 @@ class TestActions(unittest.TestCase):
test_actions_dict = [{"id": "1", test_actions_dict = [{"id": "1",
"target": test_photos_dict[0], "target": test_photos_dict[0],
"target_type": "photo", "target_type": "photo",
"type": "comment",
"totalRows": 2}, "totalRows": 2},
{"id": "2", {"id": "2",
"target": test_photos_dict[1], "target": test_photos_dict[1],
"target_type": "photo", "target_type": "photo",
"type": "comment",
"totalRows": 2}] "totalRows": 2}]
def setUp(self): def setUp(self):
@ -36,26 +38,31 @@ class TestActionCreate(TestActions):
def test_action_create(self, mock_post): def test_action_create(self, mock_post):
"""Check that an action can be created on a photo object""" """Check that an action can be created on a photo object"""
mock_post.return_value = self._return_value(self.test_actions_dict[0]) mock_post.return_value = self._return_value(self.test_actions_dict[0])
result = self.client.action.create(target=self.test_photos[0], foo="bar") result = self.client.action.create(target=self.test_photos[0], type="comment", foo="bar")
mock_post.assert_called_with("/action/create.json", target=self.test_photos[0].id, mock_post.assert_called_with("/action/%s/photo/create.json" %
target_type="photo", self.test_photos[0].id,
type="comment",
foo="bar") foo="bar")
self.assertEqual(result.id, "1") self.assertEqual(result.id, "1")
self.assertEqual(result.target.id, "photo1") self.assertEqual(result.target.id, "photo1")
self.assertEqual(result.target_type, "photo") self.assertEqual(result.target_type, "photo")
self.assertEqual(result.type, "comment")
@mock.patch.object(trovebox.Trovebox, 'post') @mock.patch.object(trovebox.Trovebox, 'post')
def test_action_create_id(self, mock_post): def test_action_create_id(self, mock_post):
"""Check that an action can be created using a photo id""" """Check that an action can be created using a photo id"""
mock_post.return_value = self._return_value(self.test_actions_dict[0]) mock_post.return_value = self._return_value(self.test_actions_dict[0])
result = self.client.action.create(target=self.test_photos[0].id, result = self.client.action.create(target=self.test_photos[0].id,
target_type="photo", foo="bar") target_type="photo", type="comment",
mock_post.assert_called_with("/action/create.json", target=self.test_photos[0].id, foo="bar")
target_type="photo", mock_post.assert_called_with("/action/%s/photo/create.json" %
self.test_photos[0].id,
type="comment",
foo="bar") foo="bar")
self.assertEqual(result.id, "1") self.assertEqual(result.id, "1")
self.assertEqual(result.target.id, "photo1") self.assertEqual(result.target.id, "photo1")
self.assertEqual(result.target_type, "photo") self.assertEqual(result.target_type, "photo")
self.assertEqual(result.type, "comment")
@mock.patch.object(trovebox.Trovebox, 'post') @mock.patch.object(trovebox.Trovebox, 'post')
def test_action_create_invalid_type(self, mock_post): def test_action_create_invalid_type(self, mock_post):

View file

@ -1,6 +1,6 @@
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_activity.py patched/api/api_activity.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_activity.py patched/api/api_activity.py
--- original/api/api_activity.py 2013-08-19 17:59:15.592149000 +0100 --- original/api/api_activity.py 2013-09-02 21:17:41.848947000 +0100
+++ patched/api/api_activity.py 2013-08-19 18:08:39.950947589 +0100 +++ patched/api/api_activity.py 2013-09-02 21:18:19.701134833 +0100
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
raise TroveboxError("Purge response returned False") raise TroveboxError("Purge response returned False")
return True return True
@ -11,11 +11,11 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_ac
def __init__(self, client): def __init__(self, client):
self._client = client self._client = client
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_album.py patched/api/api_album.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_album.py patched/api/api_album.py
--- original/api/api_album.py 2013-08-19 16:09:53.539609000 +0100 --- original/api/api_album.py 2013-09-02 21:17:41.848947000 +0100
+++ patched/api/api_album.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/api/api_album.py 2013-09-02 21:18:19.701134833 +0100
@@ -3,7 +3,7 @@ @@ -4,7 +4,7 @@
"""
from trovebox.objects.album import Album from trovebox.objects.album import Album
from trovebox import http
-class ApiAlbums(object): -class ApiAlbums(object):
+class ApiAlbums(object): # pylint: disable=R0903 +class ApiAlbums(object): # pylint: disable=R0903
@ -23,10 +23,10 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_al
def __init__(self, client): def __init__(self, client):
self._client = client self._client = client
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_tag.py patched/api/api_tag.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_tag.py patched/api/api_tag.py
--- original/api/api_tag.py 2013-08-19 16:09:53.539609000 +0100 --- original/api/api_tag.py 2013-09-02 21:17:41.848947000 +0100
+++ patched/api/api_tag.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/api/api_tag.py 2013-09-02 21:18:19.705134853 +0100
@@ -3,7 +3,7 @@ @@ -4,7 +4,7 @@
""" from trovebox import http
from trovebox.objects.tag import Tag from trovebox.objects.tag import Tag
-class ApiTags(object): -class ApiTags(object):
@ -35,8 +35,8 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/api/api_ta
def __init__(self, client): def __init__(self, client):
self._client = client self._client = client
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/auth.py patched/auth.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/auth.py patched/auth.py
--- original/auth.py 2013-08-19 16:09:53.543609000 +0100 --- original/auth.py 2013-09-02 21:17:41.848947000 +0100
+++ patched/auth.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/auth.py 2013-09-02 21:18:19.705134853 +0100
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import os import os
@ -47,7 +47,7 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/auth.py pa
from ConfigParser import SafeConfigParser as ConfigParser # Python2 from ConfigParser import SafeConfigParser as ConfigParser # Python2
try: try:
@@ -12,9 +12,9 @@ @@ -12,9 +12,9 @@
except ImportError: except ImportError: # pragma: no cover
import StringIO as io # Python2 import StringIO as io # Python2
-class Auth(object): -class Auth(object):
@ -68,8 +68,8 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/auth.py pa
parser.readfp(buf) # Python2 parser.readfp(buf) # Python2
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/http.py patched/http.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/http.py patched/http.py
--- original/http.py 2013-08-19 16:09:53.543609000 +0100 --- original/http.py 2013-09-02 21:17:41.848947000 +0100
+++ patched/http.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/http.py 2013-09-02 21:18:25.749164824 +0100
@@ -7,18 +7,18 @@ @@ -7,18 +7,18 @@
import requests_oauthlib import requests_oauthlib
import logging import logging
@ -87,7 +87,7 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/http.py pa
if sys.version < '3': if sys.version < '3':
- TEXT_TYPE = unicode - TEXT_TYPE = unicode
+ TEXT_TYPE = unicode # pylint: disable=C0103 + TEXT_TYPE = unicode # pylint: disable=C0103
else: else: # pragma: no cover
- TEXT_TYPE = str - TEXT_TYPE = str
+ TEXT_TYPE = str # pylint: disable=C0103 + TEXT_TYPE = str # pylint: disable=C0103
@ -103,8 +103,8 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/http.py pa
token='', token_secret='', api_version=None): token='', token_secret='', api_version=None):
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/__init__.py patched/__init__.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/__init__.py patched/__init__.py
--- original/__init__.py 2013-08-19 17:02:22.951226000 +0100 --- original/__init__.py 2013-09-02 21:17:41.848947000 +0100
+++ patched/__init__.py 2013-08-19 18:08:36.194928993 +0100 +++ patched/__init__.py 2013-09-02 21:18:19.705134853 +0100
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
__init__.py : Trovebox package top level __init__.py : Trovebox package top level
""" """
@ -133,8 +133,8 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/__init__.p
token='', token_secret='', token='', token_secret='',
api_version=None): api_version=None):
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/main.py patched/main.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/main.py patched/main.py
--- original/main.py 2013-08-19 16:09:53.543609000 +0100 --- original/main.py 2013-09-02 21:17:41.852947000 +0100
+++ patched/main.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/main.py 2013-09-02 21:18:19.705134853 +0100
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
################################################################# #################################################################
@ -161,9 +161,18 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/main.py pa
files[f].close() files[f].close()
if options.verbose: if options.verbose:
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/objects/photo.py patched/objects/photo.py
--- original/objects/photo.py 2013-09-02 19:48:44.862482000 +0100
+++ patched/objects/photo.py 2013-09-02 21:18:29.001180950 +0100
@@ -1,4 +1,4 @@
-"""
+""" # pylint: disable=R0801
Representation of a Photo object
"""
from trovebox.errors import TroveboxError
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/objects/tag.py patched/objects/tag.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/objects/tag.py patched/objects/tag.py
--- original/objects/tag.py 2013-08-19 16:09:53.543609000 +0100 --- original/objects/tag.py 2013-09-02 21:17:41.852947000 +0100
+++ patched/objects/tag.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/objects/tag.py 2013-09-02 21:18:19.705134853 +0100
@@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
-""" -"""
+""" # pylint: disable=R0801 +""" # pylint: disable=R0801
@ -176,8 +185,8 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/objects/ta
from urllib import quote # Python2 from urllib import quote # Python2
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/objects/trovebox_object.py patched/objects/trovebox_object.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/objects/trovebox_object.py patched/objects/trovebox_object.py
--- original/objects/trovebox_object.py 2013-08-19 16:09:53.543609000 +0100 --- original/objects/trovebox_object.py 2013-09-02 21:17:41.852947000 +0100
+++ patched/objects/trovebox_object.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/objects/trovebox_object.py 2013-09-02 21:18:19.705134853 +0100
@@ -1,10 +1,10 @@ @@ -1,10 +1,10 @@
""" """
Base object supporting the storage of custom fields as attributes Base object supporting the storage of custom fields as attributes
@ -192,8 +201,8 @@ diff --unified --recursive '--exclude=.pylint-ignores.patch' original/objects/tr
self._trovebox = trovebox self._trovebox = trovebox
self._json_dict = json_dict self._json_dict = json_dict
diff --unified --recursive '--exclude=.pylint-ignores.patch' original/_version.py patched/_version.py diff --unified --recursive '--exclude=.pylint-ignores.patch' original/_version.py patched/_version.py
--- original/_version.py 2013-08-19 16:09:53.543609000 +0100 --- original/_version.py 2013-09-02 21:17:41.852947000 +0100
+++ patched/_version.py 2013-08-19 18:08:20.118849270 +0100 +++ patched/_version.py 2013-09-02 21:18:19.705134853 +0100
@@ -1,2 +1,2 @@ @@ -1,2 +1,2 @@
- -
+ # pylint: disable=C0111 + # pylint: disable=C0111

View file

@ -20,9 +20,7 @@ class ApiAction(object):
if isinstance(target, Photo): if isinstance(target, Photo):
target_type = "photo" target_type = "photo"
else: else:
raise NotImplementedError("Actions can only be assigned to " raise NotImplementedError("Unsupported target type")
"Photos when target_type isn't "
"specified")
# Extract the ID from the target # Extract the ID from the target
try: try:
target_id = target.id target_id = target.id
@ -30,8 +28,8 @@ class ApiAction(object):
# Assume the ID was passed in directly # Assume the ID was passed in directly
target_id = target target_id = target
result = self._client.post("/action/create.json", result = self._client.post("/action/%s/%s/create.json" %
target=target_id, target_type=target_type, (target_id, target_type),
**kwds)["result"] **kwds)["result"]
return Action(self._client, result) return Action(self._client, result)