moved existing template folder tests into test_template_folders

also refactored slightly to work with new html, and separate succesful
and bad-permissions test cases
This commit is contained in:
Leo Hemsted
2018-11-19 17:33:33 +00:00
parent 690585c017
commit 6743bd11fa
3 changed files with 270 additions and 271 deletions

View File

@@ -1,4 +1,3 @@
import uuid
from datetime import datetime
from unittest.mock import ANY, Mock
@@ -28,8 +27,6 @@ from tests.conftest import (
TEMPLATE_ONE_ID,
active_caseworking_user,
active_user_view_permissions,
active_user_with_permissions,
fake_uuid,
mock_get_service_email_template,
mock_get_service_letter_template,
mock_get_service_template,
@@ -176,265 +173,6 @@ def test_should_show_page_for_choosing_a_template(
mock_get_template_folders.assert_called_once_with(SERVICE_ONE_ID)
@pytest.mark.parametrize('user', [
pytest.param(
active_user_with_permissions
),
pytest.param(
active_user_view_permissions,
marks=pytest.mark.xfail(raises=AssertionError)
),
pytest.param(
active_caseworking_user,
marks=pytest.mark.xfail(raises=AssertionError)
),
])
@pytest.mark.parametrize('extra_service_permissions', [
pytest.param(
['edit_folders']
),
pytest.param(
[],
marks=pytest.mark.xfail(raises=AssertionError)
),
])
def test_should_show_checkboxes_for_selecting_templates(
client_request,
mocker,
service_one,
mock_get_service_templates,
mock_get_template_folders,
mock_has_no_jobs,
fake_uuid,
user,
extra_service_permissions,
):
service_one['permissions'] += extra_service_permissions
client_request.login(user(fake_uuid))
page = client_request.get(
'main.choose_template',
service_id=SERVICE_ONE_ID,
)
checkboxes = page.select('input[name=templates_and_folders]')
assert len(checkboxes) == 4
assert checkboxes[0]['value'] == TEMPLATE_ONE_ID
assert checkboxes[0]['id'] == 'templates-or-folder-{}'.format(TEMPLATE_ONE_ID)
for index in (1, 2, 3):
assert checkboxes[index]['value'] != TEMPLATE_ONE_ID
assert TEMPLATE_ONE_ID not in checkboxes[index]['id']
@pytest.mark.parametrize('user', [
pytest.param(
active_user_with_permissions
),
pytest.param(
active_user_view_permissions,
marks=pytest.mark.xfail(raises=AssertionError)
),
pytest.param(
active_caseworking_user,
marks=pytest.mark.xfail(raises=AssertionError)
),
])
@pytest.mark.parametrize('extra_service_permissions', [
pytest.param(
['edit_folders']
),
pytest.param(
[],
marks=pytest.mark.xfail(raises=AssertionError)
),
])
@pytest.mark.parametrize('folder_id, expected_destinations', [
(None, []),
(fake_uuid(), []),
])
def test_should_show_radio_buttons_for_move_destination(
client_request,
mocker,
service_one,
mock_get_service_templates,
mock_get_template_folders,
mock_has_no_jobs,
fake_uuid,
user,
extra_service_permissions,
folder_id,
expected_destinations,
):
service_one['permissions'] += extra_service_permissions
client_request.login(user(fake_uuid))
FOLDER_TWO_ID = str(uuid.uuid4())
FOLDER_ONE_TWO_ID = str(uuid.uuid4())
mock_get_template_folders.return_value = [
{'id': PARENT_FOLDER_ID, 'name': 'folder_one', 'parent_id': None},
{'id': FOLDER_TWO_ID, 'name': 'folder_two', 'parent_id': None},
{'id': CHILD_FOLDER_ID, 'name': 'folder_one_one', 'parent_id': PARENT_FOLDER_ID},
{'id': FOLDER_ONE_TWO_ID, 'name': 'folder_one_two', 'parent_id': PARENT_FOLDER_ID},
]
page = client_request.get(
'main.choose_template',
service_id=SERVICE_ONE_ID,
)
radios = page.select('input[type=radio]')
labels = page.select('label[for^=move_to]')
assert radios == page.select('input[name=move_to]')
assert [x['value'] for x in radios] == [
PARENT_FOLDER_ID, CHILD_FOLDER_ID, FOLDER_ONE_TWO_ID, FOLDER_TWO_ID,
]
assert [x.text.strip() for x in labels] == [
'folder_one', 'folder_one_one', 'folder_one_two', 'folder_two',
]
assert page.select_one('button[name=operation]')['value'] == 'move'
@pytest.mark.parametrize('user', [
pytest.param(
active_user_with_permissions
),
pytest.param(
active_user_view_permissions,
marks=pytest.mark.xfail(raises=AssertionError)
),
pytest.param(
active_caseworking_user,
marks=pytest.mark.xfail(raises=AssertionError)
),
])
@pytest.mark.parametrize('extra_service_permissions', [
pytest.param(
['edit_folders']
),
pytest.param(
[],
marks=pytest.mark.xfail(raises=AssertionError)
),
])
@pytest.mark.parametrize('folder_id, expected_destinations', [
(None, []),
(fake_uuid(), []),
])
def test_should_post_move_to_api(
client_request,
service_one,
fake_uuid,
mock_get_service_templates,
mock_get_template_folders,
mock_move_to_template_folder,
user,
extra_service_permissions,
folder_id,
expected_destinations,
):
service_one['permissions'] += extra_service_permissions
client_request.login(user(fake_uuid))
FOLDER_TWO_ID = str(uuid.uuid4())
mock_get_template_folders.return_value = [
{'id': PARENT_FOLDER_ID, 'name': 'folder_one', 'parent_id': None},
{'id': FOLDER_TWO_ID, 'name': 'folder_two', 'parent_id': None},
]
client_request.post(
'main.choose_template',
service_id=SERVICE_ONE_ID,
_data={
'operation': 'move',
'move_to': PARENT_FOLDER_ID,
'templates_and_folders': [
FOLDER_TWO_ID,
TEMPLATE_ONE_ID,
],
},
_expected_status=302,
_expected_redirect=url_for(
'main.choose_template',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
mock_move_to_template_folder.assert_called_once_with(
service_id=SERVICE_ONE_ID,
folder_id=PARENT_FOLDER_ID,
folder_ids={FOLDER_TWO_ID},
template_ids={TEMPLATE_ONE_ID},
)
def test_should_be_able_to_move_a_sub_item(
client_request,
service_one,
fake_uuid,
mock_get_service_templates,
mock_get_template_folders,
mock_move_to_template_folder,
):
service_one['permissions'] += ['edit_folders']
GRANDCHILD_FOLDER_ID = str(uuid.uuid4())
mock_get_template_folders.return_value = [
{'id': PARENT_FOLDER_ID, 'name': 'folder_one', 'parent_id': None},
{'id': CHILD_FOLDER_ID, 'name': 'folder_one_one', 'parent_id': PARENT_FOLDER_ID},
{'id': GRANDCHILD_FOLDER_ID, 'name': 'folder_one_one_one', 'parent_id': CHILD_FOLDER_ID},
]
client_request.post(
'main.choose_template',
service_id=SERVICE_ONE_ID,
template_folder_id=PARENT_FOLDER_ID,
_data={
'operation': 'move',
'move_to': 'None',
'templates_and_folders': [GRANDCHILD_FOLDER_ID],
},
_expected_status=302,
)
mock_move_to_template_folder.assert_called_once_with(
service_id=SERVICE_ONE_ID,
folder_id=None,
folder_ids={GRANDCHILD_FOLDER_ID},
template_ids=set(),
)
@pytest.mark.parametrize('thing_to_move', [
PARENT_FOLDER_ID, # Cant move a folder inside itself
CHILD_FOLDER_ID, # Cant move a folder which doesnt belong to the service
])
def test_should_validate_illegal_moves(
client_request,
service_one,
fake_uuid,
mock_get_service_templates,
mock_get_template_folders,
mock_move_to_template_folder,
thing_to_move,
):
service_one['permissions'] += 'edit_folders'
FOLDER_TWO_ID = str(uuid.uuid4())
mock_get_template_folders.return_value = [
{'id': PARENT_FOLDER_ID, 'name': 'folder_one', 'parent_id': None},
{'id': FOLDER_TWO_ID, 'name': 'folder_two', 'parent_id': None},
]
client_request.post(
'main.choose_template',
service_id=SERVICE_ONE_ID,
_data={
'operation': 'move',
'move_to': PARENT_FOLDER_ID,
'templates_and_folders': [
thing_to_move,
],
},
_expected_status=200,
_expected_redirect=None,
)
assert mock_move_to_template_folder.called is False
def test_should_not_show_template_nav_if_only_one_type_of_template(
client_request,
mock_get_template_folders,