def main(job_id, session): job = session.query(Job).get(job_id) if not job: die("Job ({}) does not exist.".format(job_id)) print isinstance(job.title, unicode) print "You're reviewing the following listing:" print make_summary(job).encode('utf-8') action = 'publish' if not job.published else 'unpublish' if prompt("Do you want to {} this listing?".format(blue(action)), yesno=True): job.published = not job.published session.commit() print green('Job {}ed!'.format(action)) if action == 'unpublish': return if prompt(blue('Do you want to send a confirmation email?'), yesno=True): send_confirmation_email(job) print green('Confirmation email sent!') else: die('Bye.')
def test_send_confirmation_email(app, monkeypatch, job): mock = MagicMock() monkeypatch.setattr('jobber.functions.send_email_template', mock) context = {'job': job, 'default_sender': DEFAULT_SENDER} recipient = [job.recruiter_email] send_confirmation_email(job) mock.assert_called_with('confirmation', context, recipient)
def reviewed_via_email(token): """Returns a 200 if the review was successful, otherwise returns a 406 as per Mailgun's documentation: http://documentation.mailgun.com/user_manual.html#routes """ sender = request.form['sender'] reply = request.form['stripped-text'].strip() logger.info("Received email review request with token {} and reply '{}'." .format(token, reply)) if sender not in settings.EMAIL_REVIEWERS: logger.info("Unauthorized email reviewer with email '{}' and token {}!" .format(sender, token)) abort(406) if reply != 'ok': logger.info("Bad reply, aborting review.") abort(406) token_model = db.session.query(EmailReviewToken).filter_by(token=token).first() if not token_model: logger.info("Unknown token {}, aborting review." .format(token)) abort(406) if token_model.used: logger.info("Token {} is already used, aborting review." .format(token)) abort(406) token_model.use() job = token_model.job was_published = False if not job.published: job.published = True was_published = True db.session.commit() # To avoid any race conditions between manually reviewing and reviewing via # email, we make a last check before sending the email. if was_published: send_confirmation_email(job) logger.info("Reviewed job ({}) via email with token {}." .format(job.id, token)) return 'okay', 200
def test_send_confirmation_email(app, monkeypatch, job): mock = MagicMock() monkeypatch.setattr('jobber.functions.send_email_template', mock) context = { 'job': job, 'default_sender': DEFAULT_SENDER } recipient = [job.recruiter_email] send_confirmation_email(job) mock.assert_called_with('confirmation', context, recipient)