def test_task_marked_as_completed_two_way_redundancy(self): # When assignment_per_task==2, completing 2 Assignments marks Task as complete project = Project( name='test', html_template='<p>${number} - ${letter}</p><textarea>') project.save() batch = Batch(name='test', project=project) batch.assignments_per_task = 2 batch.save() task = Task(batch=batch, input_csv_fields={ 'number': '1', 'letter': 'a' }) task.save() self.assertFalse(task.completed) self.assertFalse(batch.completed) TaskAssignment(assigned_to=None, completed=True, task=task).save() task.refresh_from_db() batch.refresh_from_db() self.assertFalse(task.completed) self.assertFalse(batch.completed) TaskAssignment(assigned_to=None, completed=True, task=task).save() task.refresh_from_db() batch.refresh_from_db() self.assertTrue(task.completed) self.assertTrue(batch.completed)
class TestCancelOrPublishBatch(django.test.TestCase): def setUp(self): User.objects.create_superuser('admin', '*****@*****.**', 'secret') project = Project(name='foo', html_template='<p>${foo}: ${bar}</p>') project.save() self.batch = Batch(active=False, project=project, name='MY_BATCH_NAME') self.batch.save() def test_batch_cancel(self): batch_id = self.batch.id client = django.test.Client() client.login(username='******', password='******') response = client.post(reverse('turkle_admin:cancel_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 0) def test_batch_cancel_bad_batch_id(self): batch_id = 666 client = django.test.Client() client.login(username='******', password='******') response = client.post(reverse('turkle_admin:cancel_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 1) self.assertEqual(str(messages[0]), u'Cannot find Batch with ID 666') def test_batch_publish(self): batch_id = self.batch.id client = django.test.Client() self.assertFalse(self.batch.active) client.login(username='******', password='******') response = client.post(reverse('turkle_admin:publish_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 0) self.batch.refresh_from_db() self.assertTrue(self.batch.active) def test_batch_publish_bad_batch_id(self): batch_id = 666 client = django.test.Client() client.login(username='******', password='******') response = client.post(reverse('turkle_admin:publish_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 1) self.assertEqual(str(messages[0]), u'Cannot find Batch with ID 666')
class TestCancelOrPublishBatch(django.test.TestCase): def setUp(self): User.objects.create_superuser('admin', '*****@*****.**', 'secret') project = Project(name='foo', html_template='<p>${foo}: ${bar}</p><textarea>') project.save() self.batch = Batch(active=False, project=project, name='MY_BATCH_NAME') self.batch.save() def test_batch_cancel(self): batch_id = self.batch.id client = django.test.Client() client.login(username='******', password='******') response = client.post(reverse('turkle_admin:cancel_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 0) def test_batch_cancel_bad_batch_id(self): batch_id = 666 client = django.test.Client() client.login(username='******', password='******') response = client.post(reverse('turkle_admin:cancel_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 1) self.assertEqual(str(messages[0]), 'Cannot find Batch with ID 666') def test_batch_publish(self): batch_id = self.batch.id client = django.test.Client() self.assertFalse(self.batch.active) client.login(username='******', password='******') response = client.post(reverse('turkle_admin:publish_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 0) self.batch.refresh_from_db() self.assertTrue(self.batch.active) def test_batch_publish_bad_batch_id(self): batch_id = 666 client = django.test.Client() client.login(username='******', password='******') response = client.post(reverse('turkle_admin:publish_batch', kwargs={'batch_id': batch_id})) self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], reverse('turkle_admin:turkle_batch_changelist')) messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 1) self.assertEqual(str(messages[0]), 'Cannot find Batch with ID 666')