示例#1
0
 def test_notify_comment_followers(self):
     # send a couple of comments to the article with followup=True and check
     # that when the second comment is confirmed a followup notification 
     # email is sent to the user who sent the first comment
     self.assertEqual(len(mail.outbox), 1)
     self.get_confirm_comment_url(self.key)
     self.assertEqual(len(mail.outbox), 1) # no comment followers yet
     # send 2nd comment
     self.form = comments.get_form()(self.article)
     data = {"name":"Alice", "email":"*****@*****.**", "followup": True, 
             "reply_to": 0, "level": 1, "order": 1,
             "comment":"Es war einmal iene kleine..." }
     data.update(self.form.initial)
     self.response = self.client.post(reverse("comments-post-comment"), 
                                     data=data)
     if mail_sent_queue.get(block=True):
         pass
     self.assertEqual(len(mail.outbox), 2)
     self.key = re.search(r'http://.+/confirm/(?P<key>[\S]+)', 
                          mail.outbox[1].body).group("key")
     self.get_confirm_comment_url(self.key)
     if mail_sent_queue.get(block=True):
         pass
     self.assertEqual(len(mail.outbox), 3)
     self.assert_(mail.outbox[2].to == ["*****@*****.**"])
     self.assert_(mail.outbox[2].body.find("There is a new comment following up yours.") > -1)
示例#2
0
 def test_notify_comment_followers(self):
     # send a couple of comments to the article with followup=True and check
     # that when the second comment is confirmed a followup notification
     # email is sent to the user who sent the first comment
     self.assertEqual(len(mail.outbox), 1)
     self.get_confirm_comment_url(self.key)
     self.assertEqual(len(mail.outbox), 1)  # no comment followers yet
     # send 2nd comment
     self.form = comments.get_form()(self.article)
     data = {
         "name": "Alice",
         "email": "*****@*****.**",
         "followup": True,
         "reply_to": 0,
         "level": 1,
         "order": 1,
         "comment": "Es war einmal iene kleine..."
     }
     data.update(self.form.initial)
     self.response = self.client.post(reverse("comments-post-comment"),
                                      data=data)
     if mail_sent_queue.get(block=True):
         pass
     self.assertEqual(len(mail.outbox), 2)
     self.key = re.search(r'http://.+/confirm/(?P<key>[\S]+)',
                          mail.outbox[1].body).group("key")
     self.get_confirm_comment_url(self.key)
     if mail_sent_queue.get(block=True):
         pass
     self.assertEqual(len(mail.outbox), 3)
     self.assert_(mail.outbox[2].to == ["*****@*****.**"])
     self.assert_(mail.outbox[2].body.find(
         "There is a new comment following up yours.") > -1)
示例#3
0
    def test_job_review(self):
        # FIXME: refactor to separate tests cases for clarity?
        mail.outbox = []
        url = reverse('jobs:job_review')

        response = self.client.get(url)
        self.assertEqual(response.status_code, 302)

        self.client.login(username=self.super_username, password=self.super_password)

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['object_list']), 3)
        self.assertIn(self.job1, response.context['object_list'])
        self.assertIn(self.job2, response.context['object_list'])
        self.assertIn(self.job3, response.context['object_list'])

        # no email notifications sent before offer is approved
        self.assertEqual(len(mail.outbox), 0)
        self.client.post(url, data={'job_id': self.job1.pk, 'action': 'approve'})
        j1 = Job.objects.get(pk=self.job1.pk)
        self.assertEqual(j1.status, Job.STATUS_APPROVED)
        # exactly one approval notification email should sent
        # to the offer creator
        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertEqual(message.to, [self.creator.email, '*****@*****.**'])
        self.assertIn(self.contact, message.body)
        mail.outbox = []

        # no email notifications sent before offer is rejected
        self.assertEqual(len(mail.outbox), 0)
        self.client.post(url, data={'job_id': self.job2.pk, 'action': 'reject'})
        j2 = Job.objects.get(pk=self.job2.pk)
        self.assertEqual(j2.status, Job.STATUS_REJECTED)
        # exactly one rejection notification email should sent
        # to the offer creator
        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertEqual(message.to, [self.creator.email, '*****@*****.**'])
        self.assertIn(self.contact, message.body)
        mail.outbox = []

        self.client.post(url, data={'job_id': self.job3.pk, 'action': 'remove'})
        j3 = Job.objects.get(pk=self.job3.pk)
        self.assertEqual(j3.status, Job.STATUS_REMOVED)

        response = self.client.post(url, data={'job_id': 999999, 'action': 'approve'})
        self.assertEqual(response.status_code, 302)
