예제 #1
0
파일: tests.py 프로젝트: eguven/exp_todo
 def test_post_get(self):
     saved = []
     for pk in xrange(1, 6):
         item = TodoItem(title='Title %d' % pk, order=pk, done=False)
         self.client.post(
             reverse('todo_api:handle_rest_call'),
             data=json.dumps(item.to_json()),
             content_type='application/json')
         item.pk = pk
         saved.append(item)
     expected = json.dumps([item.to_json() for item in saved])
     response = self.client.get(reverse('todo_api:handle_rest_call'))
     self.assertEqual(expected, response.content)
예제 #2
0
def createTodoItem(request, list_id):
    user_id = request.session.get('user_id')
    title = request.POST.get('title')
        
    try:
        if title is None:
            return HttpResponseBadRequest()

        # Make sure the user is authorized to make modifications to this list
        todo_list = TodoList.objects.get(pk=list_id)
        if not todo_list.collaborators.filter(pk=user_id).exists():
            return HttpResponseForbidden()

        todo = TodoItem(title=title, todo_list=todo_list)
        todo.full_clean()
        todo.save()

        # If the request was accepted and successfully processed, broadcast a 
        # 'item-added' message on the pusher channel for this list
        channel_name = 'presence-todoList' + list_id
        p[channel_name].trigger('item-added', todo.to_json())

    except TodoList.DoesNotExist:
        return HttpResponseNotFound()    

    except ValidationError as e:
        return HttpResponseBadRequest(content=e.message)

    return HttpResponse(content=todo_list.to_json(), content_type='application/json')
예제 #3
0
파일: tests.py 프로젝트: mmww/exp_todo
 def test_json(self):
     """Checking json serialization"""
     item = TodoItem(title='the title', order=2, done=False)
     result = item.to_json()
     self.assertEqual(result, {
         'title': 'the title',
         'order': 2,
         'done': False
     })
예제 #4
0
파일: tests.py 프로젝트: eguven/exp_todo
 def test_json(self):
     """Checking json serialization"""
     item = TodoItem(
         title='the title',
         order=2,
         done=False)
     result = item.to_json()
     self.assertEqual(
         result,
         {'title': 'the title',
          'order': 2,
          'done': False})
     item.save()
     result = item.to_json()
     self.assertEqual(
         result,
         {'pk':1,
          'title': 'the title',
          'order': 2,
          'done': False})