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_task_fromdict_dependencies_dont_exist_yet(self): user = self.create_user() task1_info = {'description': 'foobar', 'uuid': '1234abc', 'entry': '1234', 'project': 'test', 'user': user, 'status': 'pending', } task2_info = {'description': 'baz', 'uuid': 'aaaaaa', 'entry': '1237', 'depends': '1234abc', 'user': user, 'status': 'pending', 'annotation_123456': 'some note' } task2 = Task.fromdict(task2_info) task1 = Task.fromdict(task1_info) task2_info.pop('user') task1_info.pop('user') self.assertEqual(task1.todict(), task1_info) self.assertEqual(task2.todict(), task2_info)
def test_task_fromdict_dependencies_dont_exist_yet(self): user = self.create_user() task1_info = { 'description': 'foobar', 'uuid': '1234abc', 'entry': '1234', 'project': 'test', 'user': user, 'status': 'pending', } task2_info = { 'description': 'baz', 'uuid': 'aaaaaa', 'entry': '1237', 'depends': '1234abc', 'user': user, 'status': 'pending', 'annotation_123456': 'some note' } task2 = Task.fromdict(task2_info) task1 = Task.fromdict(task1_info) task2_info.pop('user') task1_info.pop('user') self.assertEqual(task1.todict(), task1_info) self.assertEqual(task2.todict(), task2_info)
def test_task_fromdict_dependencies(self): user = self.create_user() task1 = Task(user=user, description='test') task1.save(track=False) task2 = Task(user=user, description='test2') task2.save(track=False) data = {'description': 'foobar', 'uuid': 'sssssssss', 'status': 'pending', 'entry': '12345', 'user': user, 'annotation_1324076995': u'this is an annotation', 'depends': u','.join([t.uuid for t in (task1, task2)]), 'priority': '', } task = Task.fromdict(data) # ensure the data is in the db, not just the task # object from above task = Task.objects.get(description='foobar') self.assertEqual(list(Undo.objects.all()), []) data.pop('user') data.pop('priority') self.assertEqual(data, task.todict())
def test_task_fromdict_track(self): user = self.create_user() data = {'description': 'foobar', 'uuid': 'sssssssss', 'status': 'pending', 'entry': '12345', 'user': user, 'annotation_1324076995': u'this is an annotation', 'priority': 'H', } task = Task.fromdict(data, track=True) # ensure the data is in the db, not just the task # object from above task = Task.objects.all()[0] # see reasoning in the add_tasks_POST test self.assertEqual(Undo.objects.count(), 2) # this is a brand new task, the firts undo shouldn't # have an 'old' field. self.assertEqual(Undo.objects.all()[0].old, None) data.pop('user') self.assertEqual(data, task.todict()) undo2 = Undo.objects.all()[1] self.assertNotEqual(undo2.old, undo2.new)
def test_task_fromdict_dependencies(self): user = self.create_user() task1 = Task(user=user, description='test') task1.save(track=False) task2 = Task(user=user, description='test2') task2.save(track=False) data = { 'description': 'foobar', 'uuid': 'sssssssss', 'status': 'pending', 'entry': '12345', 'user': user, 'annotation_1324076995': u'this is an annotation', 'depends': u','.join([t.uuid for t in (task1, task2)]), 'priority': '', } task = Task.fromdict(data) # ensure the data is in the db, not just the task # object from above task = Task.objects.get(description='foobar') self.assertEqual(list(Undo.objects.all()), []) data.pop('user') data.pop('priority') self.assertEqual(data, task.todict())
def test_task_fromdict_track(self): user = self.create_user() data = { 'description': 'foobar', 'uuid': 'sssssssss', 'status': 'pending', 'entry': '12345', 'user': user, 'annotation_1324076995': u'this is an annotation', 'priority': 'H', } task = Task.fromdict(data, track=True) # ensure the data is in the db, not just the task # object from above task = Task.objects.all()[0] # see reasoning in the add_tasks_POST test self.assertEqual(Undo.objects.count(), 2) # this is a brand new task, the firts undo shouldn't # have an 'old' field. self.assertEqual(Undo.objects.all()[0].old, None) data.pop('user') self.assertEqual(data, task.todict()) undo2 = Undo.objects.all()[1] self.assertNotEqual(undo2.old, undo2.new)
def test_task_fromdict_optional_end(self): user = self.create_user() data = {'description': 'foobar', 'uuid': 'sssssssss', 'status': 'completed', 'entry': '12345', 'end': '45678', 'user': user, 'annotation_1324076995': 'this is an annotation', } task = Task.fromdict(data) self.assertEqual(list(Undo.objects.all()), []) data.pop('user') self.assertEqual(data, task.todict())
def test_task_fromdict_optional_end(self): user = self.create_user() data = { 'description': 'foobar', 'uuid': 'sssssssss', 'status': 'completed', 'entry': '12345', 'end': '45678', 'user': user, 'annotation_1324076995': 'this is an annotation', } task = Task.fromdict(data) self.assertEqual(list(Undo.objects.all()), []) data.pop('user') self.assertEqual(data, task.todict())
def test_task_fromdict(self): user = self.create_user() data = {'description': 'foobar', 'uuid': 'sssssssss', 'status': 'pending', 'entry': '12345', 'user': user, 'annotation_1324076995': u'this is an annotation', 'priority': 'H', } task = Task.fromdict(data) # ensure the data is in the db, not just the task # object from above task = Task.objects.all()[0] self.assertEqual(list(Undo.objects.all()), []) data.pop('user') self.assertEqual(data, task.todict())
def test_task_fromdict(self): user = self.create_user() data = { 'description': 'foobar', 'uuid': 'sssssssss', 'status': 'pending', 'entry': '12345', 'user': user, 'annotation_1324076995': u'this is an annotation', 'priority': 'H', } task = Task.fromdict(data) # ensure the data is in the db, not just the task # object from above task = Task.objects.all()[0] self.assertEqual(list(Undo.objects.all()), []) data.pop('user') self.assertEqual(data, task.todict())