def test_property_from_config_missing_config(self, mock_set_skin):
        'Test getting a property when there is no config'
        context = MagicMock(spec=['OtherConfig'])
        siteEmail = SiteEmail(context, None)

        r = siteEmail.property_from_config(b'DivisionConfiguration', b'emailSkin')

        self.assertIsNone(r)
    def test_fix_color_codes(self):
        t = '<td bgcolor="transparent"><p bgcolor="#fff">Hej</p></td>'
        siteEmail = SiteEmail(None, None)

        r = siteEmail.fix_color_codes(t)

        e = '<td><p bgcolor="#ffffff">Hej</p></td>'
        self.assertEqual(e, r)
    def test_fix_color_codes(self):
        t = '<td bgcolor="transparent"><p bgcolor="#fff">Hej</p></td>'
        siteEmail = SiteEmail(None, None)

        r = siteEmail.fix_color_codes(t)

        e = '<td><p bgcolor="#ffffff">Hej</p></td>'
        self.assertEqual(e, r)
    def test_property_from_config_missing_property(self, mock_set_skin):
        'Test getting a property when there is no property on the config'
        context = MagicMock(spec=['DivisionConfiguration'])
        context.DivisionConfiguration.getProperty.return_value = None
        siteEmail = SiteEmail(context, None)

        r = siteEmail.property_from_config(b'DivisionConfiguration', b'emailSkin')

        self.assertIsNone(r)
    def test_property_from_config(self, mock_set_skin):
        'Test getting a property from a config'
        context = MagicMock(spec=['DivisionConfiguration'])
        context.DivisionConfiguration.getProperty.return_value = self.skinName
        siteEmail = SiteEmail(context, None)

        r = siteEmail.property_from_config(b'DivisionConfiguration', b'emailSkin')

        self.assertEqual(self.skinName, r)
    def test_property_from_config_missing_config(self, mock_set_skin):
        'Test getting a property when there is no config'
        context = MagicMock(spec=['OtherConfig'])
        siteEmail = SiteEmail(context, None)

        r = siteEmail.property_from_config(b'DivisionConfiguration',
                                           b'emailSkin')

        self.assertIsNone(r)
    def test_property_from_config(self, mock_set_skin):
        'Test getting a property from a config'
        context = MagicMock(spec=['DivisionConfiguration'])
        context.DivisionConfiguration.getProperty.return_value = self.skinName
        siteEmail = SiteEmail(context, None)

        r = siteEmail.property_from_config(b'DivisionConfiguration',
                                           b'emailSkin')

        self.assertEqual(self.skinName, r)
    def test_property_from_config_missing_property(self, mock_set_skin):
        'Test getting a property when there is no property on the config'
        context = MagicMock(spec=['DivisionConfiguration'])
        context.DivisionConfiguration.getProperty.return_value = None
        siteEmail = SiteEmail(context, None)

        r = siteEmail.property_from_config(b'DivisionConfiguration',
                                           b'emailSkin')

        self.assertIsNone(r)
    def test_mailto_ascii(self):
        'Test the construction of a "mailto" URI with Unicode'
        body = b'This is ASCII text actually'
        subject = b'A message'
        to = b'*****@*****.**'
        siteEmail = SiteEmail(None, None)
        r = siteEmail.mailto(to, subject, body)

        expected = 'mailto:[email protected]?subject=A%20message'\
            '&body=This%20is%20ASCII%20text%20actually'
        self.assertEqual(expected, r)
    def test_mailto_ascii(self):
        'Test the construction of a "mailto" URI with Unicode'
        body = b'This is ASCII text actually'
        subject = b'A message'
        to = b'*****@*****.**'
        siteEmail = SiteEmail(None, None)
        r = siteEmail.mailto(to, subject, body)

        expected = 'mailto:[email protected]?subject=A%20message'\
            '&body=This%20is%20ASCII%20text%20actually'
        self.assertEqual(expected, r)
    def test_mailto(self):
        'Test the construction of a "mailto" URI with Unicode'
        body = 'This is unicode text \u2014 actually'
        subject = 'A message'
        to = '*****@*****.**'
        siteEmail = SiteEmail(None, None)
        r = siteEmail.mailto(to, subject, body)

        expected = 'mailto:[email protected]?subject=A%20message'\
            '&body=This%20is%20unicode%20text%20%E2%80%94%20actually'
        self.assertEqual(expected, r)
    def test_mailto(self):
        'Test the construction of a "mailto" URI with Unicode'
        body = 'This is unicode text \u2014 actually'
        subject = 'A message'
        to = '*****@*****.**'
        siteEmail = SiteEmail(None, None)
        r = siteEmail.mailto(to, subject, body)

        expected = 'mailto:[email protected]?subject=A%20message'\
            '&body=This%20is%20unicode%20text%20%E2%80%94%20actually'
        self.assertEqual(expected, r)
    def test_skin_not_found(self, faux_getUtility, faux_applySkin):
        'Test that we handle a missing skin correctly'
        context = MagicMock(spec=['DivisionConfiguration', 'GlobalConfiguration'])
        request = MagicMock()
        dc = context.DivisionConfiguration
        dc.getProperty.return_value = self.skinName
        siteEmail = SiteEmail(context, request)
        faux_getUtility.side_effect = gs.content.email.base.emailmessage.ComponentLookupError()

        with self.assertRaises(gs.content.email.base.emailmessage.LocationError):
            siteEmail.set_skin()
        faux_getUtility.assert_called_with(
            gs.content.email.base.emailmessage.IBrowserSkinType,
            self.skinName)
    def test_apply_skin(self, faux_getUtility, faux_applySkin):
        'Test that we actually apply the skin'
        context = MagicMock(spec=['DivisionConfiguration', 'GlobalConfiguration'])
        request = MagicMock()
        dc = context.DivisionConfiguration
        dc.getProperty.return_value = self.skinName
        fauxSkin = faux_getUtility()
        siteEmail = SiteEmail(context, request)

        r = siteEmail.set_skin()
        self.assertIsNone(r)
        faux_getUtility.assert_called_with(
            gs.content.email.base.emailmessage.IBrowserSkinType,
            self.skinName)
        faux_applySkin.assert_called_with(request, fauxSkin)
    def test_apply_skin(self, faux_getUtility, faux_applySkin):
        'Test that we actually apply the skin'
        context = MagicMock(
            spec=['DivisionConfiguration', 'GlobalConfiguration'])
        request = MagicMock()
        dc = context.DivisionConfiguration
        dc.getProperty.return_value = self.skinName
        fauxSkin = faux_getUtility()
        siteEmail = SiteEmail(context, request)

        r = siteEmail.set_skin()
        self.assertIsNone(r)
        faux_getUtility.assert_called_with(
            gs.content.email.base.emailmessage.IBrowserSkinType, self.skinName)
        faux_applySkin.assert_called_with(request, fauxSkin)
    def test_skin_not_found(self, faux_getUtility, faux_applySkin):
        'Test that we handle a missing skin correctly'
        context = MagicMock(
            spec=['DivisionConfiguration', 'GlobalConfiguration'])
        request = MagicMock()
        dc = context.DivisionConfiguration
        dc.getProperty.return_value = self.skinName
        siteEmail = SiteEmail(context, request)
        faux_getUtility.side_effect = gs.content.email.base.emailmessage.ComponentLookupError(
        )

        with self.assertRaises(
                gs.content.email.base.emailmessage.LocationError):
            siteEmail.set_skin()
        faux_getUtility.assert_called_with(
            gs.content.email.base.emailmessage.IBrowserSkinType, self.skinName)
    def test_base_url_page(self):
        'Test the base attribute when the URL ends with page.html'
        request = TestRequest(
            ACTUAL_URL='http://groups.example.com/email/page.html',
            URL='http://groups.example.com/email/page.html',
            URL1='http://groups.example.com/email')
        siteEmail = SiteEmail(None, request)

        r = siteEmail.base
        self.assertEqual('http://groups.example.com/email', r)
    def test_skin_name_missing(self, mock_set_skin):
        'Test getting the skin name when it is missing from all config'
        context = MagicMock(
            spec=['DivisionConfiguration', 'GlobalConfiguration'])
        context.DivisionConfiguration.getProperty.return_value = None
        context.GlobalConfiguration.getProperty.return_value = None
        siteEmail = SiteEmail(context, None)

        r = siteEmail.skin_name

        self.assertIsNone(r)
    def test_skin_name_local(self, mock_set_skin):
        'Test getting the skin name when it is in just the division config'
        context = MagicMock(
            spec=['DivisionConfiguration', 'GlobalConfiguration'])
        context.DivisionConfiguration.getProperty.return_value = self.skinName
        context.GlobalConfiguration.getProperty.return_value = None
        siteEmail = SiteEmail(context, None)

        r = siteEmail.skin_name

        self.assertEqual(self.skinName, r)
    def test_skin_name_override(self, mock_set_skin):
        'Test getting the skin name when it is in both the division and global config'
        context = MagicMock(
            spec=['DivisionConfiguration', 'GlobalConfiguration'])
        context.DivisionConfiguration.getProperty.return_value = 'local'
        context.GlobalConfiguration.getProperty.return_value = 'global'
        siteEmail = SiteEmail(context, None)

        r = siteEmail.skin_name

        self.assertEqual('local', r)
 def test_call(self):
     'Test the __call__ method, simulating rendering.'
     gs.content.email.base.emailmessage.SitePage.__call__ = MagicMock(
         return_value=self.withStyle)
     request = TestRequest(
         ACTUAL_URL='http://groups.example.com/email/page.html',
         URL='http://groups.example.com/email/page.html',
         URL1='http://groups.example.com/email')
     siteEmail = SiteEmail(None, request)
     r = siteEmail()
     self.assertEqual(self.discard_whitespace(self.withStyleAttr),
                      self.discard_whitespace(r))
 def test_base_url_awol(self):
     'Test the base-attribute when the URL is missing'
     request = TestRequest()
     siteEmail = SiteEmail(None, request)
     r = siteEmail.base
     self.assertEqual('', r)