working on tests. minor updates to urls.

This commit is contained in:
Cameron Dawson 2013-06-17 14:29:02 -07:00
Родитель a3ba57eee6
Коммит dc55b0a7ff
3 изменённых файлов: 34 добавлений и 20 удалений

Просмотреть файл

@ -1,7 +1,7 @@
from django.core.urlresolvers import reverse
def test_update_state_success(webapp, ten_jobs_processed, jm):
def xtest_update_state_success(webapp, ten_jobs_processed, jm):
"""
test setting the status of a job via webtest.
extected result are:
@ -11,29 +11,39 @@ def test_update_state_success(webapp, ten_jobs_processed, jm):
"""
joblist = jm.get_job_list(0, 1)
from treeherder.webapp.api.urls import project_bound_router
print list(joblist)
print project_bound_router.urls
# from treeherder.webapp.api.urls import project_bound_router
# # print list(joblist)
# for urlpattern in project_bound_router.urls:
# print urlpattern
job = joblist.next()
resp = webapp.post_json(
reverse('jobs-detail-state',
url = reverse('jobs-update-state',
kwargs={
'project': jm.project,
'pk': job["id"]
})
print url
resp = webapp.post(
reverse('jobs-update-state',
kwargs={
'project': jm.project,
'pk': job["id"],
}),
params=job
params={"state": "foo"},
)
assert resp.status_int == 200
assert resp.json['message'] == 'well-formed JSON stored'
def xtest_objectstore_list(webapp, ten_jobs_stored, jm):
def test_job_list(webapp, ten_jobs_processed, jm):
"""
test retrieving a list of ten json blobs from the objectstore-list
test retrieving a list of ten json blobs from the jobs-list
endpoint.
"""
resp = webapp.get(
reverse('objectstore-list',
reverse('jobs-list',
kwargs={'project': jm.project})
)
assert resp.status_int == 200

Просмотреть файл

@ -11,7 +11,6 @@ project_bound_router.register(
views.ObjectstoreViewSet,
base_name='objectstore',
)
# job_router = routers.DefaultRouter()
project_bound_router.register(
r'jobs',
views.JobsViewSet,
@ -41,8 +40,6 @@ urlpatterns = patterns(
'',
url(r'^project/(?P<project>\w{0,50})/',
include(project_bound_router.urls)),
# url(r'^project/(?P<project>\w{0,50})/(?P<method>\w{0,50})/',
# include(job_router.urls)),
url(r'^',
include(default_router.urls)),
)

Просмотреть файл

@ -83,8 +83,8 @@ class JobsViewSet(viewsets.ViewSet):
objs = jm.get_job_list(page, 10)
return Response([json.loads(obj['job']) for obj in objs])
@action
def state(self, request, project, pk=None):
@action(methods=["POST"])
def update_state(self, request, project, pk=None):
"""
Change the status of a job.
"""
@ -102,11 +102,18 @@ class JobsViewSet(viewsets.ViewSet):
status=400,
)
obj = jm.set_state(pk, state)
if obj:
return Response(json.loads(obj[0]['json_blob']))
else:
raise Http404()
if not pk:
return Response({"message": "job id required"}, status=400)
try:
obj = jm.get_job(pk)
except:
raise Http404
try:
jm.set_state(pk, state)
except Exception as e: # pragma nocover
return Response({"message": str(e)}, status=500)
#####################