Пример #1
0
    def test_6_banners(self):
        """Only 6 banners should be included in the banner set."""
        for k in range(10):
            FacebookBannerLocaleFactory.create(locale='en-US')
        response = self._pre_auth_promo('en-US')

        eq_(len(response.context['banners']), 6)
Пример #2
0
    def test_6_banners(self):
        """Only 6 banners should be included in the banner set."""
        for k in range(10):
            FacebookBannerLocaleFactory.create(locale='en-US')
        response = self._pre_auth_promo('en-US')

        eq_(len(response.context['banners']), 6)
Пример #3
0
    def test_locale_banners(self):
        """Ensure that the banners used by the page match the user's locale."""
        banner1 = FacebookBannerLocaleFactory.create(locale='fr').banner
        banner2 = FacebookBannerLocaleFactory.create(locale='fr').banner
        FacebookBannerLocaleFactory.create(locale='en-US')
        response = self._pre_auth_promo('fr')

        eq_(list(response.context['banners']), [banner1, banner2])
Пример #4
0
    def test_locale_banners(self):
        """Ensure that the banners used by the page match the user's locale."""
        banner1 = FacebookBannerLocaleFactory.create(locale='fr').banner
        banner2 = FacebookBannerLocaleFactory.create(locale='fr').banner
        FacebookBannerLocaleFactory.create(locale='en-US')
        response = self._pre_auth_promo('fr')

        eq_(list(response.context['banners']), [banner1, banner2])
Пример #5
0
 def test_image_for_locale_found(self):
     """
     If the banner is available in the requested locale, return the image for
     that locale.
     """
     banner = FacebookBannerFactory.create(image='banner')
     FacebookBannerLocaleFactory.create(banner=banner, locale='pt-BR',
                                        image='locale')
     ok_(banner.image_for_locale('pt-BR').name.endswith('locale'))
Пример #6
0
 def test_image_for_locale_blank_default(self):
     """
     If a banner is available in the requested locale but the image is blank,
     return the default image.
     """
     banner = FacebookBannerFactory.create(image='banner')
     FacebookBannerLocaleFactory.create(banner=banner, locale='es',
                                        image='')
     ok_(banner.image_for_locale('es').name.endswith('banner'))
Пример #7
0
 def test_fallback_locales(self):
     """
     If a banner is available across a language and the user is using a
     specific subset of that locale (e.g. banner is in de and user is using
     de-at), the user should be presented with that banner as an option.
     """
     FacebookBannerLocaleFactory.create(locale='de')
     form = self.form('de-at')
     eq_(len(form.fields['banner'].choices), 1)
Пример #8
0
 def test_fallback_locales(self):
     """
     If a banner is available across a language and the user is using a
     specific subset of that locale (e.g. banner is in de and user is using
     de-at), the user should be presented with that banner as an option.
     """
     FacebookBannerLocaleFactory.create(locale='de')
     form = self.form('de-at')
     eq_(len(form.fields['banner'].choices), 1)
Пример #9
0
 def test_image_for_locale_found(self):
     """
     If the banner is available in the requested locale, return the image for
     that locale.
     """
     banner = FacebookBannerFactory.create(image='banner')
     FacebookBannerLocaleFactory.create(banner=banner,
                                        locale='pt-BR',
                                        image='locale')
     ok_(banner.image_for_locale('pt-BR').name.endswith('locale'))
Пример #10
0
 def test_image_for_locale_blank_default(self):
     """
     If a banner is available in the requested locale but the image is blank,
     return the default image.
     """
     banner = FacebookBannerFactory.create(image='banner')
     FacebookBannerLocaleFactory.create(banner=banner,
                                        locale='es',
                                        image='')
     ok_(banner.image_for_locale('es').name.endswith('banner'))
Пример #11
0
    def test_default_locale(self):
        """
        If no banners are available in the requested locale, default to the
        site's default language code.
        """
        banner1 = FacebookBannerLocaleFactory.create(locale='fr').banner
        banner2 = FacebookBannerLocaleFactory.create(locale='fr').banner
        response = self._pre_auth_promo('pt-BR')

        eq_(list(response.context['banners']), [banner1, banner2])
