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_display_no_message(self):
     # A notification is not added if there is no message to show.
     product, user = self.make_product_user([License.GNU_GPL_V2])
     notification = LicenseNotification(product)
     result = notification.display()
     self.assertEqual('', notification.getCommercialUseMessage())
     self.assertIs(False, result)
 def test_getCommercialUseMessage_with_complimentary_cs(self):
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     notification = LicenseNotification(product)
     message = (
         "Ball's complimentary commercial subscription expires on %s." %
         product.commercial_subscription.date_expires.date().isoformat())
     self.assertEqual(message, notification.getCommercialUseMessage())
 def test_getCommercialUseMessage_with_commercial_subscription(self):
     product, user = self.make_product_user([License.MIT])
     self.factory.makeCommercialSubscription(product)
     product.licenses = [License.MIT, License.OTHER_PROPRIETARY]
     notification = LicenseNotification(product)
     message = (
         "Ball's commercial subscription expires on %s." %
         product.commercial_subscription.date_expires.date().isoformat())
     self.assertEqual(message, notification.getCommercialUseMessage())
 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_display_escapee_user_data(self):
     # A notification is added if there is a message to show.
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     product.display_name = '<b>Look</b>'
     notification = LicenseNotification(product)
     result = notification.display()
     self.assertIs(True, result)
     request = get_current_browser_request()
     self.assertEqual(1, len(request.response.notifications))
     self.assertIn('&lt;b&gt;Look&lt;/b&gt;',
                   request.response.notifications[0].message)
 def test_display_no_request(self):
     # If there is no request, there is no reason to show a message in
     # the browser.
     product, user = self.make_product_user([License.GNU_GPL_V2])
     # Using the proxied product leads to an exeception when
     # notification.display() below is called because the permission
     # checks product require an interaction.
     notification = LicenseNotification(removeSecurityProxy(product))
     logout()
     result = notification.display()
     self.assertIs(False, result)
 def test_display_escapee_user_data(self):
     # A notification is added if there is a message to show.
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     product.displayname = '<b>Look</b>'
     notification = LicenseNotification(product)
     result = notification.display()
     self.assertIs(True, result)
     request = get_current_browser_request()
     self.assertEqual(1, len(request.response.notifications))
     self.assertIn(
         '&lt;b&gt;Look&lt;/b&gt;',
         request.response.notifications[0].message)
 def test_display_has_message(self):
     # A notification is added if there is a message to show.
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     notification = LicenseNotification(product)
     result = notification.display()
     message = notification.getCommercialUseMessage()
     self.assertIs(True, result)
     request = get_current_browser_request()
     self.assertEqual(1, len(request.response.notifications))
     self.assertIn(
         html_escape(message), request.response.notifications[0].message)
     self.assertIn(
         '<a href="https://help.launchpad.net/CommercialHosting">',
         request.response.notifications[0].message)
 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'])
 def test_getCommercialUseMessage_without_commercial_subscription(self):
     product, user = self.make_product_user([License.MIT])
     notification = LicenseNotification(product)
     self.assertEqual('', notification.getCommercialUseMessage())
 def test_getTemplateName_other_open_source(self):
     product, user = self.make_product_user([License.OTHER_OPEN_SOURCE])
     notification = LicenseNotification(product)
     self.assertEqual(
         'product-license-other-open-source.txt',
         notification.getTemplateName())
 def test_getTemplateName_propietary(self):
     product, user = self.make_product_user([License.OTHER_PROPRIETARY])
     notification = LicenseNotification(product)
     self.assertEqual(
         'product-license-other-proprietary.txt',
         notification.getTemplateName())
 def test_getTemplateName_other_dont_know(self):
     product, user = self.make_product_user([License.DONT_KNOW])
     notification = LicenseNotification(product)
     self.assertEqual(
         'product-license-dont-know.txt',
         notification.getTemplateName())
 def test_formatDate(self):
     # Verify the date format.
     now = datetime(2005, 6, 15, 0, 0, 0, 0, pytz.UTC)
     result = LicenseNotification._formatDate(now)
     self.assertEqual('2005-06-15', result)