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)
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()
def test_parse_undo(self): parsed = parse_undo(UNDO_SAMPLE) self.assertEqual(parsed, PARSED_UNDO_SAMPLE)