Skip to content

Commit

Permalink
Merge pull request #39 from unlimitedlabs/worker-info
Browse files Browse the repository at this point in the history
Add worker info to task assignment API call
  • Loading branch information
jrbotros committed Oct 7, 2015
2 parents abca140 + d29c43a commit 7051fe9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 49 deletions.
2 changes: 2 additions & 0 deletions orchestra/tests/helpers/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def setup_models(test_case):
for user_id, certifications in workers.items():
# Create user, worker, client
user = (UserFactory(username='test_user_{}'.format(user_id),
first_name='test_first_{}'.format(user_id),
last_name='test_last_{}'.format(user_id),
password='test_{}'.format(user_id),
email='test_user_{}@test.com'.format(user_id)))
test_case.workers[user_id] = WorkerFactory(user=user)
Expand Down
67 changes: 37 additions & 30 deletions orchestra/tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_entry_level_task_assignment(self):
self.clients[0], {'task_id': task_id},
task.project.short_description,
'Processing', 'Processing', False,
False, {})
False, {}, self.workers[0])

# no more tasks for user 0 left
response = (self.clients[0].get(
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_reviewer_task_assignment(self):
self.clients[1], {'task_id': returned['id']},
Task.objects.get(id=returned['id']).project.short_description,
'Processing', 'Reviewing', True,
False, {'test_key': 'test_value'})
False, {'test_key': 'test_value'}, self.workers[1])

def test_save_entry_level_task_assignment(self):
# user 0 only has certification for entry level tasks
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_save_entry_level_task_assignment(self):
self.clients[0], {'task_id': task_id},
task.project.short_description,
'Processing', 'Processing', False,
False, new_data)
False, new_data, self.workers[0])

def test_save_reviewer_task_assignment(self):
new_data = {'new_test_key': 'new_test_value'}
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_save_reviewer_task_assignment(self):
self.clients[1], {'task_id': task_id},
task.project.short_description,
'Processing', 'Reviewing', True,
False, reviewer_data)
False, reviewer_data, self.workers[1])

def test_submit_entry_level_task_assignment(self):
# user 0 only has certification for entry level tasks
Expand Down Expand Up @@ -304,7 +304,7 @@ def test_submit_entry_level_task_assignment(self):
self.clients[0], {'task_id': task_id},
task.project.short_description,
'Submitted', 'Pending Review', False,
True, data, work_times_seconds=[1])
True, data, self.workers[0], work_times_seconds=[1])

# user cannot resubmit a task
response = self._submit_assignment(
Expand Down Expand Up @@ -333,14 +333,14 @@ def test_submit_reviewer_task_assignment(self):
self.clients[0], {'task_id': task_id},
task.project.short_description,
'Submitted', 'Reviewing', False,
True, {'test_key': 'test_value'})
True, {'test_key': 'test_value'}, self.workers[0])

# user 1 should be able to review the post
self._verify_good_task_assignment_information(
self.clients[1], {'task_id': task_id},
task.project.short_description,
'Processing', 'Reviewing', True,
False, {'test_key': 'test_value'})
False, {'test_key': 'test_value'}, self.workers[1])

# user 1 can't submit a task
response = self._submit_assignment(
Expand All @@ -360,14 +360,14 @@ def test_submit_reviewer_task_assignment(self):
self.clients[0], {'task_id': task_id},
task.project.short_description,
'Processing', 'Post-review Processing', False,
False, rejected_data)
False, rejected_data, self.workers[0])

# user 1 should no longer be able to modify the post
self._verify_good_task_assignment_information(
self.clients[1], {'task_id': task_id},
task.project.short_description,
'Submitted', 'Post-review Processing', True,
True, rejected_data, work_times_seconds=[1])
True, rejected_data, self.workers[1], work_times_seconds=[1])

# user 0 submits an updated data
response = self._submit_assignment(
Expand All @@ -379,7 +379,7 @@ def test_submit_reviewer_task_assignment(self):
self.clients[1], {'task_id': task_id},
task.project.short_description,
'Processing', 'Reviewing', True,
False, data, work_times_seconds=[1])
False, data, self.workers[1], work_times_seconds=[1])

accepted_data = {'accepted_key': 'accepted_val'}
# user 1 accepts a task
Expand All @@ -393,7 +393,7 @@ def test_submit_reviewer_task_assignment(self):
self.clients[1], {'task_id': task_id},
task.project.short_description,
'Submitted', 'Pending Review', True,
True, accepted_data, work_times_seconds=[1, 1])
True, accepted_data, self.workers[1], work_times_seconds=[1, 1])

# make sure a task can't be submitted twice
response = self._submit_assignment(
Expand Down Expand Up @@ -424,7 +424,7 @@ def test_submit_reviewer_task_assignment(self):
self.clients[3], {'task_id': task_id},
task.project.short_description,
'Submitted', 'Post-review Processing', True,
True, rejected_data, work_times_seconds=[1])
True, rejected_data, self.workers[3], work_times_seconds=[1])

# check client dashboards
self._check_client_dashboard_state(self.clients[0], 'pending_review')
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_submit_reviewer_task_assignment(self):
self.clients[3], {'task_id': task_id},
task.project.short_description,
'Submitted', 'Complete', True,
True, accepted_data, work_times_seconds=[1, 1])
True, accepted_data, self.workers[3], work_times_seconds=[1, 1])

