示例#1
0
 def test_settings_form(self):
     s = Settings()
     s.save()
     form = SettingsForm(self._create_settings_data(s))
     request = fake_request(path='')
     form.configure(request, s, edit=True)
     self.assertTrue(form.is_valid())
示例#2
0
 def test_has_social_media_should_be_true_if_at_least_one_social_media_is_assigned(
         self):
     settings = Settings()
     for attr, _ in settings.social_links:
         s = Settings()
         setattr(s, attr, 'social-media-url')
         self.assertTrue(s.has_social_media)
示例#3
0
 def test_should_return_html_for_opening_times(self):
     settings = Settings()
     settings.monday_start = datetime.time(9)
     settings.monday_close = datetime.time(17)
     settings.opening_times_enabled = True
     self.assertEqual(
         '<p><span class="opening_times_day">Monday</span><span class="opening_times_col">:</span><span class="opening_times_range">09:00 - 17:00</span></p>',
         opening_times(Context({'settings': settings})))
示例#4
0
    def test_should_contain_reply_to_from_cms_settings(self):
        s = Settings()
        s.enquiry_reply = '*****@*****.**'
        s.save()

        cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>')

        m = self.get_latest_email()
        self.assertTrue(m.extra_headers.get('Reply-To'),
                        '*****@*****.**')
示例#5
0
 def test_settings_form_should_parse_page_size_as_integer(self):
     s = Settings()
     s.save()
     form = SettingsForm(
         self._create_settings_data(s, {
             'page_size': '10',
             'max_page_size': '100'
         }))
     request = fake_request(path='')
     form.configure(request, s, edit=True)
     self.assertTrue(form.is_valid())
     self.assertEqual(10, form.cleaned_data.get('page_size'))
     self.assertEqual(100, form.cleaned_data.get('max_page_size'))
示例#6
0
class CMSModelsDefaultPagesSettingsMixinTestCase(CubaneTestCase):
    def setUp(self):
        self.settings = Settings()

    def test_get_default_pages_pks_should_be_empty_by_default(self):
        self.assertEqual([], self.settings.get_default_pages_pks())

    def test_get_default_pages_pks_should_return_pks_for_default_pages_as_list(
            self):
        home = Page()
        contact = Page()
        _404 = Page()
        enquiry = Page()

        home.save()
        contact.save()
        _404.save()
        enquiry.save()

        self.settings.homepage = home
        self.settings.contact_page = contact
        self.settings.default_404 = _404
        self.settings.enquiry_template = enquiry

        self.assertEqual([home.pk, contact.pk, _404.pk, enquiry.pk],
                         self.settings.get_default_pages_pks())

        home.delete()
        contact.delete()
        _404.delete()
        enquiry.delete()

    def test_get_default_pages_pks_should_return_pks_for_default_pages_as_list_abmitting_not_assigned_pages(
            self):
        contact = Page()
        enquiry = Page()

        contact.save()
        enquiry.save()

        self.settings.contact_page = contact
        self.settings.enquiry_template = enquiry

        self.assertEqual([contact.pk, enquiry.pk],
                         self.settings.get_default_pages_pks())

        contact.delete()
        enquiry.delete()
示例#7
0
 def _create_spf_test_form(self):
     s = Settings()
     s.save()
     form = SettingsForm(
         self._create_settings_data(
             s, {
                 'enquiry_email': '*****@*****.**',
                 'enquiry_from': '*****@*****.**',
                 'enquiry_reply': '*****@*****.**'
             }))
     factory = RequestFactory()
     request = factory.post('/')
     request.session = SessionStore()
     request._messages = FallbackStorage(request)
     form.configure(request, s, edit=True)
     return (request, form)
示例#8
0
 def test_settings_form_should_raise_error_if_enquiry_email_and_reply_to_address_are_the_same(
         self):
     s = Settings()
     s.save()
     form = SettingsForm(
         self._create_settings_data(
             s, {
                 'enquiry_email': '*****@*****.**',
                 'enquiry_from': '*****@*****.**',
                 'enquiry_reply': '*****@*****.**'
             }))
     request = fake_request(path='')
     form.configure(request, s, edit=True)
     self.assertFalse(form.is_valid())
     self.assertFormFieldError(
         form, 'enquiry_from',
         SettingsForm.ERROR_FROM_EMAIL_CANNOT_BE_THE_SAME_AS_ENQUIRY_EMAIL)
