Exemple #1
0
    def test_get_configuration_value_for_site_with_configuration(self):
        """
        ``get_configuration_value_for_site`` returns the key's value or the default in the site configuration.

        We do not test whether we get back the key's value or the default in particular, but just that
        the function returns a value through the configuration, rather than the default.
        """
        site = SiteFactory()
        site.configuration = mock.MagicMock(get_value=mock.MagicMock(
            return_value='value'))
        assert utils.get_configuration_value_for_site(site, 'key',
                                                      'default') == 'value'
Exemple #2
0
    def test_send_email_notification_message_with_site_from_email_override(
            self, site_config_from_email_address, expected_from_email_address):
        """
        Test that we can successfully override a from email address per site.
        """
        user = UserFactory(username='******',
                           email='*****@*****.**',
                           first_name='sal')
        enrolled_in = {
            'name': 'Demo Course',
            'url': 'http://lms.example.com/courses',
            'type': 'course',
            'start': '2017-01-01'
        }
        enrolled_in['start'] = datetime.datetime.strptime(
            enrolled_in['start'], '%Y-%m-%d')

        site = SiteFactory()
        if site_config_from_email_address:
            site.configuration = mock.MagicMock(get_value=mock.MagicMock(
                return_value=site_config_from_email_address))

        enterprise_customer = mock.MagicMock(
            name='Example Corporation',
            enterprise_enrollment_template=mock.MagicMock(
                render_all_templates=mock.MagicMock(return_value=((
                    'plaintext_value',
                    '<b>HTML value</b>',
                ))),
                subject_line='New course! {course_name}!'),
            site=site)

        conn = mail.get_connection()
        utils.send_email_notification_message(
            user,
            enrolled_in,
            enterprise_customer,
            email_connection=conn,
        )

        assert len(mail.outbox) == 1
        assert getattr(mail.outbox[0],
                       'from_email') == expected_from_email_address
        assert mail.outbox[0].connection is conn