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("private-sub.example.com", 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["emails"].paginator.count, 2) self.assertContains(response, "Dummy message", count=2)
def setUp(self): 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')
def setUp(self): MailingList.objects.create(name="*****@*****.**", subject_prefix="[example] ", archive_policy=ArchivePolicy.private.value) msg = EmailMessage() 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) self.mailman_client.get_list.side_effect = \ lambda name: FakeMMList(name) User.objects.create_user('superuser', '*****@*****.**', 'testPass', is_superuser=True) self.mm_subbed_user = self._create_user('subbeduser', '*****@*****.**') self.mm_subbed_user.subscriptions = [ FakeMMMember("list.example.com", '*****@*****.**'), ] self.mm_unsubbed_user = self._create_user('unsubbeduser', '*****@*****.**') self.mm_unsubbed_user.subscriptions = [] def mm_get_user(email): if email == '*****@*****.**': return self.mm_subbed_user else: return self.mm_unsubbed_user self.mailman_client.get_user.side_effect = mm_get_user
def test_email_in_link_in_body(self): MailingList.objects.create(name="*****@*****.**", archive_policy=ArchivePolicy.private.value) mm_mlist = FakeMMList("*****@*****.**") self.mailman_client.get_list.side_effect = lambda name: mm_mlist msg = Message() msg["From"] = "Dummy Sender <*****@*****.**>" msg["Subject"] = "Dummy Subject" msg["Date"] = "Mon, 02 Feb 2015 13:00:00 +0300" msg["Message-ID"] = "<msg2>" link = "http://example.com/list/[email protected]/message" msg.set_payload("Email address in link: %s" % link) add_to_list("*****@*****.**", msg) for query in [{ "q": "dummy" }, { "q": "dummy", "mlist": "*****@*****.**" }]: response = self.client.get(reverse("hk_search"), query) self.assertContains( response, '<a href="{0}" rel="nofollow">{0}</a>'.format(link), msg_prefix="With query %r" % query, status_code=200)
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("list.example.com", self.user.email), ] self.mm_user.addresses = ['*****@*****.**']
def test_import_list_from_mailman_existing(self, update_from_mailman): MailingList.objects.create(name="*****@*****.**") mm_mlist = FakeMMList("*****@*****.**") self.mailman_client.get_list.side_effect = lambda lid: mm_mlist mailman.import_list_from_mailman("list.example.com") self.assertTrue(self.mailman_client.get_list.called) self.assertEqual(self.mailman_client.get_list.call_args_list[0][0], ("list.example.com", )) self.assertEqual(update_from_mailman.call_count, 1)
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_basic(self): mlist = MailingList.objects.create( name="*****@*****.**", ) mm_mlist = FakeMMList("*****@*****.**") self.mailman_client.get_list.side_effect = lambda name: mm_mlist self._send_message(mlist) response = self.client.get( reverse("hk_search"), {"q": "dummy", "mlist": "*****@*****.**"}) self.assertContains(response, "Dummy message")
def setUp(self): 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.mm_user.user_id = "dummy" self.mm_user.addresses = [] self.mailman_client.get_user.side_effect = lambda e: self.mm_user self.mm_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.subscriptions = [ FakeMMMember("private.example.com", 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.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_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 = ["*****@*****.**"] self.client.login(username='******', password='******') 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)
def test_email_escaped_sender(self): MailingList.objects.create( name="*****@*****.**", ) mm_mlist = FakeMMList("*****@*****.**") self.mailman_client.get_list.side_effect = lambda name: mm_mlist msg = EmailMessage() msg["From"] = "*****@*****.**" msg["Subject"] = "Dummy Subject" msg["Date"] = "Mon, 02 Feb 2015 13:00:00 +0300" msg["Message-ID"] = "<msg2>" msg.set_payload("Dummy content") add_to_list("*****@*****.**", msg) for query in [{"q": "dummy"}, {"q": "dummy", "mlist": "*****@*****.**"}]: response = self.client.get(reverse("hk_search"), query) self.assertNotContains( response, "*****@*****.**", msg_prefix="With query %r" % query, status_code=200)
def test_public_profile_as_superuser(self): user_id = uuid.uuid1() self.user.is_superuser = True self.user.save() self.client.login(username='******', password='******') 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 = [ "*****@*****.**", "*****@*****.**", ] response = self.client.get( reverse("hk_public_user_profile", args=[user_id.int])) self.assertEqual(response.status_code, 200) self.assertContains(response, "Email addresses:", count=1) self.assertContains(response, "*****@*****.**", count=1) self.assertContains(response, "*****@*****.**", count=1)
def test_get_new_lists_from_mailman(self): mlists = [ FakeMMList("*****@*****.**" % i) for i in range(1, 23) ] mlists[1].settings["archive_policy"] = "never" def _make_page(count, page): return FakeMMPage(mlists, count, page) self.mailman_client.get_list_page.side_effect = _make_page MailingList.objects.create(name="*****@*****.**") mailman.get_new_lists_from_mailman() self.assertEqual(self.mailman_client.get_list_page.call_count, 3) # Only the third list should have been created. self.assertFalse( MailingList.objects.filter(name="*****@*****.**").exists()) for i in range(3, 23): self.assertTrue( MailingList.objects.filter(name="*****@*****.**" % i).exists()) # Calls to MailingList.update_from_mailman() self.assertEqual(self.mailman_client.get_list.call_count, 20)
def test_email_escaped_body(self): MailingList.objects.create(name="*****@*****.**", archive_policy=ArchivePolicy.private.value) mm_mlist = FakeMMList("*****@*****.**") self.mailman_client.get_list.side_effect = lambda name: mm_mlist msg = Message() msg["From"] = "Dummy Sender <*****@*****.**>" msg["Subject"] = "Dummy Subject" msg["Date"] = "Mon, 02 Feb 2015 13:00:00 +0300" msg["Message-ID"] = "<msg2>" msg.set_payload("Email address: [email protected]") add_to_list("*****@*****.**", msg) for query in [{ "q": "dummy" }, { "q": "dummy", "mlist": "*****@*****.**" }]: response = self.client.get(reverse("hk_search"), query) self.assertNotContains(response, "*****@*****.**", msg_prefix="With query %r" % query, status_code=200)
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