Пример #12
0
 def test_image_for_locale_fallback(self):
     """
     If the banner is available in a certain language and the requested
     locale is a subset of that language that isn't available, return the
     image for the fallback language.
     """
     banner = FacebookBannerFactory.create(image='banner')
     FacebookBannerLocaleFactory.create(banner=banner, locale='de',
                                        image='locale')
     ok_(banner.image_for_locale('de-ch').name.endswith('locale'))
Пример #13
0
    def test_default_locale(self):
        """
        If no banners are available in the requested locale, default to the
        site's default language code.
        """
        banner1 = FacebookBannerLocaleFactory.create(locale='fr').banner
        banner2 = FacebookBannerLocaleFactory.create(locale='fr').banner
        response = self._pre_auth_promo('pt-BR')

        eq_(list(response.context['banners']), [banner1, banner2])
Пример #14
0
 def test_image_for_locale_fallback(self):
     """
     If the banner is available in a certain language and the requested
     locale is a subset of that language that isn't available, return the
     image for the fallback language.
     """
     banner = FacebookBannerFactory.create(image='banner')
     FacebookBannerLocaleFactory.create(banner=banner,
                                        locale='de',
                                        image='locale')
     ok_(banner.image_for_locale('de-ch').name.endswith('locale'))
Пример #15
0
    def test_no_locale(self):
        """
        If the request has no set locale, the form should accept any banner in
        any locale.
        """
        fr_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=fr_banner, locale='fr')
        en_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=en_banner, locale='en-us')

        form = self.form(None, {'text': 'asdf', 'banner': fr_banner.id})
        ok_(form.is_valid())

        form = self.form(None, {'text': 'asdf', 'banner': en_banner.id})
        ok_(form.is_valid())
Пример #16
0
    def test_with_locale(self):
        """
        If the request has a set locale, the form should only accept banners
        available in that locale.
        """
        fr_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=fr_banner, locale='fr')
        en_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=en_banner, locale='en-us')

        form = self.form('fr', {'text': 'asdf', 'banner': fr_banner.id})
        ok_(form.is_valid())

        form = self.form('fr', {'text': 'asdf', 'banner': en_banner.id})
        ok_(not form.is_valid())
Пример #17
0
    def test_with_locale(self):
        """
        If the request has a set locale, the form should only accept banners
        available in that locale.
        """
        fr_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=fr_banner, locale='fr')
        en_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=en_banner, locale='en-us')

        form = self.form('fr', {'text': 'asdf', 'banner': fr_banner.id})
        ok_(form.is_valid())

        form = self.form('fr', {'text': 'asdf', 'banner': en_banner.id})
        ok_(not form.is_valid())
Пример #18
0
    def test_no_locale(self):
        """
        If the request has no set locale, the form should accept any banner in
        any locale.
        """
        fr_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=fr_banner, locale='fr')
        en_banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=en_banner, locale='en-us')

        form = self.form(None, {'text': 'asdf', 'banner': fr_banner.id})
        ok_(form.is_valid())

        form = self.form(None, {'text': 'asdf', 'banner': en_banner.id})
        ok_(form.is_valid())
