Beispiel #1
0
    def _pre_setup(self):
        # Add the models to the db.
        self._original_installed_apps = list(settings.INSTALLED_APPS)
        for app in self.apps:
            settings.INSTALLED_APPS.append(app)
        loading.cache.loaded = False
        call_command('syncdb', interactive=False, verbosity=0)
        call_command('update_badges', verbosity=0)
        badger.autodiscover()

        if get_url_prefix:
            # If we're in funfactoryland, make sure a locale prefix is
            # set for urlresolvers
            locale = 'en-US'
            self.old_prefix = get_url_prefix()
            self.old_locale = get_language()
            rf = RequestFactory()
            set_url_prefix(Prefixer(rf.get('/%s/' % (locale, ))))
            activate(locale)

        # Create a default user for tests
        self.user_1 = self._get_user(username="******",
                                     email="*****@*****.**",
                                     password="******")

        # Call the original method that does the fixtures etc.
        super(test.TestCase, self)._pre_setup()
Beispiel #2
0
    def _pre_setup(self):
        # Add the models to the db.
        self._original_installed_apps = list(settings.INSTALLED_APPS)
        for app in self.apps:
            settings.INSTALLED_APPS.append(app)
        loading.cache.loaded = False
        call_command('syncdb', interactive=False, verbosity=0)
        call_command('update_badges', verbosity=0)
        badger.autodiscover()

        if get_url_prefix:
            # If we're in funfactoryland, make sure a locale prefix is 
            # set for urlresolvers
            locale = 'en-US'
            self.old_prefix = get_url_prefix()
            self.old_locale = get_language()
            rf = RequestFactory()
            set_url_prefix(Prefixer(rf.get('/%s/' % (locale,))))
            activate(locale)

        # Create a default user for tests
        self.user_1 = self._get_user(username="******",
                                     email="*****@*****.**",
                                     password="******")

        # Call the original method that does the fixtures etc.
        super(test.TestCase, self)._pre_setup()
Beispiel #3
0
    def test_localized_search_plugin(self):
        """Every locale gets its own plugin."""
        response = self.client.get(reverse('search_plugin'))
        assert '/en-US/search' in response.content

        # Prefixer and its locale are sticky; clear it before the next request
        set_url_prefix(None)
        response = self.client.get(reverse('search_plugin', prefix='/fr/'))
        assert '/fr/search' in response.content
Beispiel #4
0
    def test_localized_search_plugin(self):
        """Every locale gets its own plugin."""
        response = self.client.get(reverse('search_plugin'))
        assert '/en-US/search' in response.content

        # Prefixer and its locale are sticky; clear it before the next request
        set_url_prefix(None)
        response = self.client.get(reverse('search_plugin', prefix='/fr/'))
        assert '/fr/search' in response.content
Beispiel #5
0
 def activate(self, locale):
     """Context manager that temporarily activates a locale."""
     old_prefix = get_url_prefix()
     old_locale = get_language()
     rf = test_utils.RequestFactory()
     set_url_prefix(Prefixer(rf.get('/%s/' % (locale, ))))
     activate(locale)
     yield
     set_url_prefix(old_prefix)
     activate(old_locale)
Beispiel #6
0
 def activate(self, locale):
     """Context manager that temporarily activates a locale."""
     old_prefix = get_url_prefix()
     old_locale = get_language()
     rf = test_utils.RequestFactory()
     set_url_prefix(Prefixer(rf.get('/%s/' % (locale,))))
     activate(locale)
     yield
     set_url_prefix(old_prefix)
     activate(old_locale)
Beispiel #7
0
    def _post_teardown(self):
        # Call the original method.
        super(test.TestCase, self)._post_teardown()
        # Restore the settings.
        settings.INSTALLED_APPS = self._original_installed_apps
        loading.cache.loaded = False

        if get_url_prefix:
            # If we're in funfactoryland, back out of the locale tweaks
            set_url_prefix(self.old_prefix)
            activate(self.old_locale)
Beispiel #8
0
    def _post_teardown(self):
        # Call the original method.
        super(test.TestCase, self)._post_teardown()

        Award.objects.all().delete()
        Badge.objects.all().delete()

        loading.cache.loaded = False

        if get_url_prefix:
            # If we're in funfactoryland, back out of the locale tweaks
            set_url_prefix(self.old_prefix)
Beispiel #9
0
    def _post_teardown(self):
        # Call the original method.
        super(test.TestCase, self)._post_teardown()

        Award.objects.all().delete()
        Badge.objects.all().delete()

        loading.cache.loaded = False

        if get_url_prefix:
            # If we're in funfactoryland, back out of the locale tweaks
            set_url_prefix(self.old_prefix)
Beispiel #10
0
    def _post_teardown(self):
        # Call the original method.
        super(test.TestCase, self)._post_teardown()

        Award.objects.all().delete()
        Badge.objects.all().delete()

        # Restore the settings.
        settings.INSTALLED_APPS = self._original_installed_apps
        loading.cache.loaded = False

        if get_url_prefix:
            # If we're in funfactoryland, back out of the locale tweaks
            set_url_prefix(self.old_prefix)
            activate(self.old_locale)
