class TestOneDistroSeriesOnly(TestCaseWithFactory):
    """Ensure the correct behaviour when only one distro series is present.
    """
    layer = LaunchpadFunctionalLayer

    def setUp(self):
        TestCaseWithFactory.setUp(self)
        self.distribution = self.factory.makeDistribution(name='ibuntu')

        # Ensure there is only one series available.
        self.series = [
            self.factory.makeDistroSeries(name="feasty", version='9.04'),
        ]
        self.entries = SourcesListEntries(self.distribution,
                                          'http://example.com/my/archive',
                                          self.series)

        self.view = SourcesListEntriesView(self.entries,
                                           LaunchpadTestRequest())
        self.view.initialize()

    def testNoSelectorForOneSeries(self):
        # The selector should not be presented when there is only one series

        self.failUnless(self.view.sources_in_more_than_one_series is False)

    def testDefaultDistroSeries(self):
        # When there is only one distro series it should always be the
        # default.
        self.failUnless(self.view.default_series == self.series[0])
    def testDefaultWithoutUserAgent(self):
        # If there is no user-agent setting, then we force the user
        # to make a selection.
        view = SourcesListEntriesView(self.entries, LaunchpadTestRequest())
        view.initialize()

        self.assertEqual('YOUR_IBUNTU_VERSION_HERE', view.default_series_name)
    def testDefaultWithoutUserAgent(self):
        # If there is no user-agent setting, then we force the user
        # to make a selection.
        view = SourcesListEntriesView(self.entries, LaunchpadTestRequest())
        view.initialize()

        self.assertEqual('YOUR_IBUNTU_VERSION_HERE', view.default_series_name)
