def test_adding_review_and_comment_to_proposal_in_database(database): """A reviewed proposal has a score and possible a comment added. Put a proposal with user and presenter into the database. Although this is not allowed in the application have the user score and comment on their proposal to show that this all works in the database. """ user = User(**user_data) proposal = Proposal(user, **proposal_data) presenter = Presenter(**presenter_data) ProposalPresenter(proposal, presenter, True) score = Score(proposal, user, 10) comment = Comment(proposal, user, 'Perfect') database.session.add(user) database.session.add(proposal) database.session.add(presenter) database.session.add(score) database.session.add(comment) database.session.commit() query_result = Proposal.query.filter_by(proposer=user).all() assert len(query_result) == 1 proposal = query_result[0] assert proposal.scores is not None assert len(proposal.scores) == 1 assert proposal.scores[0].score == 10 assert proposal.comments is not None assert len(proposal.comments) == 1 assert proposal.comments[0].comment == 'Perfect'
def test_putting_proposal_in_database(database, registrant, presenter_data, proposal_data): """Put a proposal item into the database. A proposal has to be submitted by a user so tehre must be a user. Proposals must also have at least one presenter, by default the user is the lead presenter. """ user = User(**registrant) proposal = Proposal(user, **proposal_data) presenter = Presenter(**presenter_data) ProposalPresenter(proposal, presenter, True) assert proposal.presenters[0] == presenter assert presenter.proposals[0] == proposal presenter.is_lead = True database.session.add(user) database.session.add(proposal) database.session.add(presenter) database.session.commit() query_result = Proposal.query.filter_by(proposer=user).all() assert len(query_result) == 1 proposal = query_result[0] assert proposal.proposer.email == user.email assert { 'title': proposal.title, 'session_type': proposal.session_type, 'summary': proposal.summary, 'notes': proposal.notes, 'audience': proposal.audience, } == proposal_data assert proposal.status == ProposalState.submitted assert len(proposal.presenters) == 1 proposal_presenter = proposal.presenters[0] is_lead = proposal_presenter.is_lead assert is_lead assert (proposal_presenter.email, proposal_presenter.name) == (user.email, user.name)
def insert_keynotes_from_files(): """Insert new keynote records from files in the keynote_directory directory.""" # The directory contains one directory per keynote with person's name as the name. # The directory contains three files: details.txt, bio.adoc, and blurb.adoc. # The file details.txt contains key: value pairs one on each line, with title, email and country. keynotes_directory = Path(__file__).parent.parent / 'keynotes_directory' if keynotes_directory.exists(): keynote_presenter_directories = os.listdir(keynotes_directory.as_posix()) if len(keynote_presenter_directories) != 4: click.echo(click.style('There are not four keynotes', fg='red')) else: user = User.query.filter_by(email='*****@*****.**').all() assert len(user) == 1 user = user[0] for directory in keynote_presenter_directories: with open(keynotes_directory / directory / 'bio.adoc') as f: bio = f.read().strip() with open(keynotes_directory / directory / 'blurb.adoc') as f: blurb = f.read().strip() assert bio assert blurb details = {} with open(keynotes_directory / directory / 'details.txt') as f: for line in f.read().strip().splitlines(): key, value = [x.strip() for x in line.split(':')] assert key assert value details[key] = value assert 'title' in details assert 'email' in details assert 'country' in details proposal = Proposal(user, details['title'], blurb, SessionType.keynote, status=ProposalState.acknowledged) # Protect against the case that the keynote has submitted a proposal. presenter = Presenter.query.filter_by(email=details['email']).all() if presenter: assert len(presenter) == 1 presenter = presenter[0] else: presenter = Presenter(details['email'], directory.replace('_', ' '), bio, details['country']) proposal_presenter = ProposalPresenter(proposal, presenter, True) db.session.add(proposal) db.session.add(presenter) db.session.add(proposal_presenter) db.session.commit() else: click.echo(click.style('Cannot find the keynotes_data directory', fg='red'))
def add_a_proposal_as_user(user_email, proposal_data): """Given a user email and a dictionary of details about a proposal add the proposal to the database.""" user = User.query.filter_by(email=user_email).first() proposal = Proposal( user, proposal_data['title'], proposal_data['summary'], proposal_data['session_type'], ) db.session.add(proposal) for presenter_data in proposal_data['presenters']: presenter = Presenter( presenter_data['email'], presenter_data['name'], presenter_data['bio'], presenter_data['country'], ) db.session.add(presenter) ProposalPresenter(proposal, presenter, presenter_data['is_lead']) db.session.commit()
def submit(): check = is_acceptable_route() if not check[0]: return check[1] assert check[1] is None if is_logged_in(): if request.method == 'POST': user = User.query.filter_by(email=session['email']).first() if user: proposal_data = request.json status, message = validate_proposal_data(proposal_data) if not status: # NB This should never be executed. response = jsonify(message) response.status_code = 400 return response proposal = Proposal( user, proposal_data.get('title').strip(), proposal_data.get('summary').strip(), SessionType(proposal_data.get('session_type').strip()), SessionAudience(proposal_data.get('audience').strip()) if proposal_data.get('audience') else SessionAudience.all, proposal_data.get('keywords').strip() if proposal_data.get('keywords') else '', proposal_data.get('no_video') if proposal_data.get('no_video') else False, proposal_data.get('notes').strip() if proposal_data.get('notes') else '', proposal_data.get('constraints').strip() if proposal_data.get('constraints') else '', ) db.session.add(proposal) presenters_data = proposal_data.get('presenters') for presenter_data in presenters_data: presenter = Presenter.query.filter_by(email=presenter_data['email']).all() if presenter: assert len(presenter) == 1 presenter = presenter[0] if presenter.name != presenter_data['name']: presenter.name = presenter_data['name'] if presenter.bio != presenter_data['bio']: presenter.bio = presenter_data['bio'] if presenter.country != presenter_data['country']: presenter.country = presenter_data['country'] else: presenter = Presenter( presenter_data['email'], presenter_data['name'], presenter_data['bio'], presenter_data['country'], ) db.session.add(presenter) ProposalPresenter(proposal, presenter, presenter_data['is_lead']) db.session.commit() session['just_submitted'] = True return jsonify('submit_success') return render_template('general.html', page=md(base_page, { 'pagetitle': 'Submit POST Error', 'data': 'The logged in user is not in database. This cannot happen.', })) user = User.query.filter_by(email=session['email']).first() if user: presenter = Presenter.query.filter_by(email=user.email).all() if presenter: assert len(presenter) == 1 presenter = presenter[0] (p_email, p_name, p_bio, p_country) = (presenter.email, presenter.name, presenter.bio, presenter.country) else: (p_email, p_name, p_bio, p_country) = (user.email, user.name, '', user.country) return render_template('submit.html', page=md(base_page, { 'pagetitle': 'Submit a proposal', 'data': Markup(submit_form_preface_markup), 'title': '', 'session_type': SessionType.session.value, 'summary': '', 'audience': SessionAudience.all.value, 'keywords': '', 'no_video': False, 'notes': '', 'constraints': '', 'presenter': { 'email': p_email, 'name': p_name, 'is_lead': True, 'bio': p_bio, 'country': p_country, }, 'countries': sorted(countries), 'submit_label': 'Submit', })) return render_template('general.html', page=md(base_page, { 'pagetitle': 'Submission Problem', 'data': 'The logged in user is not in database. This cannot happen.', })) return render_template('general.html', page=md(base_page, { 'pagetitle': 'Submit Not Possible', 'data': 'You must be registered and logged in to submit a proposal.' }))
def submit(): check = is_acceptable_route() if not check[0]: return check[1] assert check[1] is None page = { 'title': 'Submit', 'year': year, } if is_logged_in(): if request.method == 'POST': user = User.query.filter_by(email=session['email']).first() if user: proposal_data = request.json status, message = validate_proposal_data(proposal_data) response = {} if status: proposal = Proposal( user, proposal_data.get('title').strip(), SessionType(proposal_data.get('session_type')), proposal_data.get('abstract').strip()) db.session.add(proposal) presenters_data = proposal_data.get('presenters') for presenter_data in presenters_data: presenter = Presenter( presenter_data['email'], presenter_data['name'], 'A human being.', presenter_data['country'], presenter_data['state'], ) ProposalPresenter(proposal, presenter, presenter_data['lead']) db.session.add(presenter) db.session.commit() response['success'] = True response[ 'message'] = '''Thank you, you have successfully submitted a proposal for the ACCU {} conference! If you need to edit it you can via the 'My Proposal' menu item.'''.format(year) response['redirect'] = '/' else: response['success'] = False response['message'] = message return jsonify(**response) else: user = User.query.filter_by(email=session['email']).first() if user: return render_template( 'submit.html', page={ 'title': 'Submit a proposal for ACCU {}'.format(year), 'name': user.name, 'proposer': { 'email': user.email, 'name': user.name, 'bio': 'A human being.', 'country': user.country, 'state': user.state, } }) return render_template( 'failure.html', page=md(page, {'data': 'Must be logged in to submit a proposal.'}))