def test__upload__upload_MultiFileField(client, faker, n, loggedin_user, mock_email): s, f = faker.get_test_field_of_type(FieldType.get_multifile()) field_data = { f.field_name: [], } files = [] for _ in range(n): fake_file = faker.fake_file() field_data[f.field_name].append(fake_file.file_tuple()) files.append({ 'field': f, 'file': fake_file, }) expected = faker.task_details(service=s) resp = _create_task_post(client, expected, field_data) assert_emails_sent(mock_email, context='created', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(expected, loggedin_user, files=files)
def test__update_task__upload_MultiFileField__no_file(client, faker, loggedin_user, mock_email): s, f = faker.get_test_field_of_type(FieldType.get_multifile()) files = [] task = faker.get_test_task(service=s, requestor=loggedin_user) orig1 = faker.fake_file() faker.get_test_task_file(task=task, field=f, fake_file=orig1, filename=orig1.filename) files.append({'field': f, 'file': orig1}) orig2 = faker.fake_file() faker.get_test_task_file(task=task, field=f, fake_file=orig1, filename=orig1.filename) files.append({'field': f, 'file': orig1}) resp = _edit_task_post(client, task) assert_emails_sent(mock_email, context='updated', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(task, loggedin_user, files=files)
def test__update_task__with_all_values(client, faker, loggedin_user, mock_email): task = faker.get_test_task(requestor=loggedin_user) resp = _edit_task_post(client, task) assert_emails_sent(mock_email, context='updated', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(task, loggedin_user)
def test__create_task__with_all_values(client, faker, loggedin_user, mock_email): expected = faker.task_details(service=faker.get_test_service()) resp = _create_task_post(client, expected) assert_emails_sent(mock_email, context='created', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(expected, loggedin_user)
def test__upload__upload_MultiFileField__no_file(client, faker, loggedin_user, mock_email): s, f = faker.get_test_field_of_type(FieldType.get_multifile()) expected = faker.task_details(service=s) resp = _create_task_post(client, expected) assert_emails_sent(mock_email, context='created', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(expected, loggedin_user)
def test__create_task__empty_requestor__uses_current_user( client, faker, loggedin_user, mock_email): expected = faker.task_details(service=faker.get_test_service()) expected.requestor_id = None resp = _create_task_post(client, expected) assert_emails_sent(mock_email, context='created', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') expected.requestor_id = loggedin_user.id assert__task(expected, loggedin_user)
def test__upload__upload_FileField(client, faker, loggedin_user, mock_email): s, f = faker.get_test_field_of_type(FieldType.get_file()) field_data = {} fake_file = faker.fake_file() field_data[f.field_name] = fake_file.file_tuple() files = [{ 'field': f, 'file': fake_file, }] expected = faker.task_details(service=s) resp = _create_task_post(client, expected, field_data) assert_emails_sent(mock_email, context='created', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(expected, loggedin_user, files=files)
def test__update_task__fields(client, faker, field_type, original_value, value, expected_value, loggedin_user, mock_email): s, f = faker.get_test_field_of_type(FieldType._get_field_type(field_type)) field_data = {} data = [] if value is not None: field_data[f.field_name] = value data.append({ 'field': f, 'value': expected_value, }) task = faker.get_test_task(service=s, requestor=loggedin_user) orig = faker.get_test_task_data(task=task, field=f, value=original_value) resp = _edit_task_post(client, task, field_data) assert_emails_sent(mock_email, context='updated', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(task, loggedin_user, data=data)
def test__create_task__radio_fields(client, faker, choices, value, expected_value, loggedin_user, mock_email): s, f = faker.get_test_field_of_type(FieldType.get_radio(), choices=choices) field_data = {} if value is not None: field_data[f.field_name] = value expected = faker.task_details(service=s) resp = _create_task_post(client, expected, field_data) assert_emails_sent(mock_email, context='created', user=loggedin_user) assert__redirect(resp, endpoint='ui.index') assert__task(expected, loggedin_user, data=[ { 'field': f, 'value': expected_value, }, ])