def test_getRecipientPersons_to_user(self):
     # The recipient set only contains the user.
     sender = self.factory.makePerson()
     user = self.factory.makePerson(email='*****@*****.**')
     recipient_set = ContactViaWebNotificationRecipientSet(sender, user)
     self.assertContentEqual([('*****@*****.**', user)],
                             list(recipient_set.getRecipientPersons()))
 def test_getRecipientPersons_to_user(self):
     # The recipient set only contains the user.
     sender = self.factory.makePerson()
     user = self.factory.makePerson(email='*****@*****.**')
     recipient_set = ContactViaWebNotificationRecipientSet(sender, user)
     self.assertContentEqual(
         [('*****@*****.**', user)],
         list(recipient_set.getRecipientPersons()))
 def test_getRecipientPersons_to_admins(self):
     # The recipient set only contains the team admins when the user
     # is not an admin of the team the user is contacting
     admin = self.factory.makePerson(email='*****@*****.**')
     member = self.factory.makePerson(email='*****@*****.**')
     team = self.factory.makeTeam(owner=admin, members=[member])
     recipient_set = ContactViaWebNotificationRecipientSet(member, team)
     self.assertContentEqual([('*****@*****.**', admin)],
                             list(recipient_set.getRecipientPersons()))
 def test_getRecipientPersons_to_members(self):
     # The recipient set contains all the team members when the admin
     # is contacting the team.
     admin = self.factory.makePerson(email='*****@*****.**')
     member = self.factory.makePerson(email='*****@*****.**')
     team = self.factory.makeTeam(owner=admin, members=[member])
     recipient_set = ContactViaWebNotificationRecipientSet(admin, team)
     self.assertContentEqual(
         [('*****@*****.**', admin), ('*****@*****.**', member)],
         list(recipient_set.getRecipientPersons()))
 def test_getRecipientPersons_to_admins(self):
     # The recipient set only contains the team admins when the user
     # is not an admin of the team the user is contacting
     admin = self.factory.makePerson(email='*****@*****.**')
     member = self.factory.makePerson(email='*****@*****.**')
     team = self.factory.makeTeam(owner=admin, members=[member])
     recipient_set = ContactViaWebNotificationRecipientSet(member, team)
     self.assertContentEqual(
         [('*****@*****.**', admin)],
         list(recipient_set.getRecipientPersons()))
 def test_rationale_and_reason_user(self):
     sender = self.factory.makePerson()
     user = self.factory.makePerson(name='pting')
     recipient_set = ContactViaWebNotificationRecipientSet(sender, user)
     for email, recipient in recipient_set.getRecipientPersons():
         reason, rationale = recipient_set.getReason(email)
     self.assertEqual(
         'using the "Contact this user" link on your profile page\n'
         '(http://launchpad.dev/~pting)', reason)
     self.assertEqual('ContactViaWeb user', rationale)
 def test_getRecipientPersons_to_members(self):
     # The recipient set contains all the team members when the admin
     # is contacting the team.
     admin = self.factory.makePerson(email='*****@*****.**')
     member = self.factory.makePerson(email='*****@*****.**')
     team = self.factory.makeTeam(owner=admin, members=[member])
     recipient_set = ContactViaWebNotificationRecipientSet(admin, team)
     self.assertContentEqual([('*****@*****.**', admin),
                              ('*****@*****.**', member)],
                             list(recipient_set.getRecipientPersons()))
 def test_len_to_admins(self):
     # The recipient set length is based on the number of admins.
     sender = self.factory.makePerson()
     team = self.factory.makeTeam()
     self.assertEqual(
         1, len(ContactViaWebNotificationRecipientSet(sender, team)))
     with person_logged_in(team.teamowner):
         team.teamowner.leave(team)
     self.assertEqual(
         0, len(ContactViaWebNotificationRecipientSet(sender, team)))
 def test_nonzero(self):
     # The recipient set can be used in boolean conditions.
     sender = self.factory.makePerson()
     user = self.factory.makePerson(email='*****@*****.**')
     self.assertTrue(
         bool(ContactViaWebNotificationRecipientSet(sender, user)))
     inactive_user = self.factory.makePerson(
         email_address_status=EmailAddressStatus.NEW)
     self.assertFalse(
         bool(ContactViaWebNotificationRecipientSet(sender, inactive_user)))
 def test_rationale_and_reason_user(self):
     sender = self.factory.makePerson()
     user = self.factory.makePerson(name='pting')
     recipient_set = ContactViaWebNotificationRecipientSet(sender, user)
     for email, recipient in recipient_set.getRecipientPersons():
         reason, rationale = recipient_set.getReason(email)
     self.assertEqual(
         'using the "Contact this user" link on your profile page\n'
         '(http://launchpad.dev/~pting)',
         reason)
     self.assertEqual('ContactViaWeb user', rationale)
 def test_len_to_user(self):
     # The recipient set length is based on the user activity.
     sender = self.factory.makePerson()
     user = self.factory.makePerson(email='*****@*****.**')
     self.assertEqual(
         1, len(ContactViaWebNotificationRecipientSet(sender, user)))
     inactive_user = self.factory.makePerson(
         email_address_status=EmailAddressStatus.NEW)
     self.assertEqual(
         0,
         len(ContactViaWebNotificationRecipientSet(sender, inactive_user)))
 def test_rationale_and_reason_members(self):
     team = self.factory.makeTeam(name='pting')
     sender = team.teamowner
     recipient_set = ContactViaWebNotificationRecipientSet(sender, team)
     for email, recipient in recipient_set.getRecipientPersons():
         reason, rationale = recipient_set.getReason(email)
     self.assertEqual(
         'to each member of the Pting team using the '
         '"Contact this team" link on the Pting team page\n'
         '(http://launchpad.dev/~pting)', reason)
     self.assertEqual('ContactViaWeb member (pting team)', rationale)
 def test_rationale_and_reason_admin(self):
     sender = self.factory.makePerson()
     team = self.factory.makeTeam(name='pting')
     recipient_set = ContactViaWebNotificationRecipientSet(sender, team)
     for email, recipient in recipient_set.getRecipientPersons():
         reason, rationale = recipient_set.getReason(email)
     self.assertEqual(
         'using the "Contact this team\'s admins" link '
         'on the Pting team page\n'
         '(http://launchpad.dev/~pting)', reason)
     self.assertEqual('ContactViaWeb owner (pting team)', rationale)
 def test_rationale_and_reason_members(self):
     team = self.factory.makeTeam(name='pting')
     sender = team.teamowner
     recipient_set = ContactViaWebNotificationRecipientSet(sender, team)
     for email, recipient in recipient_set.getRecipientPersons():
         reason, rationale = recipient_set.getReason(email)
     self.assertEqual(
         'to each member of the Pting team using the '
         '"Contact this team" link on the Pting team page\n'
         '(http://launchpad.dev/~pting)',
         reason)
     self.assertEqual('ContactViaWeb member (pting team)', rationale)
 def test_rationale_and_reason_admin(self):
     sender = self.factory.makePerson()
     team = self.factory.makeTeam(name='pting')
     recipient_set = ContactViaWebNotificationRecipientSet(sender, team)
     for email, recipient in recipient_set.getRecipientPersons():
         reason, rationale = recipient_set.getReason(email)
     self.assertEqual(
         'using the "Contact this team\'s admins" link '
         'on the Pting team page\n'
         '(http://launchpad.dev/~pting)',
         reason)
     self.assertEqual('ContactViaWeb owner (pting team)', rationale)
 def test_len_to_members(self):
     # The recipient set length is based on the number members.
     member = self.factory.makePerson()
     sender_team = self.factory.makeTeam(members=[member])
     owner = sender_team.teamowner
     with StormStatementRecorder() as recorder:
         total = len(
             ContactViaWebNotificationRecipientSet(owner, sender_team))
         self.assertThat(recorder, HasQueryCount(LessThan(3)))
     self.assertEqual(2, total)
     with person_logged_in(owner):
         owner.leave(sender_team)
     self.assertEqual(
         1, len(ContactViaWebNotificationRecipientSet(owner, sender_team)))
 def test_description_to_members(self):
     member = self.factory.makePerson()
     team = self.factory.makeTeam(name='pting', members=[member])
     admin = team.teamowner
     recipient_set = ContactViaWebNotificationRecipientSet(admin, team)
     self.assertEqual(
         'You are contacting 2 members of the Pting (pting) team directly.',
         recipient_set.description)
 def test_description_to_user(self):
     sender = self.factory.makePerson()
     user = self.factory.makePerson(name='pting')
     recipient_set = ContactViaWebNotificationRecipientSet(sender, user)
     self.assertEqual('You are contacting Pting (pting).',
                      recipient_set.description)
 def test_description_to_admin(self):
     member = self.factory.makePerson()
     team = self.factory.makeTeam(name='pting', members=[member])
     recipient_set = ContactViaWebNotificationRecipientSet(member, team)
     self.assertEqual('You are contacting the Pting (pting) team admins.',
                      recipient_set.description)