示例#1
0
    def test_taskdb_PUT_undo(self):
        self._create_user_and_login()
        data = open(os.path.join(TASK_DATA, 'undo.data'), 'r').read()
        expected_parsed = parse_undo(data)

        post_response = self.client.put('/taskdb/undo.data',
                        content_type='text/plain',
                        data=data)
        self.assertEqual(post_response.status_code, 200)

        get_response = self.client.get('/taskdb/undo.data')

        actual_parsed = parse_undo(get_response.content)
        self.assertEqual(expected_parsed, actual_parsed)
示例#2
0
    def test_taskdb_PUT_undo(self):
        self._create_user_and_login()
        data = open(os.path.join(TASK_DATA, 'undo.data'), 'r').read()
        expected_parsed = parse_undo(data)

        post_response = self.client.put('/taskdb/undo.data',
                                        content_type='text/plain',
                                        data=data)
        self.assertEqual(post_response.status_code, 200)

        get_response = self.client.get('/taskdb/undo.data')

        actual_parsed = parse_undo(get_response.content)
        self.assertEqual(expected_parsed, actual_parsed)
示例#3
0
def post_taskdb(request, filename):
    if filename not in TASK_FNAMES:
        return HttpResponseForbidden('Forbidden!')

    user = request.user
    data = request.raw_post_data

    if filename in ['pending.data', 'completed.data']:
        parsed = [decode_task(line) for line in data.splitlines()]
        if filename == 'pending.data':
            tasks = Task.objects.filter(status='pending', user=user)
        elif filename == 'completed.data':
            tasks = Task.objects.filter(status__in=['completed', 'deleted'])

        tasks.delete()

        for task in parsed:
            task.update({'user': user})
            Task.fromdict(task)

    elif filename == 'undo.data':
        Undo.objects.all().delete()
        parsed = parse_undo(data)
        for undo_dict in parsed:
            undo_dict.update({'user': user})
            Undo.fromdict(undo_dict)
    else:
        return HttpResponseNotFound()

    return HttpResponse()
示例#4
0
 def test_parse_undo(self):
     parsed = parse_undo(UNDO_SAMPLE)
     self.assertEqual(parsed, PARSED_UNDO_SAMPLE)
示例#5
0
 def test_parse_undo(self):
     parsed = parse_undo(UNDO_SAMPLE)
     self.assertEqual(parsed, PARSED_UNDO_SAMPLE)