Example #1
0
 def test_reply_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 = ["testuser@example.com", "otheremail@example.com"]
     mm_user.subscriptions = []
     mlist = MailingList.objects.get(name="list@example.com")
     url = reverse("hk_message_reply", args=("list@example.com", get_message_id_hash("msg")))
     with patch("hyperkitty.views.message.post_to_list") as posting_fn:
         response = self.client.post(url, {"message": "dummy reply content", "sender": "otheremail@example.com"})
         self.assertEqual(response.status_code, 200)
         self.assertEqual(posting_fn.call_count, 1)
         self.assertEqual(
             posting_fn.call_args[0][1:],
             (
                 mlist,
                 "Re: Dummy Subject",
                 "dummy reply content",
                 {"From": "otheremail@example.com", "In-Reply-To": "<msg>", "References": "<msg>"},
             ),
         )
     result = json.loads(response.content)
     # print(result["message_html"])
     self.assertIn("Django User", result["message_html"])
     self.assertIn("dummy reply content", result["message_html"])
     self.assertIn(get_gravatar_url("otheremail@example.com", 120).replace("&", "&amp;"), result["message_html"])
Example #2
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 = ["testuser@example.com", "otheremail@example.com"]
     mm_user.subscriptions = []
     mlist = MailingList.objects.get(name="list@example.com")
     url = reverse("hk_message_new", args=["list@example.com"])
     with patch("hyperkitty.views.message.post_to_list") as posting_fn:
         response = self.client.post(
             url, {"subject": "Test subject", "sender": "otheremail@example.com", "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": "otheremail@example.com"}),
         )
     redirect_url = reverse(
         "hk_archives_with_month",
         kwargs={"mlist_fqdn": "list@example.com", "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")
Example #3
0
    def test_regular(self):
        handler = Mock(name="handler_value")
        handler.context_id = "context_id_value"
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"
        handler.suggest_id = "suggest_id_value"
        handler.page_size = "page_size_value"

        suggestions = Mock()
        sender = MagicMock()
        target = Target(suggestions, sender)

        target.on_next_page_message(handler, {"suggest_id": "suggest_id_value", "offset": "original_offset_value"})

        self.assertEqual(1, target.suggestions.get_suggestion_items.call_count)
        self.assertEqual("user_id_value", target.suggestions.get_suggestion_items.call_args_list[0][0][0])
        self.assertEqual("application_id_value", target.suggestions.get_suggestion_items.call_args_list[0][0][1])
        self.assertEqual("session_id_value", target.suggestions.get_suggestion_items.call_args_list[0][0][2])
        self.assertEqual("locale_value", target.suggestions.get_suggestion_items.call_args_list[0][0][3])
        self.assertEqual("suggest_id_value", target.suggestions.get_suggestion_items.call_args_list[0][0][4])
        self.assertEqual("page_size_value", target.suggestions.get_suggestion_items.call_args_list[0][0][5])
        self.assertEqual("original_offset_value", target.suggestions.get_suggestion_items.call_args_list[0][0][6])

        self.assertEqual("context_id_value", handler.context_id)
        self.assertEqual("suggest_id_value", handler.suggest_id)
Example #4
0
 def test_get_subscriptions(self):
     self.mailman_client.get_list.side_effect = lambda name: FakeMMList(name)
     mm_user = Mock()
     self.mailman_client.get_user.side_effect = lambda name: mm_user
     mm_user.user_id = uuid.uuid1().int
     mm_user.subscription_list_ids = ["test@example.com"]
     MailingList.objects.create(name="test@example.com")
     try:
         subs = self.user.hyperkitty_profile.get_subscriptions()
     except AttributeError:
         # print_exc()
         self.fail("Subscriptions should be available even if " "the user has never voted yet\n%s" % format_exc())
     self.assertEqual(subs, ["test@example.com"])
Example #5
0
 def test_public_profile_as_oneself(self):
     user_id = uuid.uuid1()
     self.mailman_client.get_list.side_effect = lambda name: FakeMMList(name)
     mm_user = Mock()
     self.mailman_client.get_user.side_effect = lambda name: mm_user
     mm_user.user_id = user_id.int
     mm_user.created_on = None
     mm_user.addresses = ["test@example.com"]
     self.client.login(username="testuser", password="testPass")
     response = self.client.get(reverse("hk_public_user_profile", args=[user_id.int]))
     self.assertEqual(response.status_code, 200)
     self.assertTrue(response.context["is_user"])
     self.assertContains(response, "This is you.", count=1)
     self.assertContains(response, "Edit your private profile", count=1)
Example #6
0
 def test_overview_with_user(self):
     user = User.objects.create_user("testuser", "dummy@example.com", "testPass")
     sender = Sender.objects.get(address="dummy@example.com")
     sender.mailman_id = "dummy"
     sender.save()
     mm_user = Mock()
     mm_user.user_id = "dummy"
     self.mailman_client.get_user.side_effect = lambda name: mm_user
     self.client.login(username="testuser", password="testPass")
     thread = Thread.objects.first()
     Favorite.objects.create(thread=thread, user=user)
     response = self.client.get(reverse("hk_list_overview", args=["list@example.com"]))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.context["threads_posted_to"]), 1)
     self.assertEqual(len(response.context["flagged_threads"]), 1)
