def test_send_known_license(self):
     # A known licence does not generate an email.
     product, user = self.make_product_user([License.GNU_GPL_V2])
     notification = LicenseNotification(product)
     result = notification.send()
     self.assertIs(False, result)
     self.assertEqual(0, len(pop_notifications()))
 def test_send_other_proprietary(self):
     # An Other/Proprietary licence sends one email.
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     notification = LicenseNotification(product)
     result = notification.send()
     self.assertIs(True, result)
     self.verify_whiteboard(product)
     notifications = pop_notifications()
     self.assertEqual(1, len(notifications))
     self.verify_user_email(notifications.pop())
 def test_send_other_open_source(self):
     # An Other/Open Source licence sends one email.
     product, user = self.make_product_user([License.OTHER_OPEN_SOURCE])
     notification = LicenseNotification(product)
     result = notification.send()
     self.assertIs(True, result)
     self.verify_whiteboard(product)
     notifications = pop_notifications()
     self.assertEqual(1, len(notifications))
     self.verify_user_email(notifications.pop())
 def test_send_other_dont_know(self):
     # An Other/I don't know licence sends one email.
     product, user = self.make_product_user([License.DONT_KNOW])
     notification = LicenseNotification(product)
     result = notification.send()
     self.assertIs(True, result)
     self.verify_whiteboard(product)
     notifications = pop_notifications()
     self.assertEqual(1, len(notifications))
     self.verify_user_email(notifications.pop())
 def test_send_other_proprietary_no_team_admins_falls_back_to_owner(self):
     # If there are no team admins, an Other/Proprietary licence falls
     # back to sending email to the team owner.
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     owner = self.factory.makePerson(email='*****@*****.**')
     team = self.factory.makeTeam(
         owner=owner, membership_policy=TeamMembershipPolicy.RESTRICTED)
     with person_logged_in(team.teamowner):
         team.teamowner.leave(team)
     with person_logged_in(product.owner):
         product.owner = team
     pop_notifications()
     notification = LicenseNotification(product)
     result = notification.send()
     self.assertIs(True, result)
     notifications = pop_notifications()
     self.assertEqual(1, len(notifications))
     self.assertEqual('*****@*****.**', notifications[0]['To'])
 def test_send_other_proprietary_team_admins(self):
     # An Other/Proprietary licence sends one email to the team admins.
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     owner = self.factory.makePerson(email='*****@*****.**')
     team = self.factory.makeTeam(
         owner=owner, membership_policy=TeamMembershipPolicy.RESTRICTED)
     admin = self.factory.makePerson(email='*****@*****.**')
     with person_logged_in(owner):
         team.addMember(admin, owner)
         membership_set = getUtility(ITeamMembershipSet)
         tm = membership_set.getByPersonAndTeam(admin, team)
         tm.setStatus(TeamMembershipStatus.ADMIN, owner)
     with person_logged_in(product.owner):
         product.owner = team
     pop_notifications()
     notification = LicenseNotification(product)
     result = notification.send()
     self.assertIs(True, result)
     notifications = pop_notifications()
     self.assertEqual(1, len(notifications))
     self.assertEqual('[email protected],[email protected]', notifications[0]['To'])