Ejemplo n.º 1
0
def test_should_redirect_when_deleting_a_template(
    logged_in_client,
    api_user_active,
    mock_login,
    mock_get_service,
    mock_get_service_template,
    mock_delete_service_template,
    mock_get_user,
    mock_get_user_by_email,
    mock_has_permissions,
    fake_uuid,
):
    service_id = fake_uuid
    template_id = fake_uuid
    name = "new name"
    type_ = "sms"
    content = "template content"
    data = {
        'id': str(template_id),
        'name': name,
        'template_type': type_,
        'content': content,
        'service': service_id
    }
    response = logged_in_client.post(url_for('.delete_service_template',
                                             service_id=service_id,
                                             template_id=template_id),
                                     data=data)

    assert response.status_code == 302
    assert response.location == url_for('.choose_template',
                                        service_id=service_id,
                                        _external=True)
    mock_get_service_template.assert_called_with(service_id, template_id)
    mock_delete_service_template.assert_called_with(service_id, template_id)
Ejemplo n.º 2
0
def test_should_show_delete_template_page_with_time_block_for_empty_notification(
    client_request,
    mock_get_service_template,
    mocker,
    fake_uuid
):
    with freeze_time('2012-01-08 12:00:00'):
        template = template_json('1234', '1234', "Test template", "sms", "Something very interesting")
        single_notification_json('1234', template=template)
        mocker.patch('app.template_statistics_client.get_template_statistics_for_template',
                     return_value=None)

    with freeze_time('2012-01-01 11:00:00'):
        page = client_request.get(
            '.delete_service_template',
            service_id=SERVICE_ONE_ID,
            template_id=fake_uuid,
            _test_page_title=False,
        )
    assert page.h1.text == 'Are you sure you want to delete Two week reminder?'
    assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
        'It was last used more than seven days ago'
    )
    assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
        'service one: Template <em>content</em> with & entity'
    )
    mock_get_service_template.assert_called_with(SERVICE_ONE_ID, fake_uuid)
Ejemplo n.º 3
0
def test_should_show_page_for_one_template(
    logged_in_client,
    mock_get_service_template,
    service_one,
    fake_uuid,
):
    template_id = fake_uuid
    response = logged_in_client.get(url_for(
        '.edit_service_template',
        service_id=service_one['id'],
        template_id=template_id))

    assert response.status_code == 200
    assert "Two week reminder" in response.get_data(as_text=True)
    assert "Template &lt;em&gt;content&lt;/em&gt; with &amp; entity" in response.get_data(as_text=True)
    assert "Use priority queue?" not in response.get_data(as_text=True)
    mock_get_service_template.assert_called_with(service_one['id'], template_id)
Ejemplo n.º 4
0
def test_should_show_page_template_with_priority_select_if_platform_admin(
    logged_in_platform_admin_client,
    platform_admin_user,
    mocker,
    mock_get_service_template,
    fake_uuid,
):
    mocker.patch('app.user_api_client.get_users_for_service', return_value=[platform_admin_user])
    template_id = fake_uuid
    response = logged_in_platform_admin_client.get(url_for(
        '.edit_service_template',
        service_id='1234',
        template_id=template_id))

    assert response.status_code == 200
    assert "Two week reminder" in response.get_data(as_text=True)
    assert "Template &lt;em&gt;content&lt;/em&gt; with &amp; entity" in response.get_data(as_text=True)
    assert "Use priority queue?" in response.get_data(as_text=True)
    mock_get_service_template.assert_called_with('1234', template_id)
Ejemplo n.º 5
0
def test_should_show_delete_template_page_with_never_used_block(
    client_request,
    mock_get_service_template,
    fake_uuid,
    mocker,
):
    mocker.patch(
        'app.template_statistics_client.get_template_statistics_for_template',
        side_effect=HTTPError(response=Mock(status_code=404),
                              message="Default message"))
    page = client_request.get(
        '.delete_service_template',
        service_id=SERVICE_ONE_ID,
        template_id=fake_uuid,
        _test_page_title=False,
    )
    assert page.h1.text == 'Are you sure you want to delete Two week reminder?'
    assert not page.select('.banner-dangerous p')
    assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
        'service one: Template <em>content</em> with & entity')
    mock_get_service_template.assert_called_with(SERVICE_ONE_ID, fake_uuid)