Example #7
0
 def test_call_set_mailman_id(self):
     mock_user = Mock()
     mock_user.user_id = "from-mailman"
     self.mailman_client.get_user.side_effect = lambda a: mock_user
     for i in range(10):
         Sender.objects.create(address="test%s@example.com" % i)
     for i in range(10, 20):
         Sender.objects.create(address="test%s@example.com" % i, mailman_id="already-set")
     mailman.sync_with_mailman()
     # Track calls to Sender.set_mailman_id() using the client's
     # get_user() method. Didn't find anything better.
     # Only senders with a mailman_id to None should have been considered.
     self.assertEqual(self.mailman_client.get_user.call_count, 10)
     self.assertEqual(Sender.objects.filter(mailman_id__isnull=True).count(), 0)
     self.assertEqual(Sender.objects.filter(mailman_id="from-mailman").count(), 10)
     self.assertEqual(Sender.objects.filter(mailman_id="already-set").count(), 10)
    def test_regular(self):
        sender = Mock()
        context = Mock()
        suggest = Mock()
        target = Target(sender, context, suggest)

        handler = Mock()
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"

        target.on_new_message_empty(handler, "message_value")

        self.assertEqual(1, context.get_context.call_count)
        self.assertEqual(handler, context.get_context.call_args_list[0][0][0])
    def test_regular(self):
        sender = Mock()
        detect = Mock()
        context = Mock()
        suggest = Mock()
        target = Target(sender, detect, context, suggest)

        handler = Mock()
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"

        target.on_new_message_text(handler, "message_value", "message_text_value")

        self.assertEqual(1, detect.post_detect.call_count)
        self.assertEqual("user_id_value", detect.post_detect.call_args_list[0][0][0])
        self.assertEqual("application_id_value", detect.post_detect.call_args_list[0][0][1])
        self.assertEqual("session_id_value", detect.post_detect.call_args_list[0][0][2])
        self.assertEqual("locale_value", detect.post_detect.call_args_list[0][0][3])
        self.assertEqual("message_text_value", detect.post_detect.call_args_list[0][0][4])
Example #10
0
    def test_context_id_None(self):
        product_content = Mock()
        client_handlers = {}
        user_info_cache = Mock()
        favorites_cache = Mock()
        target = Target(
            product_content=product_content,
            client_handlers=client_handlers,
            user_info_cache=user_info_cache,
            favorites_cache=favorites_cache,
        )

        target.get_context = Mock()
        target.post_context = Mock(return_value=("context_id_value", "context_rev_value"))
        handler = Mock()
        handler.context_id = None
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"

        target.open(handler)

        self.assertEqual(0, target.get_context.call_count)
        self.assertEqual(1, target.post_context.call_count)

        self.assertEqual("user_id_value", target.post_context.call_args_list[0][0][0])
        self.assertEqual("application_id_value", target.post_context.call_args_list[0][0][1])
        self.assertEqual("session_id_value", target.post_context.call_args_list[0][0][2])
        self.assertEqual("locale_value", target.post_context.call_args_list[0][0][3])

        self.assertEqual("context_id_value", handler.context_id)
        self.assertEqual("context_rev_value", handler.context_rev)

        self.assertEqual(1, handler.write_message.call_count)
        self.assertDictEqual(
            {"context_id": "context_id_value", "type": "connection_opened"},
            handler.write_message.call_args_list[0][0][0],
        )
Example #11
0
    def test_regular(self):
        handler = Mock(name="handler_value")
        handler.context_id = "context_id_value"
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"
        handler.suggest_id = "suggest_id_value"
        handler.context_rev = "old_rev"

        product_content = Mock()
        client_handlers = Mock()
        user_info_cache = Mock()
        favorites_cache = Mock()
        target = Target(
            product_content=product_content,
            client_handlers=client_handlers,
            user_info_cache=user_info_cache,
            favorites_cache=favorites_cache,
        )
        target.post_context_feedback = Mock(return_value="new_rev")

        target.on_view_product_details_message(
            handler, {"product_id": "product_id_value", "feedback_type": "type_value"}
        )

        self.assertEqual(1, target.post_context_feedback.call_count)
        self.assertEqual("context_id_value", target.post_context_feedback.call_args_list[0][0][0])
        self.assertEqual("user_id_value", target.post_context_feedback.call_args_list[0][0][1])
        self.assertEqual("application_id_value", target.post_context_feedback.call_args_list[0][0][2])
        self.assertEqual("session_id_value", target.post_context_feedback.call_args_list[0][0][3])
        self.assertEqual("product_id_value", target.post_context_feedback.call_args_list[0][0][4])
        self.assertEqual("type_value", target.post_context_feedback.call_args_list[0][0][5])
        self.assertIsNone(target.post_context_feedback.call_args_list[0][0][6])

        self.assertEqual("context_id_value", handler.context_id)
        self.assertEqual("suggest_id_value", handler.suggest_id)
        self.assertEqual("new_rev", handler.context_rev)
def get_auth_user_mock():
    u = Mock()
    u.user_id = 1
    u.is_authenticated = Mock(return_value=True)
    return u
Example #13
0
 def mock_google_account_user(self):
     google_account_user = Mock()
     google_account_user.user_id = lambda: "123"
     google_account_user.email = lambda: "foo@gmail.com"
     google_account_user.nickname = lambda: "foo"
     return google_account_user