Esempio n. 1
0
 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)
Esempio n. 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')
Esempio n. 3
0
 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
     })
Esempio n. 4
0
 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})