def test_post(self): stuff = u"³²¼½¬¼³²" for attrname in Context.localized_strings: self.dummyContext[attrname] = u"³²¼½¬¼³²" # the test context need fields to be present from globaleaks.handlers.admin.field import create_field for idx, field in enumerate(self.dummyFields): self.dummyFields[idx]['id'] = yield create_field(field, 'en') # the test context need fields to be present from globaleaks.handlers.admin.field import create_field for idx, field in enumerate(self.dummyFields): f = yield create_field(field, 'en') self.dummyFields[idx]['id'] = f['id'] self.dummyContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[4] # Generalities ] handler = self.request(self.dummyContext, role='admin') yield handler.post() self.dummyContext['id'] = self.responses[0]['id'] self.dummyContext['creation_date'] = self.responses[0]['creation_date'] self.assertEqual(self.responses[0]['description'], stuff)
def fill_data(self): # fill_data/create_admin self.dummyAdmin = yield create_admin(copy.deepcopy(self.dummyAdminUser), 'en') self.dummyAdminUser['id'] = self.dummyAdmin['id'] # fill_data/create_custodian self.dummyCustodian = yield create_custodian(copy.deepcopy(self.dummyCustodianUser), 'en') self.dummyCustodianUser['id'] = self.dummyCustodian['id'] # fill_data/create_receiver self.dummyReceiver_1 = yield create_receiver(copy.deepcopy(self.dummyReceiver_1), 'en') self.dummyReceiverUser_1['id'] = self.dummyReceiver_1['id'] self.dummyReceiver_2 = yield create_receiver(copy.deepcopy(self.dummyReceiver_2), 'en') self.dummyReceiverUser_2['id'] = self.dummyReceiver_2['id'] receivers_ids = [self.dummyReceiver_1['id'], self.dummyReceiver_2['id']] # fill_data/create_context self.dummyContext['receivers'] = receivers_ids self.dummyContext = yield create_context(copy.deepcopy(self.dummyContext), 'en') # fill_data: create field templates for idx, field in enumerate(self.dummyFieldTemplates): f = yield create_field(copy.deepcopy(field), 'en', 'import') self.dummyFieldTemplates[idx]['id'] = f['id'] for idx, field in enumerate(self.dummyFields): change_field_type(field, 'instance') field['step_id'] = self.dummyContext['steps'][0]['id'] f = yield create_field(copy.deepcopy(field), 'en', 'import') self.dummyFields[idx]['id'] = f['id'] self.dummyContext['steps'][0]['children'].append(f) yield update_context(self.dummyContext['id'], copy.deepcopy(self.dummyContext), 'en')
def fill_data(self): yield do_appdata_init() # fill_data/create_admin self.dummyAdmin = yield create_admin( copy.deepcopy(self.dummyAdminUser), 'en') self.dummyAdminUser['id'] = self.dummyAdmin['id'] # fill_data/create_custodian self.dummyCustodian = yield create_custodian( copy.deepcopy(self.dummyCustodianUser), 'en') self.dummyCustodianUser['id'] = self.dummyCustodian['id'] custodians_ids = [self.dummyCustodian['id']] # fill_data/create_receiver self.dummyReceiver_1 = yield create_receiver( copy.deepcopy(self.dummyReceiver_1), 'en') self.dummyReceiverUser_1['id'] = self.dummyReceiver_1['id'] self.dummyReceiver_2 = yield create_receiver( copy.deepcopy(self.dummyReceiver_2), 'en') self.dummyReceiverUser_2['id'] = self.dummyReceiver_2['id'] receivers_ids = [ self.dummyReceiver_1['id'], self.dummyReceiver_2['id'] ] # fill_data/create_context self.dummyContext['custodians'] = custodians_ids self.dummyContext['receivers'] = receivers_ids self.dummyContext = yield create_context( copy.deepcopy(self.dummyContext), 'en') # fill_data: create field templates for idx, field in enumerate(self.dummyFieldTemplates): f = yield create_field(copy.deepcopy(field), 'en') self.dummyFieldTemplates[idx]['id'] = f['id'] # fill_data: create fields and associate them to the context steps for idx, field in enumerate(self.dummyFields): field['instance'] = 'instance' if idx <= 2: # "Field 1", "Field 2" and "Generalities" are associated to the first step field['step_id'] = self.dummyContext['steps'][0]['id'] else: # Name, Surname, Gender" are associated to field "Generalities" # "Field 1" and "Field 2" are associated to the first step field['fieldgroup_id'] = self.dummyFields[2]['id'] f = yield create_field(copy.deepcopy(field), 'en') self.dummyFields[idx]['id'] = f['id'] self.dummyContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[2] # Generalities ] yield update_context(self.dummyContext['id'], copy.deepcopy(self.dummyContext), 'en')
def fill_data(self): yield do_appdata_init() # fill_data/create_admin self.dummyAdmin = yield create_admin(copy.deepcopy(self.dummyAdminUser), 'en') self.dummyAdminUser['id'] = self.dummyAdmin['id'] # fill_data/create_custodian self.dummyCustodian = yield create_custodian(copy.deepcopy(self.dummyCustodianUser), 'en') self.dummyCustodianUser['id'] = self.dummyCustodian['id'] custodians_ids = [self.dummyCustodian['id']] # fill_data/create_receiver self.dummyReceiver_1 = yield create_receiver(copy.deepcopy(self.dummyReceiver_1), 'en') self.dummyReceiverUser_1['id'] = self.dummyReceiver_1['id'] self.dummyReceiver_2 = yield create_receiver(copy.deepcopy(self.dummyReceiver_2), 'en') self.dummyReceiverUser_2['id'] = self.dummyReceiver_2['id'] receivers_ids = [self.dummyReceiver_1['id'], self.dummyReceiver_2['id']] # fill_data/create_context self.dummyContext['custodians'] = custodians_ids self.dummyContext['receivers'] = receivers_ids self.dummyContext = yield create_context(copy.deepcopy(self.dummyContext), 'en') # fill_data: create field templates for idx, field in enumerate(self.dummyFieldTemplates): f = yield create_field(copy.deepcopy(field), 'en') self.dummyFieldTemplates[idx]['id'] = f['id'] # fill_data: create fields and associate them to the context steps for idx, field in enumerate(self.dummyFields): field['instance'] = 'instance' if idx <= 2: # "Field 1", "Field 2" and "Generalities" are associated to the first step field['step_id'] = self.dummyContext['steps'][0]['id'] else: # Name, Surname, Gender" are associated to field "Generalities" # "Field 1" and "Field 2" are associated to the first step field['fieldgroup_id'] = self.dummyFields[2]['id'] f = yield create_field(copy.deepcopy(field), 'en') self.dummyFields[idx]['id'] = f['id'] self.dummyContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[2] # Generalities ] yield update_context(self.dummyContext['id'], copy.deepcopy(self.dummyContext), 'en')
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ values = helpers.get_dummy_field() values['instance'] = 'template' field = yield create_field(1, values, 'en') updated_sample_field = helpers.get_dummy_field() updated_sample_field['instance'] = 'template' updated_sample_field['type'] = 'inputbox' updated_sample_field['options'] = [] updated_sample_field['x'] = 3 updated_sample_field['y'] = 3 handler = self.request(updated_sample_field, role='admin') response = yield handler.put(field['id']) self.assertEqual(field['id'], response['id']) self.assertEqual(3, response['x']) self.assertEqual(3, response['y']) wrong_sample_field = helpers.get_dummy_field() wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertRaises(errors.InputValidationError, handler.put, field['id'])
def test_post_create_from_template(self): """ Attempt to create a new field from template via post request """ values = self.get_dummy_field() values['instance'] = 'template' field_template = yield create_field(values, 'en') context = yield create_context(copy.deepcopy(self.dummyContext), 'en') step_id = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) values = self.get_dummy_field() values['instance'] = 'reference' values['template_id'] = field_template['id'] values['step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) handler = self.request(values, role='admin') yield handler.post() self.assertEqual(len(self.responses), 1) resp, = self.responses self.assertIn('id', resp) self.assertNotEqual(resp.get('options'), None)
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ attrs = get_sample_field() attrs['is_template'] = False attrs['step_id'] = yield get_step_id(self.dummyContext['id']) field = yield create_field(attrs, 'en') updated_sample_field = get_sample_field() updated_sample_field['is_template'] = False updated_sample_field['step_id'] = yield get_step_id(self.dummyContext['id']) updated_sample_field.update(type='inputbox') handler = self.request(updated_sample_field, role='admin') yield handler.put(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id']) self.assertEqual(self.responses[0]['type'], 'inputbox') wrong_sample_field = get_sample_field() attrs['is_template'] = False attrs['step_id'] = yield get_step_id(self.dummyContext['id']) wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertFailure(handler.put(field['id']), errors.InvalidInputFormat)
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ values = self.get_dummy_field() values["instance"] = "instance" context = yield create_context(copy.deepcopy(self.dummyContext), "en") values["step_id"] = yield get_step_id(context["id"]) field = yield create_field(values, "en") updated_sample_field = self.get_dummy_field() updated_sample_field["instance"] = "instance" context = yield create_context(copy.deepcopy(self.dummyContext), "en") updated_sample_field["step_id"] = yield get_step_id(context["id"]) updated_sample_field.update(type="inputbox") handler = self.request(updated_sample_field, role="admin") yield handler.put(field["id"]) self.assertEqual(len(self.responses), 1) self.assertEqual(field["id"], self.responses[0]["id"]) self.assertEqual(self.responses[0]["type"], "inputbox") wrong_sample_field = self.get_dummy_field() values["instance"] = "instance" values["step_id"] = yield get_step_id(context["id"]) wrong_sample_field.update(type="nonexistingfieldtype") handler = self.request(wrong_sample_field, role="admin") self.assertFailure(handler.put(field["id"]), errors.InvalidInputFormat)
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ values = helpers.get_dummy_field() values['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) field = yield create_field(values, 'en') updated_sample_field = helpers.get_dummy_field() updated_sample_field['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') updated_sample_field[ 'step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) updated_sample_field.update(type='inputbox') handler = self.request(updated_sample_field, role='admin') response = yield handler.put(field['id']) self.assertEqual(field['id'], response['id']) self.assertEqual(response['type'], 'inputbox') wrong_sample_field = helpers.get_dummy_field() values['instance'] = 'instance' values['step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertRaises(errors.InvalidInputFormat, handler.put, field['id'])
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ attrs = self.get_dummy_field() attrs['is_template'] = False self.dummyContext = yield create_context(self.dummyContext, 'en') attrs['step_id'] = yield get_step_id(self.dummyContext['id']) field = yield create_field(attrs, 'en') updated_sample_field = self.get_dummy_field() updated_sample_field['is_template'] = False self.dummyContext = yield create_context(self.dummyContext, 'en') updated_sample_field['step_id'] = yield get_step_id( self.dummyContext['id']) updated_sample_field.update(type='inputbox') handler = self.request(updated_sample_field, role='admin') yield handler.put(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id']) self.assertEqual(self.responses[0]['type'], 'inputbox') wrong_sample_field = self.get_dummy_field() attrs['is_template'] = False attrs['step_id'] = yield get_step_id(self.dummyContext['id']) wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertFailure(handler.put(field['id']), errors.InvalidInputFormat)
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ values = helpers.get_dummy_field() values['instance'] = 'instance' context = yield create_context(1, copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_id_of_first_step_of_questionnaire(context['questionnaire_id']) field = yield create_field(1, values, 'en') updated_sample_field = helpers.get_dummy_field() updated_sample_field['instance'] = 'instance' context = yield create_context(1, copy.deepcopy(self.dummyContext), 'en') updated_sample_field['step_id'] = yield get_id_of_first_step_of_questionnaire(context['questionnaire_id']) updated_sample_field.update(type=u'inputbox', options=[], x=3, y=3) handler = self.request(updated_sample_field, role='admin') response = yield handler.put(field['id']) self.assertEqual(field['id'], response['id']) self.assertEqual(3, response['x']) self.assertEqual(3, response['y']) wrong_sample_field = helpers.get_dummy_field() values['instance'] = 'instance' values['step_id'] = yield get_id_of_first_step_of_questionnaire(context['questionnaire_id']) wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertRaises(errors.InputValidationError, handler.put, field['id'])
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ values = self.get_dummy_field() values['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_step_id(context['id']) field = yield create_field(values, 'en') updated_sample_field = self.get_dummy_field() updated_sample_field['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') updated_sample_field['step_id'] = yield get_step_id(context['id']) updated_sample_field.update(type='inputbox') handler = self.request(updated_sample_field, role='admin') yield handler.put(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id']) self.assertEqual(self.responses[0]['type'], 'inputbox') wrong_sample_field = self.get_dummy_field() values['instance'] = 'instance' values['step_id'] = yield get_step_id(context['id']) wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertFailure(handler.put(field['id']), errors.InvalidInputFormat)
def test_001_setup_submission_environment(self): helpers.TestGL.setUp(self) basehandler = MockHandler() stuff = u"AAA :P ³²¼½¬¼³²" for attrname in Context.localized_strings: SubmissionTest.aContext1[attrname] = stuff basehandler.validate_jmessage(SubmissionTest.aContext1, adminContextDesc) # the test context need fields to be present from globaleaks.handlers.admin.field import create_field for idx, field in enumerate(self.dummyFields): f = yield create_field(field, 'en') self.dummyFields[idx]['id'] = f['id'] SubmissionTest.aContext1['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[4] # Generalities ] SubmissionTest.context_used = yield admin.create_context(SubmissionTest.aContext1) # Correctly, TTip.tipContext has not selectable receiver, and we want test it in the 2nd test SubmissionTest.context_used['selectable_receiver'] = True for attrname in Context.localized_strings: SubmissionTest.context_used[attrname] = stuff SubmissionTest.context_used = yield admin.update_context(SubmissionTest.context_used['id'], SubmissionTest.context_used) basehandler.validate_jmessage( SubmissionTest.aContext2, adminContextDesc) SubmissionTest.context_unused = yield admin.create_context(SubmissionTest.aContext2) self.assertTrue(len(SubmissionTest.context_used['id']) > 1) self.assertTrue(len(SubmissionTest.context_unused['id']) > 1) SubmissionTest.aReceiver1['contexts'] = [ SubmissionTest.context_used['id'] ] for attrname in Receiver.localized_strings: SubmissionTest.aReceiver1[attrname] = stuff * 2 SubmissionTest.aReceiver2[attrname] = stuff * 4 basehandler.validate_jmessage( SubmissionTest.aReceiver1, adminReceiverDesc ) SubmissionTest.receiver_used = yield admin.create_receiver(SubmissionTest.aReceiver1) SubmissionTest.aReceiver2['contexts'] = [ SubmissionTest.context_unused['id'] ] basehandler.validate_jmessage( SubmissionTest.aReceiver2, adminReceiverDesc ) SubmissionTest.receiver_unused = yield admin.create_receiver(SubmissionTest.aReceiver2) self.assertTrue(SubmissionTest.receiver_used['name'] == SubmissionTest.aReceiver1['name']) self.assertTrue(SubmissionTest.receiver_unused['name'] == SubmissionTest.aReceiver2['name']) self.assertTrue(len(SubmissionTest.receiver_used['contexts']), 1) self.assertTrue(len(SubmissionTest.receiver_unused['contexts']), 1)
def fill_data(self): yield do_appdata_init() receivers_ids = [] # fill_data/create_receiver self.dummyReceiver_1 = yield create_receiver(self.dummyReceiver_1, 'en') receivers_ids.append(self.dummyReceiver_1['id']) self.dummyReceiver_2 = yield create_receiver(self.dummyReceiver_2, 'en') receivers_ids.append(self.dummyReceiver_2['id']) # fill_data/create_context self.dummyContext['receivers'] = receivers_ids self.dummyContext = yield create_context( copy.deepcopy(self.dummyContext), 'en') # fill_data: create field templates for idx, field in enumerate(self.dummyFieldTemplates): f = yield create_field(copy.deepcopy(field), 'en') self.dummyFieldTemplates[idx]['id'] = f['id'] # fill_data: create fields and associate them to the context steps for idx, field in enumerate(self.dummyFields): field['is_template'] = False if idx <= 2: # "Field 1", "Field 2" and "Generalities" are associated to the first step field['step_id'] = self.dummyContext['steps'][0]['id'] else: # Name, Surname, Gender" are associated to field "Generalities" # "Field 1" and "Field 2" are associated to the first step field['fieldgroup_id'] = self.dummyFields[2]['id'] f = yield create_field(copy.deepcopy(field), 'en') self.dummyFields[idx]['id'] = f['id'] self.dummyContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[2] # Generalities ] yield update_context(self.dummyContext['id'], copy.deepcopy(self.dummyContext), 'en')
def test_get(self): """ Create a new field, the get it back using the receieved id. """ field = yield create_field(self.get_dummy_field(), 'en') handler = self.request(role='admin') yield handler.get(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id'])
def test_delete(self): """ Create a new field template, then attempt to delete it. """ values = helpers.get_dummy_field() values['instance'] = 'template' field = yield create_field(1, values, 'en') handler = self.request(role='admin') yield handler.delete(field['id'])
def test_get(self): """ Create a new field, the get it back using the receieved id. """ values = helpers.get_dummy_field() values['instance'] = 'template' field = yield create_field(values, 'en') handler = self.request(role='admin') response = yield handler.get(field['id']) self.assertEqual(field['id'], response['id'])
def fill_data(self): yield do_appdata_init() receivers_ids = [] # fill_data/create_receiver self.dummyReceiver_1 = yield create_receiver(self.dummyReceiver_1, 'en') receivers_ids.append(self.dummyReceiver_1['id']) self.dummyReceiver_2 = yield create_receiver(self.dummyReceiver_2, 'en') receivers_ids.append(self.dummyReceiver_2['id']) # fill_data/create_context self.dummyContext['receivers'] = receivers_ids self.dummyContext = yield create_context(copy.deepcopy(self.dummyContext), 'en') # fill_data: create field templates for idx, field in enumerate(self.dummyFieldTemplates): f = yield create_field(copy.deepcopy(field), 'en') self.dummyFieldTemplates[idx]['id'] = f['id'] # fill_data: create fields and associate them to the context steps for idx, field in enumerate(self.dummyFields): field['is_template'] = False if idx <= 2: # "Field 1", "Field 2" and "Generalities" are associated to the first step field['step_id'] = self.dummyContext['steps'][0]['id'] else: # Name, Surname, Gender" are associated to field "Generalities" # "Field 1" and "Field 2" are associated to the first step field['fieldgroup_id'] = self.dummyFields[2]['id'] f = yield create_field(copy.deepcopy(field), 'en') self.dummyFields[idx]['id'] = f['id'] self.dummyContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[2] # Generalities ] yield update_context(self.dummyContext['id'], copy.deepcopy(self.dummyContext), 'en')
def test_delete(self): """ Create a new field, then attempt to delete it. """ values = helpers.get_dummy_field() values['instance'] = 'instance' context = yield create_context(1, copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_id_of_first_step_of_questionnaire(context['questionnaire_id']) field = yield create_field(1, values, 'en') handler = self.request(role='admin') yield handler.delete(field['id'])
def test_get(self): """ Create a new field, the get it back using the receieved id. """ values = self.get_dummy_field() values["instance"] = "template" field = yield create_field(values, "en") handler = self.request(role="admin") yield handler.get(field["id"]) self.assertEqual(len(self.responses), 1) self.assertEqual(field["id"], self.responses[0]["id"])
def test_delete(self): """ Create a new field, then attempt to delete it. """ attrs = self.get_dummy_field() field = yield create_field(attrs, 'en') handler = self.request(role='admin') yield handler.delete(field['id']) self.assertEqual(handler.get_status(), 200) # second deletion operation should fail self.assertFailure(handler.delete(field['id']), errors.FieldIdNotFound)
def test_get(self): """ Create a new field, the get it back using the receieved id. """ values = helpers.get_dummy_field() values['instance'] = 'template' field = yield create_field(values, 'en') handler = self.request(role='admin') yield handler.get(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id'])
def test_delete(self): """ Create a new field template, then attempt to delete it. """ values = self.get_dummy_field() values["instance"] = "template" field = yield create_field(values, "en") handler = self.request(role="admin") yield handler.delete(field["id"]) self.assertEqual(handler.get_status(), 200) # second deletion operation should fail self.assertFailure(handler.delete(field["id"]), errors.FieldIdNotFound)
def test_get(self): """ Create a new field, the get it back using the receieved id. """ attrs = get_sample_field() attrs['is_template'] = False attrs['step_id'] = yield get_step_id(self.dummyContext['id']) field = yield create_field(attrs, 'en') handler = self.request(role='admin') yield handler.get(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id'])
def test_delete(self): """ Create a new field template, then attempt to delete it. """ values = helpers.get_dummy_field() values['instance'] = 'template' field = yield create_field(values, 'en') handler = self.request(role='admin') yield handler.delete(field['id']) # second deletion operation should fail yield self.assertFailure(handler.delete(field['id']), errors.FieldIdNotFound)
def test_delete(self): """ Create a new field template, then attempt to delete it. """ values = helpers.get_dummy_field() values['instance'] = 'template' field = yield create_field(values, 'en') handler = self.request(role='admin') yield handler.delete(field['id']) self.assertEqual(handler.get_status(), 200) # second deletion operation should fail yield self.assertFailure(handler.delete(field['id']), errors.FieldIdNotFound)
def test_delete(self): """ Create a new field, then attempt to delete it. """ values = helpers.get_dummy_field() values['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) field = yield create_field(values, 'en') handler = self.request(role='admin') yield handler.delete(field['id'])
def test_get(self): """ Create a new field, the get it back using the receieved id. """ attrs = self.get_dummy_field() attrs['is_template'] = False self.dummyContext = yield create_context(self.dummyContext, 'en') attrs['step_id'] = yield get_step_id(self.dummyContext['id']) field = yield create_field(attrs, 'en') handler = self.request(role='admin') yield handler.get(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id'])
def test_get(self): """ Create a new field, then get it back using the received id. """ values = self.get_dummy_field() values['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_step_id(context['id']) field = yield create_field(values, 'en') handler = self.request(role='admin') yield handler.get(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id'])
def test_get(self): """ Create a new field, then get it back using the received id. """ values = self.get_dummy_field() values["instance"] = "instance" context = yield create_context(copy.deepcopy(self.dummyContext), "en") values["step_id"] = yield get_step_id(context["id"]) field = yield create_field(values, "en") handler = self.request(role="admin") yield handler.get(field["id"]) self.assertEqual(len(self.responses), 1) self.assertEqual(field["id"], self.responses[0]["id"])
def test_get(self): """ Create a new field, then get it back using the received id. """ values = helpers.get_dummy_field() values['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) field = yield create_field(values, 'en') handler = self.request(role='admin') response = yield handler.get(field['id']) self.assertEqual(field['id'], response['id'])
def test_delete(self): """ Create a new field, then attempt to delete it. """ values = self.get_dummy_field() values['instance'] = 'instance' context = yield create_context(copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_step_id(context['id']) field = yield create_field(values, 'en') handler = self.request(role='admin') yield handler.delete(field['id']) self.assertEqual(handler.get_status(), 200) # second deletion operation should fail self.assertFailure(handler.delete(field['id']), errors.FieldIdNotFound)
def setup_tip_environment(self): basehandler = MockHandler() stuff = u'⅛⅛⅛£"$"$¼³²¼²³¼²³“““““ð' for attrname in models.Context.localized_strings: self.tipContext[attrname] = stuff basehandler.validate_jmessage(self.tipContext, requests.adminContextDesc) # the test context need fields to be present from globaleaks.handlers.admin.field import create_field for idx, field in enumerate(self.dummyFields): f = yield create_field(field, 'en') self.dummyFields[idx]['id'] = f['id'] self.tipContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[4] # Generalities ] self.context_desc = yield admin.create_context(self.tipContext) self.tipReceiver1['contexts'] = self.tipReceiver2['contexts'] = [ self.context_desc['id'] ] for attrname in models.Receiver.localized_strings: self.tipReceiver1[attrname] = stuff self.tipReceiver2[attrname] = stuff basehandler.validate_jmessage( self.tipReceiver1, requests.adminReceiverDesc ) basehandler.validate_jmessage( self.tipReceiver2, requests.adminReceiverDesc ) self.receiver1_desc = yield admin.create_receiver(self.tipReceiver1) self.receiver2_desc = yield admin.create_receiver(self.tipReceiver2) self.assertEqual(self.receiver1_desc['contexts'], [ self.context_desc['id']]) dummySubmissionDict = yield self.get_dummy_submission(self.context_desc['id']) basehandler.validate_jmessage(dummySubmissionDict, requests.wbSubmissionDesc) self.submission_desc = yield submission.create_submission(dummySubmissionDict, finalize=True) self.assertEqual(self.submission_desc['wb_steps'], dummySubmissionDict['wb_steps']) self.assertEqual(self.submission_desc['mark'], models.InternalTip._marker[1])
def test_put_1(self): """ Attempt to update a field, changing its type via a put request. """ field = yield create_field(self.get_dummy_field(), 'en') updated_sample_field = self.get_dummy_field() updated_sample_field.update(type='inputbox') handler = self.request(updated_sample_field, role='admin') yield handler.put(field['id']) self.assertEqual(len(self.responses), 1) self.assertEqual(field['id'], self.responses[0]['id']) self.assertEqual(self.responses[0]['type'], 'inputbox') wrong_sample_field = self.get_dummy_field() wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertFailure(handler.put(field['id']), errors.InvalidInputFormat)
def do_setup_tip_environment(self): basehandler = MockHandler() # the test context need fields to be present from globaleaks.handlers.admin.field import create_field for idx, field in enumerate(self.dummyFields): f = yield create_field(field, 'en') self.dummyFields[idx]['id'] = f['id'] self.tipContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[4] # Generalities ] basehandler.validate_jmessage(self.tipContext, requests.adminContextDesc) self.context_desc = yield admin.create_context(self.tipContext) self.tipReceiver1['contexts'] = self.tipReceiver2['contexts'] = [ self.context_desc['id'] ] for attrname in models.Receiver.localized_strings: self.tipReceiver2[attrname] = u'222222’‘ª‘ª’‘ÐŊ' self.tipReceiver1[attrname] = u'⅛¡⅜⅛’ŊÑŦŊ1111111’‘ª‘ª’‘ÐŊ' basehandler.validate_jmessage( self.tipReceiver1, requests.adminReceiverDesc ) basehandler.validate_jmessage( self.tipReceiver2, requests.adminReceiverDesc ) try: self.receiver1_desc = yield admin.create_receiver(self.tipReceiver1) self.receiver2_desc = yield admin.create_receiver(self.tipReceiver2) except Exception as exxxx: self.assertTrue(False) self.assertEqual(self.receiver1_desc['contexts'], [ self.context_desc['id']]) self.assertEqual(self.receiver2_desc['contexts'], [ self.context_desc['id']]) dummySubmission = yield self.get_dummy_submission(self.context_desc['id']) basehandler.validate_jmessage( dummySubmission, requests.wbSubmissionDesc) self.submission_desc = yield submission.create_submission(dummySubmission, finalize=False) self.assertEqual(self.submission_desc['wb_steps'], dummySubmission['wb_steps']) self.assertEqual(self.submission_desc['mark'], models.InternalTip._marker[0])
def setup_tip_environment(self): basehandler = MockHandler() stuff = u'⅛⅛⅛£"$"$¼³²¼²³¼²³“““““ð' for attrname in models.Context.localized_strings: self.tipContext[attrname] = stuff basehandler.validate_jmessage(self.tipContext, requests.adminContextDesc) for idx, field in enumerate(self.dummyFields): f = yield create_field(field, 'en') self.dummyFields[idx]['id'] = f['id'] self.tipContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[4] # Generalities ] self.context_desc = yield admin.create_context(self.tipContext, 'en') self.tipReceiver1['contexts'] = self.tipReceiver2['contexts'] = [ self.context_desc['id'] ] for attrname in models.Receiver.localized_strings: self.tipReceiver1[attrname] = stuff self.tipReceiver2[attrname] = stuff basehandler.validate_jmessage( self.tipReceiver1, requests.adminReceiverDesc ) basehandler.validate_jmessage( self.tipReceiver2, requests.adminReceiverDesc ) self.receiver1_desc = yield admin.create_receiver(self.tipReceiver1, 'en') self.receiver2_desc = yield admin.create_receiver(self.tipReceiver2, 'en') self.assertEqual(self.receiver1_desc['contexts'], [ self.context_desc['id']]) dummySubmissionDict = yield self.get_dummy_submission(self.context_desc['id']) basehandler.validate_jmessage(dummySubmissionDict, requests.wbSubmissionDesc) self.submission_desc = yield submission.create_submission(dummySubmissionDict, True, 'en') self.assertEqual(self.submission_desc['wb_steps'], dummySubmissionDict['wb_steps']) self.assertEqual(self.submission_desc['mark'], u'finalize')
def test_post_create_from_template(self): """ Attempt to create a new field from template via post request """ values = helpers.get_dummy_field() values['instance'] = 'template' field_template = yield create_field(1, values, 'en') context = yield create_context(1, copy.deepcopy(self.dummyContext), 'en') values = helpers.get_dummy_field() values['instance'] = 'reference' values['template_id'] = field_template['id'] values['step_id'] = yield get_id_of_first_step_of_questionnaire(context['questionnaire_id']) handler = self.request(values, role='admin') response = yield handler.post() self.assertIn('id', response) self.assertNotEqual(response.get('options'), None)
def test_post_create_from_template(self): """ Attempt to create a new field from template via post request """ values = self.get_dummy_field() values['is_template'] = True field_template = yield create_field(values, 'en') context = yield create_context(copy.deepcopy(self.dummyContext), 'en') step_id = yield get_step_id(context['id']) values = self.get_dummy_field() values['template_id'] = field_template['id'] handler = self.request(values, role='admin') yield handler.post() self.assertEqual(len(self.responses), 1) resp, = self.responses self.assertIn('id', resp) self.assertNotEqual(resp.get('options'), None)
def test_put(self): """ Attempt to update a field, changing its type via a put request. """ values = helpers.get_dummy_field() values['instance'] = 'instance' context = yield create_context(self.state, 1, copy.deepcopy(self.dummyContext), 'en') values['step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) field = yield create_field(1, values, 'en') updated_sample_field = helpers.get_dummy_field() updated_sample_field['instance'] = 'instance' context = yield create_context(self.state, 1, copy.deepcopy(self.dummyContext), 'en') updated_sample_field[ 'step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) updated_sample_field.update(type=u'inputbox', options=[], x=3, y=3) handler = self.request(updated_sample_field, role='admin') response = yield handler.put(field['id']) self.assertEqual(field['id'], response['id']) self.assertEqual(3, response['x']) self.assertEqual(3, response['y']) # assert that it is impossible to change field type self.assertEqual(response['type'], 'multichoice') wrong_sample_field = helpers.get_dummy_field() values['instance'] = 'instance' values['step_id'] = yield get_id_of_first_step_of_questionnaire( context['questionnaire_id']) wrong_sample_field.update(type='nonexistingfieldtype') handler = self.request(wrong_sample_field, role='admin') self.assertRaises(errors.InputValidationError, handler.put, field['id'])
def test_post_create_from_template(self): """ Attempt to create a new field from template via post request """ values = self.get_dummy_field() values["instance"] = "template" field_template = yield create_field(values, "en") context = yield create_context(copy.deepcopy(self.dummyContext), "en") step_id = yield get_step_id(context["id"]) values = self.get_dummy_field() values["instance"] = "reference" values["template_id"] = field_template["id"] values["step_id"] = yield get_step_id(context["id"]) handler = self.request(values, role="admin") yield handler.post() self.assertEqual(len(self.responses), 1) resp, = self.responses self.assertIn("id", resp) self.assertNotEqual(resp.get("options"), None)
def test_post_create_from_template(self): """ Attempt to create a new field from template via post request """ attrs = self.get_dummy_field() attrs['is_template'] = True field_template = yield create_field(attrs, 'en') context = yield create_context(self.dummyContext, 'en') step_id = yield get_step_id(context['id']) attrs = { 'template_id': field_template['id'], 'context_id': '', 'step_id': step_id } handler = self.request(attrs, role='admin') yield handler.post() self.assertEqual(len(self.responses), 1) resp, = self.responses self.assertIn('id', resp) self.assertNotEqual(resp.get('options'), None)
def fill_data(self): yield do_appdata_init() receivers_ids = [] # fill_data/create_receiver self.dummyReceiver_1 = yield create_receiver(self.dummyReceiver_1) receivers_ids.append(self.dummyReceiver_1['id']) self.dummyReceiver_2 = yield create_receiver(self.dummyReceiver_2) receivers_ids.append(self.dummyReceiver_2['id']) # fill_data/create_context self.dummyContext['receivers'] = receivers_ids self.dummyContext = yield create_context(self.dummyContext) # fill_data: create cield templates for idx, field in enumerate(self.dummyFieldTemplates): f = yield create_field(field, 'en') self.dummyFieldTemplates[idx]['id'] = f['id'] # fill_data: create fields and associate them to the context steps for idx, field in enumerate(self.dummyFields): field['is_template'] = False if idx <= 2: # "Field 1", "Field 2" and "Generalities" are associated to the first step field['step_id'] = self.dummyContext['steps'][0]['id'] else: # Name, Surname, Gender" are associated to field "Generalities" # "Field 1" and "Field 2" are associated to the first step field['fieldgroup_id'] = self.dummyFields[2]['id'] f = yield create_field(field, 'en') self.dummyFields[idx]['id'] = f['id'] self.dummyContext['steps'][0]['children'] = [ self.dummyFields[0], # Field 1 self.dummyFields[1], # Field 2 self.dummyFields[2] # Generalities ] yield update_context(self.dummyContext['id'], self.dummyContext) # fill_data/create_submission self.dummySubmission['context_id'] = self.dummyContext['id'] self.dummySubmission['receivers'] = receivers_ids self.dummySubmission['wb_steps'] = yield fill_random_fields(self.dummyContext['id']) self.dummySubmissionNotFinalized = yield create_submission(self.dummySubmission, finalize=False) self.dummySubmission = yield create_submission(self.dummySubmission, finalize=False) yield self.emulate_file_upload(self.dummySubmission['id']) # fill_data/update_submssion submission = yield update_submission(self.dummySubmission['id'], self.dummySubmission, finalize=True) # fill_data/create_whistleblower self.dummyWBTip = yield create_whistleblower_tip(self.dummySubmission) assert self.dummyReceiver_1.has_key('id') assert self.dummyReceiver_2.has_key('id') assert self.dummyContext.has_key('id') assert self.dummySubmission.has_key('id') yield delivery_sched.DeliverySchedule().operation() yield notification_sched.NotificationSchedule().operation() commentCreation = { 'content': 'comment!', } messageCreation = { 'content': 'message!', } rtips_desc = yield self.get_rtips() for rtip_desc in rtips_desc: yield rtip.create_comment_receiver(rtip_desc['receiver_id'], rtip_desc['rtip_id'], commentCreation) yield rtip.create_message_receiver(rtip_desc['receiver_id'], rtip_desc['rtip_id'], messageCreation) wbtips_desc = yield self.get_wbtips() for wbtip_desc in wbtips_desc: yield wbtip.create_comment_wb(wbtip_desc['wbtip_id'], commentCreation) for receiver_id in wbtip_desc['wbtip_receivers']: yield wbtip.create_message_wb(wbtip_desc['wbtip_id'], receiver_id, messageCreation) yield delivery_sched.DeliverySchedule().operation() yield notification_sched.NotificationSchedule().operation()