示例#9
0
class CMSModelsPaginationSettingsMixinTestCase(CubaneTestCase):
    def setUp(self):
        self.settings = Settings()
        self.settings.paging_enabled = True
        self.settings.paging_child_pages = 'testapp_customchildpage'

    def test_pagination_should_be_enabled_if_enabled_in_general_and_child_page_is_enabled(
            self):
        self.assertTrue(self.settings.paging_enabled_for(CustomChildPage))

    def test_pagination_should_be_disabled_if_disabled_in_general(self):
        self.settings.paging_enabled = False
        self.assertFalse(self.settings.paging_enabled_for(CustomChildPage))

    def test_pagination_should_be_disabled_if_child_page_not_enabled(self):
        self.settings.paging_child_pages = None
        self.assertFalse(self.settings.paging_enabled_for(CustomChildPage))
示例#10
0
 def test_settings_form_should_fail_if_max_page_size_it_lower_than_page_size(
         self):
     s = Settings()
     s.save()
     form = SettingsForm(
         self._create_settings_data(s, {
             'page_size': '10',
             'max_page_size': '5'
         }))
     request = fake_request(path='')
     form.configure(request, s, edit=True)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         {
             'max_page_size':
             ['Max. page size needs to be at least the page size of 10.']
         }, form.errors)
示例#11
0
 def test_should_return_contact_map_html(self):
     settings = Settings()
     settings.lat = '52.6757648'
     settings.lng = '1.3737302'
     settings.zoom = '8'
     settings.name = 'map'
     settings.save()
     content = Template("{% load cms_tags %} {% contact_map %}").render(
         Context({'settings': settings}))
     self.assertEqual(
         u' <div class="enquiry-map-canvas" data-key="foo" data-lat="52.6757648" data-lng="1.3737302" data-title="map" data-zoom="8"></div>',
         content)
示例#12
0
    def test_should_render_cms_page_and_dispatch_email(self):
        page = Page()
        page.title = 'Test Page'
        page.slug = 'test'
        page.template = 'testapp/mail/enquiry_visitor.html'
        page.set_slot_content('content', '<h1>Test</h1>')
        page.save()

        settings = Settings()
        settings.shop_email_template = page
        settings.save()

        cubane_send_shop_mail(None, '*****@*****.**', 'Test')

        m = self.get_latest_email()
        self.assertTrue('*****@*****.**' in m.to, 'to address not found')
        self.assertEqual(m.subject, 'Test')
        self.assertTrue('<html><head><title>' in m.message().as_string())
        self.assertTrue('<h1>Test</h1>' in m.message().as_string())
示例#13
0
 def _settings(self, name, meta_name=None):
     settings = Settings()
     settings.name = name
     settings.meta_name = meta_name
     return settings
示例#14
0
 def test_should_return_html(self):
     settings = Settings()
     settings.twitter = 'Innershed'
     self.assertEqual(
         '<div class="automated-social-links"><a href="Innershed" target="_blank"><svg viewBox="0 0 64 64" id="icon-twitter" class="icon-social icon-social-twitter"><path d="M32,0C14.3,0,0,14.3,0,32c0,17.7,14.3,32,32,32c17.7,0,32-14.3,32-32C64,14.3,49.7,0,32,0z M45,26.2c0,0.3,0,0.5,0,0.8\n\tC45,35.4,38.7,45,27.1,45c-3.6,0-6.9-1-9.7-2.8c0.5,0.1,1,0.1,1.5,0.1c3,0,5.7-1,7.8-2.7c-2.8-0.1-5.1-1.9-5.9-4.4\n\tc0.4,0.1,0.8,0.1,1.2,0.1c0.6,0,1.1-0.1,1.7-0.2c-2.9-0.6-5.1-3.1-5.1-6.2c0,0,0-0.1,0-0.1c0.8,0.5,1.8,0.8,2.9,0.8\n\tc-1.7-1.1-2.8-3.1-2.8-5.2c0-1.2,0.3-2.2,0.9-3.2c3.1,3.8,7.8,6.3,13,6.6c-0.1-0.5-0.2-0.9-0.2-1.4c0-3.5,2.8-6.3,6.3-6.3\n\tc1.8,0,3.5,0.8,4.6,2c1.4-0.3,2.8-0.8,4-1.5c-0.5,1.5-1.5,2.7-2.8,3.5c1.3-0.2,2.5-0.5,3.6-1C47.3,24.2,46.2,25.3,45,26.2z"/></svg></a></div>',
         social_media_links(Context({'settings': settings})))