示例#4
0
    def test_job_review(self):
        # FIXME: refactor to separate tests cases for clarity?
        mail.outbox = []
        url = reverse('jobs:job_review')

        response = self.client.get(url)
        self.assertEqual(response.status_code, 302)

        self.client.login(username=self.super_username, password=self.super_password)

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['object_list']), 3)
        self.assertTrue(self.job1 in response.context['object_list'])
        self.assertTrue(self.job2 in response.context['object_list'])
        self.assertTrue(self.job3 in response.context['object_list'])

        # no email notifications sent before offer is approved
        self.assertEqual(len(mail.outbox), 0)
        self.client.post(url, data={'job_id': self.job1.pk, 'action': 'approve'})
        j1 = Job.objects.get(pk=self.job1.pk)
        self.assertEqual(j1.status, Job.STATUS_APPROVED)
        # exactly one approval notification email should sent
        # to the offer creator
        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertEqual(message.to, [self.creator.email])
        self.assertTrue(self.contact in message.body)
        mail.outbox = []

        # no email notifications sent before offer is rejected
        self.assertEqual(len(mail.outbox), 0)
        self.client.post(url, data={'job_id': self.job2.pk, 'action': 'reject'})
        j2 = Job.objects.get(pk=self.job2.pk)
        self.assertEqual(j2.status, Job.STATUS_REJECTED)
        # exactly one rejection notification email should sent
        # to the offer creator
        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]
        self.assertEqual(message.to, [self.creator.email])
        self.assertTrue(self.contact in message.body)
        mail.outbox = []

        self.client.post(url, data={'job_id': self.job3.pk, 'action': 'remove'})
        j3 = Job.objects.get(pk=self.job3.pk)
        self.assertEqual(j3.status, Job.STATUS_REMOVED)

        response = self.client.post(url, data={'job_id': 999999, 'action': 'approve'})
        self.assertEqual(response.status_code, 302)
示例#5
0
    def test_job_comment(self):
        mail.outbox = []
        self.client.login(username=self.super_username,
                          password=self.super_password)

        form = comments.get_form()(self.job1)
        url = reverse('comments-post-comment')

        form_data = {
            'name': 'Reviewer',
            'email': self.superuser.email,
            'url': 'http://example.com',
            'comment': 'Lorem ispum',
            'reply_to': 0,
            'post': 'Post'
        }
        form_data.update(form.initial)

        self.assertEqual(len(mail.outbox), 0)
        response = self.client.post(url, form_data)
        self.assertEqual(response.status_code, 302)
        self.assertIn('http://testserver/comments/posted/?c=',
                      response['Location'])

        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 1)

        self.assertEqual(mail.outbox[0].to,
                         [self.creator.email, '*****@*****.**'])

        form = comments.get_form()(self.job1)
        form_data = {
            'name': 'creator',
            'email': self.creator.email,
            'url': 'http://example.com',
            'comment': 'Lorem ispum',
            'reply_to': 0,
            'post': 'Post'
        }
        form_data.update(form.initial)
        response = self.client.post(url, form_data)
        self.assertEqual(response.status_code, 302)
        self.assertIn('http://testserver/comments/posted/?c=',
                      response['Location'])

        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 3)
        self.assertEqual(mail.outbox[1].to,
                         [self.creator.email, '*****@*****.**'])
        self.assertEqual(mail.outbox[2].to, [self.superuser.email])
