Пример #1
0
class ProductizedHrefTestCase(unittest.TestCase):

    def setUp(self):
        self.ghref = Href('/gbase')
        self.phref = ProductizedHref(self.ghref, '/gbase/product')

    def test_paths_no_transform(self):
        self.assertEqual('/gbase/admin', self.phref.admin())
        self.assertEqual('/gbase/logout', self.phref.logout())
        self.assertEqual('/gbase/prefs', self.phref('prefs'))
        self.assertEqual('/gbase/verify_email?a=1&b=cde',
                         self.phref('verify_email', a=1, b='cde'))

    def test_static_path_no_transform(self):
        self.assertEqual('/gbase/js', self.phref('js/'))
        self.assertEqual('/gbase/css', self.phref('css/'))
        self.assertEqual('/gbase/img', self.phref('img/'))

    def test_params_as_args(self):
        self.assertEqual('/gbase/product/ticket/540',
                         self.phref('ticket', 540))
        self.assertEqual('/gbase/product/ticket/540',
                         self.phref.ticket(540))

    def test_params_as_kwargs(self):
        self.assertIn(self.phref('ticket', param='value',
                                 other='other value'),
                      ['/gbase/product/ticket?param=value&other=other+value',
                       '/gbase/product/ticket?other=other+value&param=value'])

    def test_params_as_dictionary(self):
        self.assertIn(self.phref.ticket({'param': 'value',
                                         'other': 'other value'}),
                      ['/gbase/product/ticket/?param=value&other=other+value',
                       '/gbase/product/ticket?other=other+value&param=value'])
Пример #2
0
    def _get_product_info(self, product, resource, max_):
        penv = ProductEnvironment(self.env, product.prefix)
        href = ProductizedHref(self.env, penv.href.base)
        results = []

        # some queries return a list/tuple, some a generator,
        # hence count() to get the result length
        def count(iter_):
            try:
                return len(iter_)
            except TypeError:
                return sum(1 for _ in iter_)

        query = resource['type'].select(penv)
        for q in itertools.islice(query, max_):
            q.url = href(resource['name'], q.name) if resource.get('hrefurl') \
                else Query.from_string(penv, 'order=priority&%s=%s' %
                    (resource['name'], q.name)).get_href(href)
            q.ticket_count = penv.db_query(
                """SELECT COUNT(*) FROM ticket WHERE ticket.%s='%s'
                   AND ticket.status <> 'closed'""" % (resource['name'], q.name))[0][0]

            results.append(q)

        # add a '(No <milestone/component/version>)' entry if there are
        # tickets without an assigned resource in the product
        ticket_count = penv.db_query(
            """SELECT COUNT(*) FROM ticket WHERE %s=''
               AND status <> 'closed'""" % (resource['name'],))[0][0]
        if ticket_count != 0:
            q = resource['type'](penv)
            q.name = '(No %s)' % (resource['name'],)
            q.url = Query.from_string(penv,
                        'status=!closed&col=id&col=summary&col=owner'
                        '&col=status&col=priority&order=priority&%s=' %
                        (resource['name'],)).get_href(href)
            q.ticket_count = ticket_count
            results.append(q)

        results.sort(key=lambda x: x.ticket_count, reverse=True)

        # add a link to the resource list if there are
        # more than max resources defined
        if count(query) > max_:
            q = resource['type'](penv)
            q.name = _('... more')
            q.ticket_count = None
            q.url = href(resource['name']) if resource.get('hrefurl') \
                else href.product(product.prefix)
            results.append(q)

        return results
Пример #3
0
    def _get_product_info(self, product, resource, max_):
        penv = ProductEnvironment(self.env, product.prefix)
        href = ProductizedHref(self.env, penv.href.base)
        results = []

        # some queries return a list/tuple, some a generator,
        # hence count() to get the result length
        def count(iter_):
            try:
                return len(iter_)
            except TypeError:
                return sum(1 for _ in iter_)

        query = resource['type'].select(penv)
        for q in itertools.islice(query, max_):
            q.url = href(resource['name'], q.name) if resource.get('hrefurl') \
                else Query.from_string(penv, 'order=priority&%s=%s' %
                    (resource['name'], q.name)).get_href(href)
            q.ticket_count = penv.db_query(
                """SELECT COUNT(*) FROM ticket WHERE ticket.%s='%s'
                   AND ticket.status <> 'closed'""" %
                (resource['name'], q.name))[0][0]

            results.append(q)

        # add a '(No <milestone/component/version>)' entry if there are
        # tickets without an assigned resource in the product
        ticket_count = penv.db_query("""SELECT COUNT(*) FROM ticket WHERE %s=''
               AND status <> 'closed'""" % (resource['name'], ))[0][0]
        if ticket_count != 0:
            q = resource['type'](penv)
            q.name = '(No %s)' % (resource['name'], )
            q.url = Query.from_string(
                penv, 'status=!closed&col=id&col=summary&col=owner'
                '&col=status&col=priority&order=priority&%s=' %
                (resource['name'], )).get_href(href)
            q.ticket_count = ticket_count
            results.append(q)

        results.sort(key=lambda x: x.ticket_count, reverse=True)

        # add a link to the resource list if there are
        # more than max resources defined
        if count(query) > max_:
            q = resource['type'](penv)
            q.name = _('... more')
            q.ticket_count = None
            q.url = href(resource['name']) if resource.get('hrefurl') \
                else href.product(product.prefix)
            results.append(q)

        return results
Пример #4
0
 def get_href(self,
              href,
              id=None,
              order=None,
              desc=None,
              format=None,
              max=None,
              page=None):
     from multiproduct.hooks import ProductizedHref
     return super(ProductQuery,
                  self).get_href(ProductizedHref(href, self.env.href.base),
                                 id, order, desc, format, max, page)
Пример #5
0
 def setUp(self):
     self.ghref = Href('/gbase')
     self.phref = ProductizedHref(self.ghref, '/gbase/product')
Пример #6
0
 def setUp(self):
     self.ghref = Href('/gbase')
     self.phref = ProductizedHref(self.ghref, '/gbase/product')