# check that reviewer cannot reaccept task
response = self._submit_assignment(
Expand Down Expand Up @@ -517,14 +517,14 @@ def test_task_timing(self):
self.clients[6], {'task_id': task.id},
task.project.short_description,
'Submitted', 'Complete', False,
True, {'test': 'test'},
True, {'test': 'test'}, self.workers[6],
work_times_seconds=[35, 37])

self._verify_good_task_assignment_information(
self.clients[7], {'task_id': task.id},
task.project.short_description,
'Submitted', 'Complete', True,
True, {'test': 'test'},
True, {'test': 'test'}, self.workers[7],
work_times_seconds=[36, 38])

def _verify_bad_task_assignment_information(
Expand All @@ -541,7 +541,7 @@ def _verify_bad_task_assignment_information(
def _verify_good_task_assignment_information(
self, client, post_data, project_description,
assignment_status, task_status, is_reviewer,
is_read_only, task_data, work_times_seconds=None):
is_read_only, task_data, worker, work_times_seconds=None):
if work_times_seconds is None:
work_times_seconds = []
response = client.post(
Expand All @@ -552,20 +552,27 @@ def _verify_good_task_assignment_information(

task = Task.objects.get(id=post_data['task_id'])
returned = json.loads(response.content.decode('utf-8'))
expected = {'project': {'details': project_description,
'id': task.project.id,
'project_data': {},
'review_document_url': None},
'status': assignment_status,
'task': {'data': task_data, 'status': task_status},
'task_id': task.id,
'workflow': {
'slug': 'test_workflow', 'name': 'The workflow'},
'prerequisites': {},
'step': {'slug': 'step1', 'name': 'The first step'},
'is_reviewer': is_reviewer,
'is_read_only': is_read_only,
'work_times_seconds': work_times_seconds}
expected = {
'project': {'details': project_description,
'id': task.project.id,
'project_data': {},
'review_document_url': None},
'status': assignment_status,
'task': {'data': task_data, 'status': task_status},
'task_id': task.id,
'workflow': {
'slug': 'test_workflow', 'name': 'The workflow'},
'prerequisites': {},
'step': {'slug': 'step1', 'name': 'The first step'},
'is_reviewer': is_reviewer,
'is_read_only': is_read_only,
'work_times_seconds': work_times_seconds,
'worker': {
'username': worker.user.username,
'first_name': worker.user.first_name,
'last_name': worker.user.last_name,
}
}
self.assertEquals(returned, expected)

def _submit_assignment(self, client, task_id, data=None,
Expand Down
40 changes: 23 additions & 17 deletions orchestra/tests/test_task_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,29 @@ def test_get_task_overview_for_worker(self):
get_task_overview_for_worker(task.id, self.workers[2])

data = get_task_overview_for_worker(task.id, self.workers[0])
expected = {'project': {'details': task.project.short_description,
'id': task.project.id,
'project_data': {},
'review_document_url': None},
'workflow': {'slug': 'test_workflow',
'name': 'The workflow'},
'prerequisites': {},
'step': {'slug': 'step1', 'name': 'The first step'},
'status': 'Submitted',
'task': {'data': {'test_key': 'test_value'},
'status': 'Pending Review'},
'task_id': task.id,
'is_reviewer': False,
'is_read_only': True,
'work_times_seconds': []}
self.assertEquals(data,
expected)
expected = {
'project': {'details': task.project.short_description,
'id': task.project.id,
'project_data': {},
'review_document_url': None},
'workflow': {'slug': 'test_workflow',
'name': 'The workflow'},
'prerequisites': {},
'step': {'slug': 'step1', 'name': 'The first step'},
'status': 'Submitted',
'task': {'data': {'test_key': 'test_value'},
'status': 'Pending Review'},
'task_id': task.id,
'is_reviewer': False,
'is_read_only': True,
'work_times_seconds': [],
'worker': {
'username': self.workers[0].user.username,
'first_name': self.workers[0].user.first_name,
'last_name': self.workers[0].user.last_name,
}
}
self.assertEquals(data, expected)

def test_task_assignment_saving(self):
"""
Expand Down
9 changes: 7 additions & 2 deletions orchestra/utils/task_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,18 @@ def get_task_assignment_details(task_assignment):
TaskAssignment.objects.filter(
task=task_assignment.task)
.order_by('-assignment_counter')[0])
task_assignment_details = {

worker = task_assignment.worker
worker_info = {attr: getattr(getattr(worker, 'user', None), attr, None)
for attr in ('username', 'first_name', 'last_name')}

return {
'task': {
'data': task_assignment.in_progress_task_data,
'status': (dict(Task.STATUS_CHOICES)
[task_assignment.task.status])
},
'worker': worker_info,
'status': (dict(TaskAssignment.STATUS_CHOICES)
[task_assignment.status]),
'is_reviewer': (
Expand All @@ -348,7 +354,6 @@ def get_task_assignment_details(task_assignment):
snapshot['work_time_seconds']
for snapshot in task_assignment.snapshots['snapshots']]
}
return task_assignment_details


def get_task_overview_for_worker(task_id, worker):
Expand Down

0 comments on commit 7051fe9

Please sign in to comment.