def test_get_user_agent_distroseries_when_invalid(self):
        """None should be returned when the version is not matched."""
        user_agent = ('Mozilla/5.0 '
                      '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                      'Gecko/2009042523 Ubuntu/10a.09 (whatever) '
                      'Firefox/3.0.10')

        version = get_user_agent_distroseries(user_agent)
        self.failUnless(version is None,
                        "None should be returned when the match fails.")
    def test_get_user_agent_distroseries_when_present(self):
        """The version number is returned when present."""
        user_agent = ('Mozilla/5.0 '
                      '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                      'Gecko/2009042523 Ubuntu/10.09 (whatever) '
                      'Firefox/3.0.10')

        version = get_user_agent_distroseries(user_agent)
        self.failUnlessEqual('10.09', version,
                             "Incorrect version string returned.")
Esempio n. 3
0
    def test_get_user_agent_distroseries_when_invalid(self):
        """None should be returned when the version is not matched."""
        user_agent = ('Mozilla/5.0 '
                      '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                      'Gecko/2009042523 Ubuntu/10a.09 (whatever) '
                      'Firefox/3.0.10')

        version = get_user_agent_distroseries(user_agent)
        self.assertIsNone(version,
                          "None should be returned when the match fails.")
Esempio n. 4
0
    def test_get_user_agent_distroseries_when_present(self):
        """The version number is returned when present."""
        user_agent = ('Mozilla/5.0 '
                      '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                      'Gecko/2009042523 Ubuntu/10.09 (whatever) '
                      'Firefox/3.0.10')

        version = get_user_agent_distroseries(user_agent)
        self.assertEqual('10.09', version,
                         "Incorrect version string returned.")
Esempio n. 5
0
    def default_series(self):
        """Return the default series for this view."""
        # If we have not been provided with any valid distroseries, then
        # we return the currentseries of the distribution.
        if len(self.terms) == 0:
            return self.context.distribution.currentseries

        # If we only have one series then we have no choice...just return it.
        elif len(self.terms) == 1:
            return self.terms[0].value

        # If the caller has indicated that there should not be a default
        # distroseries selected then we return None.
        elif self._initially_without_selection:
            return None

        # Otherwise, if the request's user-agent includes the Ubuntu version
        # number, we check for a corresponding valid distroseries and, if one
        # is found, return it's name.
        version_number = get_user_agent_distroseries(
            self.request.getHeader('HTTP_USER_AGENT'))

        if version_number is not None:

            # Finally, check if this version is one of the available
            # distroseries for this archive:
            for term in self.terms:
                if (term.value is not None
                        and term.value.version == version_number):
                    return term.value

        # If we were not able to get the users distribution series, then
        # either they are running a different OS, or they are running a
        # very old version of Ubuntu, or they have explicitly tampered
        # with user-agent headers in their browser. In any case,
        # we won't try to guess a value, but instead force them to
        # select one.
        return None
Esempio n. 6
0
    def default_series(self):
        """Return the default series for this view."""
        # If we have not been provided with any valid distroseries, then
        # we return the currentseries of the distribution.
        if len(self.terms) == 0:
            return self.context.distribution.currentseries

        # If we only have one series then we have no choice...just return it.
        elif len(self.terms) == 1:
            return self.terms[0].value

        # If the caller has indicated that there should not be a default
        # distroseries selected then we return None.
        elif self._initially_without_selection:
            return None

        # Otherwise, if the request's user-agent includes the Ubuntu version
        # number, we check for a corresponding valid distroseries and, if one
        # is found, return it's name.
        version_number = get_user_agent_distroseries(
            self.request.getHeader('HTTP_USER_AGENT'))

        if version_number is not None:

            # Finally, check if this version is one of the available
            # distroseries for this archive:
            for term in self.terms:
                if (term.value is not None and
                    term.value.version == version_number):
                    return term.value

        # If we were not able to get the users distribution series, then
        # either they are running a different OS, or they are running a
        # very old version of Ubuntu, or they have explicitly tampered
        # with user-agent headers in their browser. In any case,
        # we won't try to guess a value, but instead force them to
        # select one.
        return None