def test_search_private_lists(self): # Create 1 public and 2 private lists mlist_public = MailingList.objects.create(name="*****@*****.**") mlist_private = MailingList.objects.create( name="*****@*****.**", archive_policy=ArchivePolicy.private.value ) mlist_private_sub = MailingList.objects.create( name="*****@*****.**", archive_policy=ArchivePolicy.private.value ) # (make sure the mailman client will not reset the archive_policy) mailman_lists = { "*****@*****.**": FakeMMList("*****@*****.**"), "*****@*****.**": FakeMMList("*****@*****.**"), "*****@*****.**": FakeMMList("*****@*****.**"), } mailman_lists["*****@*****.**"].settings["archive_policy"] = "private" mailman_lists["*****@*****.**"].settings["archive_policy"] = "private" self.mailman_client.get_list.side_effect = lambda name: mailman_lists[name] # Subscribe the user to one of the private lists self.mm_user.subscriptions = [ FakeMMMember("*****@*****.**", self.user.email), ] # Populate the lists with messages self._send_message(mlist_public) self._send_message(mlist_private) self._send_message(mlist_private_sub) # There must be a result from the public and the subscribed list only self.client.login(username='******', password='******') response = self.client.get(reverse("hk_search"), {"q": "keyword"}) self.assertEqual(response.status_code, 200) self.assertEqual(response.context["messages"].paginator.count, 2) self.assertContains(response, "Dummy message", count=2)
def setUp(self): self.user = User.objects.create_user( 'testuser', '*****@*****.**', 'testPass') self.mailman_client.get_list.side_effect = lambda name: FakeMMList(name) self.mm_user = Mock() self.mailman_client.get_user.side_effect = lambda name: self.mm_user self.mm_user.user_id = uuid.uuid1().int self.mm_user.addresses = ["*****@*****.**"]
def test_search_private_list(self): mlist = MailingList.objects.create( name="*****@*****.**", archive_policy=ArchivePolicy.private.value ) mm_mlist = FakeMMList("*****@*****.**") mm_mlist.settings["archive_policy"] = "private" self.mailman_client.get_list.side_effect = lambda name: mm_mlist self.mm_user.subscription_list_ids = ["*****@*****.**",] self._send_message(mlist) response = self.client.get(reverse("hk_search"), {"q": "dummy", "mlist": "*****@*****.**"}) self.assertEqual(response.status_code, 403) self.client.login(username='******', password='******') response = self.client.get(reverse("hk_search"), {"q": "dummy", "mlist": "*****@*****.**"}) self.assertEqual(response.status_code, 200) self.assertContains(response, "Dummy message")
def test_search_private_list(self): mlist = MailingList.objects.create( name="*****@*****.**", archive_policy=ArchivePolicy.private.value ) mm_mlist = FakeMMList("*****@*****.**") mm_mlist.settings["archive_policy"] = "private" self.mailman_client.get_list.side_effect = lambda name: mm_mlist self.mm_user.subscriptions = [ FakeMMMember("*****@*****.**", self.user.email), ] self._send_message(mlist) response = self.client.get(reverse("hk_search"), {"q": "dummy", "mlist": "*****@*****.**"}) self.assertEqual(response.status_code, 403) self.client.login(username='******', password='******') response = self.client.get(reverse("hk_search"), {"q": "dummy", "mlist": "*****@*****.**"}) self.assertEqual(response.status_code, 200) self.assertContains(response, "Dummy message")
def setUp(self): self.mlist = MailingList.objects.create(name="*****@*****.**") self.ml = FakeMMList("*****@*****.**") self.mailman_client.get_list.side_effect = lambda n: self.ml #self.ml.get_member = Mock() #self.ml.subscribe = Mock() self.user = User.objects.create_user('testuser', '*****@*****.**', 'testPass') self.mm_user = Mock() self.mailman_client.get_user.side_effect = lambda name: self.mm_user self.mm_user.user_id = uuid.uuid1().int self.mm_user.addresses = ["*****@*****.**"] self.mm_user.subscriptions = [] self.request = RequestFactory().get("/") self.request.user = self.user
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 fake_member = FakeMMMember("*****@*****.**", "*****@*****.**") mm_user.subscriptions = [ fake_member, ] MailingList.objects.create(name="*****@*****.**") 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, {"*****@*****.**": "*****@*****.**"})
def setUp(self): self.user = User.objects.create_user('testuser', '*****@*****.**', 'testPass') MailingList.objects.create( name="*****@*****.**", subject_prefix="[example] ", archive_policy=ArchivePolicy.private.value) msg = Message() msg["From"] = "*****@*****.**" msg["Message-ID"] = "<msgid>" msg["Subject"] = "Dummy message" msg.set_payload("Dummy message") msg["Message-ID-Hash"] = self.msgid = add_to_list("*****@*****.**", msg) # Set the mailman_client after the message has been added to the list, # otherwise MailingList.update_from_mailman() will overwrite the list # properties. self.mailman_client.get_list.side_effect = lambda name: FakeMMList(name) self.mm_user = Mock() self.mm_user.user_id = "dummy" self.mailman_client.get_user.side_effect = lambda name: self.mm_user self.mm_user.subscriptions = [ FakeMMMember("*****@*****.**", self.user.email), ]
def setUp(self): self.ml = MailingList.objects.create(name="*****@*****.**") self.mailman_ml = FakeMMList("*****@*****.**") self.mailman_client.get_list.side_effect = lambda n: self.mailman_ml