Beispiel #11
0
    def _pre_setup(self):
        loading.cache.loaded = False
        call_command('update_badges', verbosity=0)
        badger.autodiscover()

        if get_url_prefix:
            # If we're in funfactoryland, make sure a locale prefix is
            # set for urlresolvers
            locale = 'en-US'
            self.old_prefix = get_url_prefix()
            self.old_locale = get_language()
            rf = RequestFactory()
            set_url_prefix(Prefixer(rf.get('/%s/' % (locale,))))

        # Create a default user for tests
        self.user_1 = self._get_user(username="******",
                                     email="*****@*****.**",
                                     password="******")

        # Call the original method that does the fixtures etc.
        super(test.TestCase, self)._pre_setup()
Beispiel #12
0
    def _pre_setup(self):
        loading.cache.loaded = False
        call_command('update_badges', verbosity=0)
        badger.autodiscover()

        if get_url_prefix:
            # If we're in funfactoryland, make sure a locale prefix is
            # set for urlresolvers
            locale = 'en-US'
            self.old_prefix = get_url_prefix()
            self.old_locale = get_language()
            rf = RequestFactory()
            set_url_prefix(Prefixer(rf.get('/%s/' % (locale,))))

        # Create a default user for tests
        self.user_1 = self._get_user(username="******",
                                     email="*****@*****.**",
                                     password="******")

        # Call the original method that does the fixtures etc.
        super(test.TestCase, self)._pre_setup()
Beispiel #13
0
def well_known_browserid(request):
    # HACK: The following code is terrible. But, I really wanted some
    # locale-free URLs, in order to force a locale redirect later.
    op = get_url_prefix()
    np = Prefixer(request)
    np.locale = 'XXX'
    set_url_prefix(np)
    authentication_url=reverse('whuru.browserid.sign_in').replace('/XXX','')
    provisioning_url=reverse('whuru.browserid.provision').replace('/XXX','')
    set_url_prefix(op)

    settings_root = os.path.dirname(whuru.settings.__file__)
    public_key_fn = os.path.join(settings_root, 'key.publickey')
    public_key = open(public_key_fn, 'rb').read()

    resp = render(request, 'browserid/well-known-browserid.json', dict(
        public_key=public_key,
        authentication_url=authentication_url,
        provisioning_url=provisioning_url,
    ))
    resp['Content-Type'] = 'application/json'
    return resp
Beispiel #14
0
def lang_activate(locale):
    """
    Context manager that temporarily activates a locale.

    This is slightly different from use_lang, as it also sets the global
    prefixer used by reverse to determine the locale in urls. We don't use that
    in non-test code because it creates a test request using Django test code.

    This means that use_lang does not affect reverse. We get around that with a
    hack of using the lang GET argument when necessary, but this really should
    be fixed someday.
    """
    if not locale:
        yield
    else:
        old_prefix = get_url_prefix()
        old_locale = get_language()
        rf = test_utils.RequestFactory()
        set_url_prefix(Prefixer(rf.get('/%s/' % (locale, ))))
        activate(locale)
        yield
        set_url_prefix(old_prefix)
        activate(old_locale)
Beispiel #15
0
def lang_activate(locale):
    """
    Context manager that temporarily activates a locale.

    This is slightly different from use_lang, as it also sets the global
    prefixer used by reverse to determine the locale in urls. We don't use that
    in non-test code because it creates a test request using Django test code.

    This means that use_lang does not affect reverse. We get around that with a
    hack of using the lang GET argument when necessary, but this really should
    be fixed someday.
    """
    if not locale:
        yield
    else:
        old_prefix = get_url_prefix()
        old_locale = get_language()
        rf = test_utils.RequestFactory()
        set_url_prefix(Prefixer(rf.get('/%s/' % (locale,))))
        activate(locale)
        yield
        set_url_prefix(old_prefix)
        activate(old_locale)
Beispiel #16
0
def well_known_browserid(request):
    # HACK: The following code is terrible. But, I really wanted some
    # locale-free URLs, in order to force a locale redirect later.
    op = get_url_prefix()
    np = Prefixer(request)
    np.locale = 'XXX'
    set_url_prefix(np)
    authentication_url = reverse('whuru.browserid.sign_in').replace('/XXX', '')
    provisioning_url = reverse('whuru.browserid.provision').replace('/XXX', '')
    set_url_prefix(op)

    settings_root = os.path.dirname(whuru.settings.__file__)
    public_key_fn = os.path.join(settings_root, 'key.publickey')
    public_key = open(public_key_fn, 'rb').read()

    resp = render(
        request, 'browserid/well-known-browserid.json',
        dict(
            public_key=public_key,
            authentication_url=authentication_url,
            provisioning_url=provisioning_url,
        ))
    resp['Content-Type'] = 'application/json'
    return resp