class TestOneDistroSeriesOnly(TestCaseWithFactory):
    """Ensure the correct behaviour when only one distro series is present.
    """
    layer = LaunchpadFunctionalLayer

    def setUp(self):
        TestCaseWithFactory.setUp(self)
        self.distribution = self.factory.makeDistribution(name='ibuntu')

        # Ensure there is only one series available.
        self.series = [
            self.factory.makeDistroSeries(name="feasty", version='9.04'),
            ]
        self.entries = SourcesListEntries(
            self.distribution, 'http://example.com/my/archive',
            self.series)

        self.view = SourcesListEntriesView(
            self.entries, LaunchpadTestRequest())
        self.view.initialize()

    def testNoSelectorForOneSeries(self):
        # The selector should not be presented when there is only one series

        self.failUnless(self.view.sources_in_more_than_one_series is False)

    def testDefaultDistroSeries(self):
        # When there is only one distro series it should always be the
        # default.
        self.failUnless(self.view.default_series == self.series[0])
    def testNonRecognisedDistro(self):
        # If the supplied series in the user-agent is not recognized as a
        # valid distroseries for the distro, then we force the user to
        # make a selection.
        view = SourcesListEntriesView(self.entries, LaunchpadTestRequest(
                HTTP_USER_AGENT='Mozilla/5.0 '
                                '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                                'Gecko/2009042523 Ubunti/9.04 (whatever) '
                                'Firefox/3.0.10'))

        view.initialize()

        self.assertEqual('YOUR_IBUNTU_VERSION_HERE', view.default_series_name)
    def testCommentDisplayedWhenProvided(self):
        # A comment provided to the constructor should appear when
        # rendered.
        my_comment = ("this comment should be displayed with the sources."
                      "list entries.")

        view = SourcesListEntriesView(
            self.entries, LaunchpadTestRequest(), comment=my_comment)
        view.initialize()

        html = view.__call__()
        self.assertTrue('#' + my_comment in html,
            "The comment was not included in the sources.list snippet.")
    def testNonRecognisedDistro(self):
        # If the supplied series in the user-agent is not recognized as a
        # valid distroseries for the distro, then we force the user to
        # make a selection.
        view = SourcesListEntriesView(
            self.entries,
            LaunchpadTestRequest(HTTP_USER_AGENT='Mozilla/5.0 '
                                 '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                                 'Gecko/2009042523 Ubunti/9.04 (whatever) '
                                 'Firefox/3.0.10'))

        view.initialize()

        self.assertEqual('YOUR_IBUNTU_VERSION_HERE', view.default_series_name)
    def testDefaultToUserAgentSeries(self):
        # The distroseries version found in the user-agent header will
        # be selected by default.

        # Ubuntu version 10.09 in the user-agent should display as getsy
        view = SourcesListEntriesView(
            self.entries,
            LaunchpadTestRequest(HTTP_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'))
        view.initialize()

        self.assertEqual(u'getsy', view.default_series_name)

        # Ubuntu version 9.04 in the user-agent should display as feasty
        view = SourcesListEntriesView(
            self.entries,
            LaunchpadTestRequest(HTTP_USER_AGENT='Mozilla/5.0 '
                                 '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                                 'Gecko/2009042523 Ubuntu/9.04 (whatever) '
                                 'Firefox/3.0.10'))
        view.initialize()

        self.assertEqual(u'feasty', view.default_series_name)
    def setUp(self):
        TestCaseWithFactory.setUp(self)
        self.distribution = self.factory.makeDistribution(name='ibuntu')

        # Ensure there is only one series available.
        self.series = [
            self.factory.makeDistroSeries(name="feasty", version='9.04'),
        ]
        self.entries = SourcesListEntries(self.distribution,
                                          'http://example.com/my/archive',
                                          self.series)

        self.view = SourcesListEntriesView(self.entries,
                                           LaunchpadTestRequest())
        self.view.initialize()
    def testCommentDisplayedWhenProvided(self):
        # A comment provided to the constructor should appear when
        # rendered.
        my_comment = ("this comment should be displayed with the sources."
                      "list entries.")

        view = SourcesListEntriesView(self.entries,
                                      LaunchpadTestRequest(),
                                      comment=my_comment)
        view.initialize()

        html = view.__call__()
        self.assertTrue(
            '#' + my_comment in html,
            "The comment was not included in the sources.list snippet.")
Example #11
0
 def initialize(self):
     """Set up the sources.list entries for display."""
     valid_series = []
     # use an explicit loop to preserve ordering while getting rid of dupes
     for arch_series in self.summarized_arch_series:
         series = arch_series.distro_arch_series.distroseries
         if series not in valid_series:
             valid_series.append(series)
     entries = SourcesListEntries(self.context.distribution,
                                  self.context.base_url, valid_series)
     self.sources_list_entries = SourcesListEntriesView(
         entries, self.request, initially_without_selection=True)
    def testDefaultToUserAgentSeries(self):
        # The distroseries version found in the user-agent header will
        # be selected by default.

        # Ubuntu version 10.09 in the user-agent should display as getsy
        view = SourcesListEntriesView(
            self.entries,
            LaunchpadTestRequest(
                HTTP_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'))
        view.initialize()

        self.assertEqual(u'getsy', view.default_series_name)

        # Ubuntu version 9.04 in the user-agent should display as feasty
        view = SourcesListEntriesView(
            self.entries,
            LaunchpadTestRequest(
                HTTP_USER_AGENT='Mozilla/5.0 '
                                '(X11; U; Linux i686; en-US; rv:1.9.0.10) '
                                'Gecko/2009042523 Ubuntu/9.04 (whatever) '
                                'Firefox/3.0.10'))
        view.initialize()

        self.assertEqual(u'feasty', view.default_series_name)
    def setUp(self):
        TestCaseWithFactory.setUp(self)
        self.distribution = self.factory.makeDistribution(name='ibuntu')

        # Ensure there is only one series available.
        self.series = [
            self.factory.makeDistroSeries(name="feasty", version='9.04'),
            ]
        self.entries = SourcesListEntries(
            self.distribution, 'http://example.com/my/archive',
            self.series)

        self.view = SourcesListEntriesView(
            self.entries, LaunchpadTestRequest())
        self.view.initialize()