def test_upload_logo_calls_correct_args(client, mocker, fake_uuid, upload_filename): mocker.patch('uuid.uuid4', return_value=upload_id) mocker.patch.dict('flask.current_app.config', {'LOGO_UPLOAD_BUCKET_NAME': bucket}) mocked_s3_upload = mocker.patch('app.main.s3_client.utils_s3upload') upload_logo(filename=filename, user_id=fake_uuid, filedata=data, region=region) assert mocked_s3_upload.called_once_with( filedata=data, region=region, file_location=upload_filename, bucket_name=bucket )
def create_email_branding(logo=None): form = ServiceCreateEmailBranding() if form.validate_on_submit(): if form.file.data: upload_filename = upload_logo(form.file.data.filename, form.file.data, current_app.config['AWS_REGION'], user_id=session["user_id"]) if logo and logo.startswith( TEMP_TAG.format(user_id=session['user_id'])): delete_temp_file(logo) return redirect( url_for('.create_email_branding', logo=upload_filename)) if logo: logo = persist_logo(logo, session["user_id"]) delete_temp_files_created_by(session["user_id"]) email_branding_client.create_email_branding(logo=logo, name=form.name.data, colour=form.colour.data) return redirect(url_for('.email_branding')) return render_template('views/email-branding/manage-branding.html', form=form, cdn_url=get_cdn_domain(), logo=logo)
def manage_org(logo=None): form = ServiceManageOrg() org = session.get("organisation") logo = logo if logo else org.get('logo') if org else None if form.validate_on_submit(): if form.file.data: upload_filename = upload_logo( form.file.data.filename, form.file.data, current_app.config['AWS_REGION'], user_id=session["user_id"] ) if logo and logo.startswith(TEMP_TAG.format(user_id=session['user_id'])): delete_temp_file(logo) return redirect( url_for('.manage_org', logo=upload_filename)) if logo: logo = persist_logo(logo, session["user_id"]) delete_temp_files_created_by(session["user_id"]) if org: organisations_client.update_organisation( org_id=org['id'], logo=logo, name=form.name.data, colour=form.colour.data) org_id = org['id'] else: resp = organisations_client.create_organisation( logo=logo, name=form.name.data, colour=form.colour.data) org_id = resp['data']['id'] return redirect(url_for('.organisations', organisation_id=org_id)) if org: form.name.data = org['name'] form.colour.data = org['colour'] return render_template( 'views/organisations/manage-org.html', form=form, organisation=org, cdn_url=get_cdn_domain(), logo=logo )
def update_email_branding(branding_id, logo=None): email_branding = email_branding_client.get_email_branding(branding_id)['email_branding'] form = ServiceUpdateEmailBranding() logo = logo if logo else email_branding.get('logo') if email_branding else None if form.validate_on_submit(): if form.file.data: upload_filename = upload_logo( form.file.data.filename, form.file.data, current_app.config['AWS_REGION'], user_id=session["user_id"] ) if logo and logo.startswith(TEMP_TAG.format(user_id=session['user_id'])): delete_temp_file(logo) return redirect(url_for('.update_email_branding', branding_id=branding_id, logo=upload_filename)) if logo: logo = persist_logo(logo, session["user_id"]) delete_temp_files_created_by(session["user_id"]) email_branding_client.update_email_branding( branding_id=branding_id, logo=logo, name=form.name.data, text=form.text.data, colour=form.colour.data ) return redirect(url_for('.email_branding', branding_id=branding_id)) form.name.data = email_branding['name'] form.text.data = email_branding['text'] form.colour.data = email_branding['colour'] return render_template( 'views/email-branding/manage-branding.html', form=form, email_branding=email_branding, cdn_url=get_cdn_domain(), logo=logo )