Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Added id and resource_uri to state URL
Browse files Browse the repository at this point in the history
  • Loading branch information
antisvin committed Dec 5, 2014
1 parent 24ec55f commit ed9fbf7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

README = open(os.path.join(os.path.dirname(__file__), 'README.md')).read()

# allow setup.py to be run from any path
#os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
name='tastypie-async',
version='0.1',
Expand Down Expand Up @@ -47,5 +44,4 @@
],
dependency_links=[
]
)

)
4 changes: 3 additions & 1 deletion tpasync/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def async_state(self, request, task_id, **kwargs):
"""
task = AsyncResult(task_id)
if request.method == 'GET':
data = {'state': task.state}
data = {
'state': task.state, 'id': task.id,
'resource_uri': request.get_full_path()}
if task.ready():
data['result_uri'] = self._build_reverse_url(
'api_async_result',
Expand Down
6 changes: 6 additions & 0 deletions tpasync/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def test_successful_task(self):
self.assertHttpOK(response)
data = self.deserialize(response)
self.assertEqual(data['state'], 'PENDING')
self.assertIn('resource_uri', data)
self.assertIn('id', data)
task_id = data['id']
self.assertEqual(
data['resource_uri'],
'/api/v1/test/state/{}/'.format(task_id))
self.assertNotIn('result_uri', data)
# Wait 4 seconds and retry. This time result_uri should be ready
time.sleep(4)
Expand Down

0 comments on commit ed9fbf7

Please sign in to comment.