示例#15
0
 def _settings(self):
     settings = Settings()
     settings.mailchimp_api = 'fake-api'
     settings.mailchimp_list_id = 'fake-list-id'
     return settings
示例#16
0
 def setUp(self):
     self.settings = Settings()
示例#17
0
class CMSModelsOpeningTimesSettingsMixinTestCase(CubaneTestCase):
    def setUp(self):
        self.settings = Settings()

    def test_weekday_names(self):
        self.assertEqual([
            'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday',
            'sunday'
        ], self.settings.full_week_days)

    def test_set_opening_time_with_invalid_day_should_return_false(self):
        self.assertFalse(
            self.settings.set_opening_time('does-not_exist', 'start', '09:00'))

    def test_set_opening_time_with_invalid_bound_should_return_false(self):
        self.assertFalse(
            self.settings.set_opening_time('friday', 'does-not-exist',
                                           '09:00'))

    def test_set_opening_time_with_invalid_value_should_return_false(self):
        self.assertFalse(self.settings.set_opening_time('friday', 'start', 15))

    def test_opening_times_should_return_all_opening_times(self):
        self.settings.set_opening_times(self.settings.week_days, '09:00',
                                        '17:00')
        self.settings.set_opening_times(self.settings.weekend_days, '10:00',
                                        '16:00')
        self.assertEqual([('monday', datetime(1900, 1, 1, 9,
                                              0), datetime(1900, 1, 1, 17, 0)),
                          ('tuesday', datetime(
                              1900, 1, 1, 9, 0), datetime(1900, 1, 1, 17, 0)),
                          ('wednesday', datetime(
                              1900, 1, 1, 9, 0), datetime(1900, 1, 1, 17, 0)),
                          ('thursday', datetime(
                              1900, 1, 1, 9, 0), datetime(1900, 1, 1, 17, 0)),
                          ('friday', datetime(1900, 1, 1, 9,
                                              0), datetime(1900, 1, 1, 17, 0)),
                          ('saturday', datetime(
                              1900, 1, 1, 10, 0), datetime(1900, 1, 1, 16, 0)),
                          ('sunday', datetime(1900, 1, 1, 10, 0),
                           datetime(1900, 1, 1, 16, 0))],
                         self.settings.opening_times)

    def test_same_opening_times_for_weekdays_should_return_true_if_same_opening_times(
            self):
        self.settings.set_opening_times(self.settings.full_week_days, '09:00',
                                        '17:00')
        self.assertTrue(self.settings.same_opening_times_for_weekdays)

    def test_same_opening_times_for_weekdays_should_return_false_if_not_same_opening_times(
            self):
        self.settings.set_opening_times(self.settings.week_days, '09:00',
                                        '17:00')
        self.settings.set_opening_times('friday', '10:00', '16:00')
        self.assertFalse(self.settings.same_opening_times_for_weekdays)
示例#18
0
 def setUp(self):
     self.settings = Settings()
     self.settings.paging_enabled = True
     self.settings.paging_child_pages = 'testapp_customchildpage'
示例#19
0
 def test_has_social_media_should_be_false_if_no_social_media_assigned(
         self):
     s = Settings()
     self.assertFalse(s.has_social_media)
示例#20
0
 def test_should_return_empty_string_without_mailchimp_api(self):
     settings = Settings()
     self.assertEqual(
         '', newsletter_signup_form_ajax(Context({'settings': settings})))