Пример #19
0
    def test_use_profile_image(self, delay):
        """
        If the user checked `use_profile_image`, create a banner instance,
        trigger the celery task and return a 202 Accepted.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id,
                                      text='asdf',
                                      next_action='',
                                      use_profile_image=True)

        # Asserts that banner instance exists.
        instance = FacebookBannerInstance.objects.get(banner=banner,
                                                      user=self.user)
        delay.assert_called_with(instance.id)

        # Assert response contians the expected links.
        eq_(response.status_code, 202)
        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banner_list')))
            eq_(
                response_data['check_url'],
                reverse('facebook.banners.create_image_check',
                        args=[instance.id]))
Пример #20
0
 def test_save_locale(self):
     """The form should save the current locale on the instance."""
     locale = FacebookBannerLocaleFactory.create(locale='es')
     with self.activate('es'):
         form = self.form('es', {'text': 'asdf', 'banner': locale.banner.id},
                          user=FacebookUserFactory.create())
         instance = form.save()
         eq_(instance.locale, 'es')
Пример #21
0
 def test_save_locale(self):
     """The form should save the current locale on the instance."""
     locale = FacebookBannerLocaleFactory.create(locale='es')
     with self.activate('es'):
         form = self.form('es', {
             'text': 'asdf',
             'banner': locale.banner.id
         },
                          user=FacebookUserFactory.create())
         instance = form.save()
         eq_(instance.locale, 'es')
Пример #22
0
    def test_similar_locales(self):
        """
        Regression test for a bug where a user in the de locale would get a
        banner choice for each de locale (de, de-at, de-ch, de-de), causing
        duplicate choices and form processing errors.
        """
        banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=banner, locale='de')
        FacebookBannerLocaleFactory.create(banner=banner, locale='de-at')
        FacebookBannerLocaleFactory.create(banner=banner, locale='de-ch')
        FacebookBannerLocaleFactory.create(banner=banner, locale='de-de')

        form = self.form('de')
        eq_(len(form.fields['banner'].choices), 1)
Пример #23
0
    def test_similar_locales(self):
        """
        Regression test for a bug where a user in the de locale would get a
        banner choice for each de locale (de, de-at, de-ch, de-de), causing
        duplicate choices and form processing errors.
        """
        banner = FacebookBannerFactory.create()
        FacebookBannerLocaleFactory.create(banner=banner, locale='de')
        FacebookBannerLocaleFactory.create(banner=banner, locale='de-at')
        FacebookBannerLocaleFactory.create(banner=banner, locale='de-ch')
        FacebookBannerLocaleFactory.create(banner=banner, locale='de-de')

        form = self.form('de')
        eq_(len(form.fields['banner'].choices), 1)
Пример #24
0
    def test_filter_by_locale_basic(self):
        banner1 = FacebookBannerLocaleFactory.create(locale='en-US').banner
        banner2 = FacebookBannerLocaleFactory.create(locale='en-US').banner
        FacebookBannerLocaleFactory.create(locale='fr').banner
        FacebookBannerLocaleFactory.create(locale='pt-BR').banner
        results = FacebookBanner.objects.all().filter_by_locale('en-US')

        eq_(list(results), [banner1, banner2])
Пример #25
0
    def test_no_profile_image(self):
        """
        If the user did not check `use_profile_image`, create the banner
        instance and return a 201 Created.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id, text='asdf',
                                      next_action='', use_profile_image=False)
        ok_(FacebookBannerInstance.objects.filter(banner=banner, user=self.user)
            .exists())

        eq_(response.status_code, 201)
        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banner_list')))
Пример #26
0
    def test_save_and_share(self):
        """
        If the user clicks the `Save and Share` button, the `next` link should
        point to the share page for the new banner instance.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id, text='asdf',
                                      next_action='share',
                                      use_profile_image=False)
        instance = FacebookBannerInstance.objects.get(banner=banner,
                                                      user=self.user)

        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banners.share',
                           args=[instance.id])))
Пример #27
0
    def test_no_profile_image(self):
        """
        If the user did not check `use_profile_image`, create the banner
        instance and return a 201 Created.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id,
                                      text='asdf',
                                      next_action='',
                                      use_profile_image=False)
        ok_(
            FacebookBannerInstance.objects.filter(banner=banner,
                                                  user=self.user).exists())

        eq_(response.status_code, 201)
        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banner_list')))
Пример #28
0
    def test_save_and_share(self):
        """
        If the user clicks the `Save and Share` button, the `next` link should
        point to the share page for the new banner instance.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id,
                                      text='asdf',
                                      next_action='share',
                                      use_profile_image=False)
        instance = FacebookBannerInstance.objects.get(banner=banner,
                                                      user=self.user)

        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(
                response_data['next'],
                absolutify(
                    reverse('facebook.banners.share', args=[instance.id])))
Пример #29
0
    def test_use_profile_image(self, delay):
        """
        If the user checked `use_profile_image`, create a banner instance,
        trigger the celery task and return a 202 Accepted.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id, text='asdf',
                                      next_action='', use_profile_image=True)

        # Asserts that banner instance exists.
        instance = FacebookBannerInstance.objects.get(banner=banner,
                                                      user=self.user)
        delay.assert_called_with(instance.id)

        # Assert response contians the expected links.
        eq_(response.status_code, 202)
        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banner_list')))
            eq_(response_data['check_url'],
                reverse('facebook.banners.create_image_check',
                        args=[instance.id]))