def test_form_without_submit_button(self): project = Project(name='Test', html_template='<p>Quick brown fox</p><textarea>') project.created_by = self.admin project.updated_by = self.admin save_model(project) self.assertFalse(project.html_template_has_submit_button)
def test_batch_add_validation_missing_csv_fields(self): project = Project(name='foo', html_template='<p>${f1} ${f2} ${f3}</p><textarea>') project.created_by = self.user project.updated_by = self.user save_model(project) self.assertFalse(Batch.objects.filter(name='batch_save').exists()) client = django.test.Client() client.login(username='******', password='******') # CSV file has fields 'f2' and 'f3' with open( os.path.abspath( 'turkle/tests/resources/mismatched_fields.csv')) as fp: response = client.post('/admin/turkle/batch/add/', { 'project': project.id, 'name': 'batch_save', 'csv_file': fp }) self.assertEqual(response.status_code, 200) print(response.content) self.assertTrue(b'Please correct the error' in response.content) self.assertTrue(b'extra fields' not in response.content) self.assertTrue(b'missing fields' in response.content)
def setUp(self): """ Sets up Project, Task objects, and saves them to the DB. The Project form HTML only displays the one input variable. The Task has inputs and answers and refers to the Project form. """ admin = User.objects.create_superuser('admin', '*****@*****.**', 'secret') project = Project(name='test', html_template="<p>${foo}</p><textarea>") project.created_by = admin project.updated_by = admin save_model(project) batch = Batch(name='test', project=project, filename='test.csv') batch.created_by = admin batch.updated_by = admin save_model(batch) task = Task( batch=batch, input_csv_fields={'foo': 'bar'}, completed=True, ) task.save() self.task = task self.task_assignment = TaskAssignment( answers={ "comment": "\u221e", "userDisplayLanguage": "", "sentence_textbox_3_verb1": "", "city": "", "sentence_textbox_1_verb6": "", "sentence_textbox_1_verb7": "", "sentence_textbox_1_verb4": "", "sentence_textbox_1_verb5": "", "sentence_textbox_1_verb2": "", "sentence_textbox_1_verb3": "", "sentence_textbox_1_verb1": "", "sentence_textbox_2_verb4": "", "csrfmiddlewaretoken": "7zxQ9Yyug6Nsnm4nLky9p8ObJwNipdu8", "sentence_drop_2_verb3": "foo", "sentence_drop_2_verb2": "foo", "sentence_drop_2_verb1": "foo", "sentence_textbox_2_verb1": "", "sentence_textbox_2_verb3": "", "sentence_drop_2_verb4": "foo", "sentence_textbox_2_verb2": "", "submitit": "Submit", "browserInfo": "", "sentence_drop_1_verb1": "foo", "sentence_drop_1_verb2": "foo", "sentence_drop_1_verb3": "foo", "sentence_drop_1_verb4": "foo", "sentence_drop_1_verb5": "foo", "sentence_drop_1_verb6": "foo", "sentence_drop_1_verb7": "foo", "country": "", "sentence_drop_3_verb1": "foo", "ipAddress": "", "region": "" }, assigned_to=None, completed=True, task=task ) self.task_assignment.save()
def test_form_with_submit_button(self): project = Project( name='Test', html_template='<p><input id="my_submit_button" type="submit" value="MySubmit" /></p>' ) project.created_by = self.admin project.updated_by = self.admin save_model(project) self.assertTrue(project.html_template_has_submit_button)
def test_form_without_submit_button(self): project = Project( name='Test', html_template='<p>Quick brown fox</p><textarea>' ) project.created_by = self.admin project.updated_by = self.admin save_model(project) self.assertFalse(project.html_template_has_submit_button)
def test_batch_add_validation_missing_csv_fields(self): project = Project(name='foo', html_template='<p>${f1} ${f2} ${f3}</p><textarea>') project.created_by = self.user project.updated_by = self.user save_model(project) self.assertFalse(Batch.objects.filter(name='batch_save').exists()) client = django.test.Client() client.login(username='******', password='******') # CSV file has fields 'f2' and 'f3' with open(os.path.abspath('turkle/tests/resources/mismatched_fields.csv')) as fp: response = client.post( '/admin/turkle/batch/add/', { 'project': project.id, 'name': 'batch_save', 'csv_file': fp }) self.assertEqual(response.status_code, 200) print(response.content) self.assertTrue(b'Please correct the error' in response.content) self.assertTrue(b'extra fields' not in response.content) self.assertTrue(b'missing fields' in response.content)