コード例 #1
0
def test_deletes_previous_temp_logo_after_uploading_logo(
        logged_in_platform_admin_client, mocker, fake_uuid):
    with logged_in_platform_admin_client.session_transaction() as session:
        user_id = session["user_id"]

    temp_old_filename = LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=user_id),
        unique_id=fake_uuid,
        filename='old_test.png')
    temp_filename = LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=user_id),
        unique_id=fake_uuid,
        filename='test.png')

    mocked_upload_logo = mocker.patch(
        'app.main.views.organisations.upload_logo', return_value=temp_filename)
    mocked_delete_temp_file = mocker.patch(
        'app.main.views.organisations.delete_temp_file')

    logged_in_platform_admin_client.post(
        url_for('.manage_org', logo=temp_old_filename),
        data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
        content_type='multipart/form-data')

    assert mocked_upload_logo.called
    assert mocked_delete_temp_file.called
    assert mocked_delete_temp_file.call_args == call(temp_old_filename)
コード例 #2
0
ファイル: test_email_branding.py プロジェクト: trodjr/notify
def test_create_new_email_branding_when_branding_saved(
        logged_in_platform_admin_client, mocker, mock_create_email_branding,
        fake_uuid):
    with logged_in_platform_admin_client.session_transaction() as session:
        user_id = session["user_id"]

    data = {'logo': 'test.png', 'colour': '#ff0000', 'name': 'new name'}

    temp_filename = LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=user_id),
        unique_id=fake_uuid,
        filename=data['logo'])

    mocker.patch('app.main.views.email_branding.persist_logo',
                 return_value=data['logo'])
    mocker.patch('app.main.views.email_branding.delete_temp_files_created_by')

    logged_in_platform_admin_client.post(url_for('.create_email_branding',
                                                 logo=temp_filename),
                                         content_type='multipart/form-data',
                                         data={
                                             'colour':
                                             data['colour'],
                                             'name':
                                             data['name'],
                                             'cdn_url':
                                             'https://static-logos.cdn.com'
                                         })

    assert mock_create_email_branding.called
    assert mock_create_email_branding.call_args == call(logo=data['logo'],
                                                        name=data['name'],
                                                        colour=data['colour'])
コード例 #3
0
ファイル: test_email_branding.py プロジェクト: trodjr/notify
def test_logo_persisted_when_organisation_saved(
        logged_in_platform_admin_client, mocker, fake_uuid):
    with logged_in_platform_admin_client.session_transaction() as session:
        user_id = session["user_id"]

    temp_filename = LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=user_id),
        unique_id=fake_uuid,
        filename='test.png')

    mocked_upload_logo = mocker.patch(
        'app.main.views.email_branding.upload_logo')
    mocked_persist_logo = mocker.patch(
        'app.main.views.email_branding.persist_logo', return_value='test.png')
    mocked_delete_temp_files_by = mocker.patch(
        'app.main.views.email_branding.delete_temp_files_created_by')

    logged_in_platform_admin_client.post(url_for('.create_email_branding',
                                                 logo=temp_filename),
                                         content_type='multipart/form-data')

    assert not mocked_upload_logo.called
    assert mocked_persist_logo.called
    assert mocked_delete_temp_files_by.called
    assert mocked_delete_temp_files_by.call_args == call(user_id)
コード例 #4
0
ファイル: test_email_branding.py プロジェクト: trodjr/notify
def test_temp_logo_is_shown_after_uploading_logo(
    logged_in_platform_admin_client,
    mocker,
    fake_uuid,
):
    with logged_in_platform_admin_client.session_transaction() as session:
        user_id = session["user_id"]

    temp_filename = LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=user_id),
        unique_id=fake_uuid,
        filename='test.png')

    mocker.patch('app.main.views.email_branding.upload_logo',
                 return_value=temp_filename)
    mocker.patch('app.main.views.email_branding.delete_temp_file')

    response = logged_in_platform_admin_client.post(
        url_for('main.create_email_branding'),
        data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
        content_type='multipart/form-data',
        follow_redirects=True)

    assert response.status_code == 200

    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')

    assert page.select_one('#logo-img > img').attrs['src'].endswith(
        temp_filename)
コード例 #5
0
def test_existing_organisation_updated_when_organisation_saved(
        logged_in_platform_admin_client, mocker, fake_uuid):
    with logged_in_platform_admin_client.session_transaction() as session:
        session["organisation"] = sample_orgs[0]
        user_id = session["user_id"]

    update_org = {'logo': 'test.png', 'colour': 'blue', 'name': 'new name'}

    temp_filename = LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=user_id),
        unique_id=fake_uuid,
        filename=update_org['logo'])

    mocked_update_org = mocker.patch(
        'app.organisations_client.update_organisation')
    mocker.patch('app.main.views.organisations.persist_logo',
                 return_value=update_org['logo'])
    mocker.patch('app.main.views.organisations.delete_temp_files_created_by')

    logged_in_platform_admin_client.post(url_for('.manage_org',
                                                 logo=temp_filename),
                                         content_type='multipart/form-data',
                                         data={
                                             'colour':
                                             update_org['colour'],
                                             'name':
                                             update_org['name'],
                                             'cdn_url':
                                             'https://static-logos.cdn.com'
                                         })

    assert mocked_update_org.called
    assert mocked_update_org.call_args == call(org_id=sample_orgs[0]['id'],
                                               logo=update_org['logo'],
                                               name=update_org['name'],
                                               colour=update_org['colour'])
コード例 #6
0
def request_post_manage_org_redirect(logged_in_platform_admin_client, mocker,
                                     fake_uuid):
    with logged_in_platform_admin_client.session_transaction() as session:
        user_id = session["user_id"]

    temp_filename = LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=user_id),
        unique_id=fake_uuid,
        filename='test.png')

    mocker.patch('app.main.views.organisations.upload_logo',
                 return_value=temp_filename)
    mocker.patch('app.main.views.organisations.delete_temp_file')
    mocker.patch('app.main.views.organisations.delete_temp_files_created_by')

    response = logged_in_platform_admin_client.post(
        url_for('.manage_org'),
        data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
        content_type='multipart/form-data',
        follow_redirects=True)

    assert response.status_code == 200
    return BeautifulSoup(response.data.decode('utf-8'),
                         'html.parser'), temp_filename
コード例 #7
0
ファイル: test_s3_client.py プロジェクト: trodjr/notify
def upload_filename(fake_uuid):
    return LOGO_LOCATION_STRUCTURE.format(
        temp=TEMP_TAG.format(user_id=fake_uuid), unique_id=upload_id, filename=filename)