Пример #1
0
 def test_delete_all_messages_in_thread(self):
     self.user.is_staff = True
     self.user.save()
     msg = Email.objects.get(message_id="msg")
     msg2 = Message()
     msg2["From"] = "*****@*****.**"
     msg2["Message-ID"] = "<msg2>"
     msg2["In-Reply-To"] = "<msg>"
     msg2.set_payload("Dummy message")
     add_to_list("*****@*****.**", msg2)
     msg2 = Email.objects.get(message_id="msg2")
     thread_id = msg.thread.pk
     url = reverse('hk_thread_delete',
                   args=("*****@*****.**", msg.thread.thread_id))
     response = self.client.post(url, {"email": [msg.pk, msg2.pk]})
     self.assertRedirects(
         response, reverse('hk_list_overview', kwargs={
             "mlist_fqdn": "*****@*****.**"}))
     # Flash message
     messages = get_flash_messages(response)
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].tags, "success")
     # Alls messages and the thread must be deleted.
     self.assertFalse(Email.objects.filter(message_id="msg").exists())
     self.assertFalse(Email.objects.filter(message_id="msg2").exists())
     self.assertFalse(Thread.objects.filter(pk=thread_id).exists())
Пример #2
0
 def test_delete_single_in_thread(self):
     # Delete an email in a thread that contains other emails
     self.user.is_staff = True
     self.user.save()
     msg = Email.objects.get(message_id="msg")
     msg2 = Message()
     msg2["From"] = "*****@*****.**"
     msg2["Message-ID"] = "<msg2>"
     msg2["In-Reply-To"] = "<msg>"
     msg2.set_payload("Dummy message")
     add_to_list("*****@*****.**", msg2)
     msg2 = Email.objects.get(message_id="msg2")
     thread_id = msg.thread.thread_id
     url = reverse('hk_message_delete',
                   args=("*****@*****.**", msg.message_id_hash))
     response = self.client.post(url, {"email": msg.pk})
     self.assertRedirects(
         response, reverse('hk_thread', kwargs={
             "mlist_fqdn": "*****@*****.**",
             "threadid": thread_id}))
     # Flash message
     messages = get_flash_messages(response)
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].tags, "success")
     # The message must be deleted, but not the other message or the thread.
     self.assertFalse(Email.objects.filter(message_id="msg").exists())
     self.assertTrue(Email.objects.filter(message_id="msg2").exists())
     thread = Thread.objects.get(thread_id=thread_id)
     self.assertIsNotNone(thread)
     # msg2 must now be the thread starter.
     msg2.refresh_from_db()
     self.assertIsNone(msg2.parent_id)
     self.assertEqual(thread.starting_email.message_id, "msg2")
Пример #3
0
 def test_new_message_different_sender(self):
     self.user.first_name = "Django"
     self.user.last_name = "User"
     self.user.save()
     mm_user = Mock()
     self.mailman_client.get_user.side_effect = lambda name: mm_user
     mm_user.user_id = uuid.uuid1().int
     mm_user.addresses = ["*****@*****.**", "*****@*****.**"]
     mm_user.subscriptions = []
     mlist = MailingList.objects.get(name="*****@*****.**")
     url = reverse('hk_message_new', args=["*****@*****.**"])
     with patch("hyperkitty.views.message.post_to_list") as posting_fn:
         response = self.client.post(url, {
             "subject": "Test subject",
             "sender": "*****@*****.**",
             "message": "Test message content",
             })
         self.assertEqual(posting_fn.call_count, 1)
         self.assertEqual(posting_fn.call_args[0][1:],
             (mlist, 'Test subject', 'Test message content',
              {'From': '*****@*****.**'}))
     redirect_url = reverse(
             'hk_archives_with_month', kwargs={
                 "mlist_fqdn": "*****@*****.**",
                 'year': timezone.now().year,
                 'month': timezone.now().month})
     self.assertRedirects(response, redirect_url)
     # flash message
     messages = get_flash_messages(response)
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].tags, "success")
Пример #4
0
 def test_new_message_post(self):
     self.user.first_name = "Django"
     self.user.last_name = "User"
     self.user.save()
     url = reverse('hk_message_new', args=["*****@*****.**"])
     with patch("hyperkitty.lib.posting.mailman.subscribe") as sub_fn:
         response = self.client.post(url, {
             "subject": "Test subject",
             "message": "Test message content"})
     self.assertTrue(sub_fn.called)
     redirect_url = reverse(
             'hk_archives_with_month', kwargs={
                 "mlist_fqdn": "*****@*****.**",
                 'year': timezone.now().year,
                 'month': timezone.now().month})
     self.assertRedirects(response, redirect_url)
     # flash message
     messages = get_flash_messages(response)
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].tags, "success")
     # sent email
     self.assertEqual(len(mail.outbox), 1)
     #print(mail.outbox[0].message())
     self.assertEqual(mail.outbox[0].recipients(), ["*****@*****.**"])
     self.assertEqual(mail.outbox[0].from_email, '"Django User" <*****@*****.**>')
     self.assertEqual(mail.outbox[0].subject, 'Test subject')
     self.assertEqual(mail.outbox[0].body, "Test message content")
     self.assertIsNone(mail.outbox[0].message().get("references"))
     self.assertIsNone(mail.outbox[0].message().get("in-reply-to"))
Пример #5
0
 def test_reattach_manual(self):
     threadid1 = self.messages[0]["Message-ID-Hash"]
     threadid2 = self.messages[1]["Message-ID-Hash"]
     response = self.client.post(reverse('hk_thread_reattach',
                                 args=["*****@*****.**", threadid2]),
                                 data={"parent": "",
                                       "parent-manual": threadid1})
     threads = Thread.objects.order_by("id")
     self.assertEqual(threads[0].thread_id, threadid1)
     expected_url = reverse('hk_thread', args=["*****@*****.**", threadid1])
     self.assertRedirects(response, expected_url)
     messages = get_flash_messages(response)
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].tags, "success")
Пример #6
0
 def test_delete_single_message(self):
     self.user.is_staff = True
     self.user.save()
     msg = Email.objects.get(message_id="msg")
     thread_id = msg.thread.pk
     url = reverse('hk_message_delete',
                   args=("*****@*****.**", msg.message_id_hash))
     response = self.client.post(url, {"email": msg.pk})
     self.assertRedirects(
         response, reverse('hk_list_overview', kwargs={
             "mlist_fqdn": "*****@*****.**"}))
     # Flash message
     messages = get_flash_messages(response)
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].tags, "success")
     # The message and the thread must be deleted.
     self.assertFalse(Email.objects.filter(message_id="msg").exists())
     self.assertFalse(Thread.objects.filter(pk=thread_id).exists())