示例#6
0
 def post_valid_data(self, wait_mail=True):
     data = {"name":"Bob", "email":"*****@*****.**", "followup": True, 
             "comment":"Es war einmal iene kleine..."}
     data.update(self.form.initial)
     self.response = self.client.post(reverse("comments-post-comment"), 
                                     data=data, follow=True)
     if wait_mail and mail_sent_queue.get(block=True):
         pass
示例#7
0
    def test_job_comment(self):
        mail.outbox = []
        self.client.login(username=self.super_username, password=self.super_password)

        form = comments.get_form()(self.job1)
        url = reverse('comments-post-comment')

        form_data = {
            'name': 'Reviewer',
            'email': self.superuser.email,
            'url': 'http://example.com',
            'comment': 'Lorem ispum',
            'reply_to': 0,
            'post': 'Post'
        }
        form_data.update(form.initial)

        self.assertEqual(len(mail.outbox), 0)
        response = self.client.post(url, form_data)
        self.assertEqual(response.status_code, 302)
        self.assertIn('http://testserver/comments/posted/?c=', response['Location'])

        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 1)

        self.assertEqual(mail.outbox[0].to, [self.creator.email, '*****@*****.**'])

        form = comments.get_form()(self.job1)
        form_data = {
            'name': 'creator',
            'email': self.creator.email,
            'url': 'http://example.com',
            'comment': 'Lorem ispum',
            'reply_to': 0,
            'post': 'Post'
        }
        form_data.update(form.initial)
        response = self.client.post(url, form_data)
        self.assertEqual(response.status_code, 302)
        self.assertIn('http://testserver/comments/posted/?c=', response['Location'])

        mail_sent_queue.get(block=True)
        self.assertEqual(len(mail.outbox), 3)
        self.assertEqual(mail.outbox[1].to, [self.creator.email, '*****@*****.**'])
        self.assertEqual(mail.outbox[2].to, [self.superuser.email])
示例#8
0
 def setUp(self):
     self.article = Article.objects.create(title="September", 
                                           slug="september",
                                           body="What I did on September...")
     self.form = comments.get_form()(self.article)
     data = {"name":"Bob", "email":"*****@*****.**", "followup": True, 
             "comment":"Es war einmal iene kleine..." }
     data.update(self.form.initial)
     self.response = self.client.post(reverse("comments-post-comment"), 
                                     data=data)
     if mail_sent_queue.get(block=True):
         pass
     self.key = re.search(r'http://.+/confirm/(?P<key>[\S]+)', 
                          mail.outbox[0].body).group("key")
示例#9
0
 def post_valid_data(self, wait_mail=True):
     data = {
         "name": "Bob",
         "email": "*****@*****.**",
         "followup": True,
         "reply_to": 0,
         "level": 1,
         "order": 1,
         "comment": "Es war einmal iene kleine..."
     }
     data.update(self.form.initial)
     self.response = self.client.post(reverse("comments-post-comment"),
                                      data=data,
                                      follow=True)
     if wait_mail and mail_sent_queue.get(block=True):
         pass
示例#10
0
 def setUp(self):
     self.article = Article.objects.create(
         title="September",
         slug="september",
         body="What I did on September...")
     self.form = comments.get_form()(self.article)
     data = {
         "name": "Bob",
         "email": "*****@*****.**",
         "followup": True,
         "reply_to": 0,
         "level": 1,
         "order": 1,
         "comment": "Es war einmal iene kleine..."
     }
     data.update(self.form.initial)
     self.response = self.client.post(reverse("comments-post-comment"),
                                      data=data)
     if mail_sent_queue.get(block=True):
         pass
     self.key = re.search(r'http://.+/confirm/(?P<key>[\S]+)',
                          mail.outbox[0].body).group("key")