Skip to content

Commit

Permalink
Added test for updating time-series using form.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdutton committed Jan 8, 2012
1 parent d739757 commit 18a6489
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions openorg_timeseries/tests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ def testJSONChangeUnprivileged(self):

self.assertEqual(response.status_code, httplib.FORBIDDEN)

def testFormChange(self):
form_data = {'title': 'new title',
'notes': 'new notes'}
response = self.client.post(self.location,
data=form_data,
REMOTE_USER='withaddperm')
self.assertEqual(response.status_code, httplib.OK, response._get_content())

# Check that the series has actually been updated
series = TimeSeries.objects.get(slug=self.real_timeseries['slug'])
self.assertEqual(series.title, form_data['title'])
self.assertEqual(series.notes, form_data['notes'])

def testEmptyRequest(self):
response = self.client.post(self.location,
data=json.dumps({}),
Expand Down
10 changes: 9 additions & 1 deletion openorg_timeseries/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get(self, request, slug):

def post(self, request, slug):
context = self.common(request, slug)
series = context['series']
series, form = context['series'], context['form']

if request.META.get('CONTENT_TYPE') == 'application/json':
try:
Expand Down Expand Up @@ -242,6 +242,14 @@ def post(self, request, slug):
context['updated'].append(f)
series.save()

if form.is_valid():
if not self.has_perm('change', series):
return self.lacking_privilege("modify this time-series")
form.save()

if self.get_renderers(request)[0].format == 'html':
return HttpResponseSeeOther(context['series'].get_absolute_url())

return self.render(request, context, 'timeseries-admin/detail-post')


Expand Down

0 comments on commit 18a6489

Please sign in to comment.