Exemple #1
0
def pop_questionemailjobs():
    jobs = sorted(QuestionEmailJob.iterReady(),
                  key=lambda job: job.metadata["recipient_set"])
    for job in jobs:
        job.start()
        job.complete()
    return jobs
def pop_questionemailjobs():
    jobs = sorted(
        QuestionEmailJob.iterReady(),
        key=lambda job: job.metadata["recipient_set"])
    for job in jobs:
        job.start()
        job.complete()
    return jobs
Exemple #3
0
 def test_headers(self):
     # The headers property matches the headers passed to create().
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(question, user,
                                   QuestionRecipientSet.SUBSCRIBER, subject,
                                   body, headers)
     self.assertEqual(headers, job.headers)
 def test_headers(self):
     # The headers property matches the headers passed to create().
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(
         question, user, QuestionRecipientSet.SUBSCRIBER,
         subject, body, headers)
     self.assertEqual(headers, job.headers)
Exemple #5
0
 def test_getOopsVars(self):
     # The getOopsVars() method adds the question and user to the vars.
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(question, user,
                                   QuestionRecipientSet.SUBSCRIBER, subject,
                                   body, headers)
     oops_vars = job.getOopsVars()
     self.assertTrue(('question', question.id) in oops_vars)
     self.assertTrue(('user', user.name) in oops_vars)
Exemple #6
0
 def test_from_address(self):
     # The from_address is the question with the user displayname.
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(question, user,
                                   QuestionRecipientSet.SUBSCRIBER, subject,
                                   body, headers)
     address = format_address(
         user.displayname, "*****@*****.**" % question.id)
     self.assertEqual(address, job.from_address)
 def test_getOopsVars(self):
     # The getOopsVars() method adds the question and user to the vars.
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(
         question, user, QuestionRecipientSet.SUBSCRIBER,
         subject, body, headers)
     oops_vars = job.getOopsVars()
     self.assertTrue(('question', question.id) in oops_vars)
     self.assertTrue(('user', user.name) in oops_vars)
 def test_from_address(self):
     # The from_address is the question with the user displayname.
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(
         question, user, QuestionRecipientSet.SUBSCRIBER,
         subject, body, headers)
     address = format_address(
         user.displayname,
         "*****@*****.**" % question.id)
     self.assertEqual(address, job.from_address)
def make_question_job(factory, recipient_set=QuestionRecipientSet.SUBSCRIBER,
                      body=None, question=None, user=None):
    if question is None:
        question = factory.makeQuestion()
    default_user, subject, default_body, headers = (
        make_user_subject_body_headers(factory))
    if body is None:
        body = default_body
    if user is None:
        user = default_user
    contact = factory.makePerson()
    with person_logged_in(contact):
        lang_set = getUtility(ILanguageSet)
        contact.addLanguage(lang_set['en'])
        question.target.addAnswerContact(contact, contact)
    return QuestionEmailJob.create(
        question, user, recipient_set,
        subject, body, headers)
 def test_iterReady(self):
     # Jobs in the ready state are returned by the iterator.
     # Creating a question implicitly created an question email job.
     asker = self.factory.makePerson()
     product = self.factory.makeProduct()
     naked_question_set = removeSecurityProxy(getUtility(IQuestionSet))
     question = naked_question_set.new(
         title='title', description='description', owner=asker,
         language=getUtility(ILanguageSet)['en'],
         product=product, distribution=None, sourcepackagename=None)
     job_1 = make_question_job(self.factory, question=question, body='one')
     job_2 = make_question_job(self.factory, question=question, body='two')
     job_3 = make_question_job(
         self.factory, question=question, body='three')
     job_1.start()
     job_1.complete()
     job_ids = [job.id for job in QuestionEmailJob.iterReady()]
     self.assertContentEqual([job_2.id, job_3.id], job_ids)
Exemple #11
0
def make_question_job(factory,
                      recipient_set=QuestionRecipientSet.SUBSCRIBER,
                      body=None,
                      question=None,
                      user=None):
    if question is None:
        question = factory.makeQuestion()
    default_user, subject, default_body, headers = (
        make_user_subject_body_headers(factory))
    if body is None:
        body = default_body
    if user is None:
        user = default_user
    contact = factory.makePerson()
    with person_logged_in(contact):
        lang_set = getUtility(ILanguageSet)
        contact.addLanguage(lang_set['en'])
        question.target.addAnswerContact(contact, contact)
    return QuestionEmailJob.create(question, user, recipient_set, subject,
                                   body, headers)
Exemple #12
0
 def test_create(self):
     # The create class method converts the extra job arguments
     # to metadata.
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(question, user,
                                   QuestionRecipientSet.SUBSCRIBER, subject,
                                   body, headers)
     self.assertEqual(QuestionJobType.EMAIL, job.job_type)
     self.assertEqual(question, job.question)
     self.assertContentEqual(
         ['body', 'headers', 'recipient_set', 'subject', 'user'],
         job.metadata.keys())
     self.assertEqual(user.id, job.metadata['user'])
     self.assertEqual(QuestionRecipientSet.SUBSCRIBER.name,
                      job.metadata['recipient_set'])
     self.assertEqual(subject, job.metadata['subject'])
     self.assertEqual(body, job.metadata['body'])
     self.assertEqual(headers['X-Launchpad-Question'],
                      job.metadata['headers']['X-Launchpad-Question'])
     self.assertProvides(job, IQuestionEmailJob)
Exemple #13
0
 def test_iterReady(self):
     # Jobs in the ready state are returned by the iterator.
     # Creating a question implicitly created an question email job.
     asker = self.factory.makePerson()
     product = self.factory.makeProduct()
     naked_question_set = removeSecurityProxy(getUtility(IQuestionSet))
     question = naked_question_set.new(
         title='title',
         description='description',
         owner=asker,
         language=getUtility(ILanguageSet)['en'],
         product=product,
         distribution=None,
         sourcepackagename=None)
     job_1 = make_question_job(self.factory, question=question, body='one')
     job_2 = make_question_job(self.factory, question=question, body='two')
     job_3 = make_question_job(self.factory,
                               question=question,
                               body='three')
     job_1.start()
     job_1.complete()
     job_ids = [job.id for job in QuestionEmailJob.iterReady()]
     self.assertContentEqual([job_2.id, job_3.id], job_ids)
 def test_create(self):
     # The create class method converts the extra job arguments
     # to metadata.
     question = self.factory.makeQuestion()
     user, subject, body, headers = make_user_subject_body_headers(
         self.factory)
     job = QuestionEmailJob.create(
         question, user, QuestionRecipientSet.SUBSCRIBER,
         subject, body, headers)
     self.assertEqual(QuestionJobType.EMAIL, job.job_type)
     self.assertEqual(question, job.question)
     self.assertContentEqual(
         ['body', 'headers', 'recipient_set', 'subject', 'user'],
         job.metadata.keys())
     self.assertEqual(user.id, job.metadata['user'])
     self.assertEqual(
         QuestionRecipientSet.SUBSCRIBER.name,
         job.metadata['recipient_set'])
     self.assertEqual(subject, job.metadata['subject'])
     self.assertEqual(body, job.metadata['body'])
     self.assertEqual(
         headers['X-Launchpad-Question'],
         job.metadata['headers']['X-Launchpad-Question'])
     self.assertProvides(job, IQuestionEmailJob)