示例#1
0
文件: search.py 项目: nagyist/agilo
    def get_tickets_matching(self, t_id, summary):
        """
        Returns a list of dictionaries (id: value, summary: value) matching the summary 
        request and excluding the requesting ticket having id = id.
        """
        try:
            t_id = int(t_id)  # Make sure it is an int :-)
            keyword = re.compile(summary, re.IGNORECASE)
            db = self.env.get_db_cnx()

            from agilo.ticket.model import AgiloTicketModelManager
            sql = """SELECT id, type, summary FROM ticket WHERE id != $id $allowed 
                  AND id NOT IN (SELECT dest FROM %s WHERE src = $id UNION
                  SELECT src FROM %s WHERE dest = $id) ORDER BY summary""" \
                    % (LINKS_TABLE, LINKS_TABLE)
            sql_query = string.Template(sql)
            sql_allowed = "AND ticket.type IN ('%s')"
            t_type = AgiloTicketModelManager(
                self.env).get(tkt_id=t_id).get_type()
            linkconfig = LinksConfiguration(self.env)
            if linkconfig.is_allowed_source_type(t_type):
                allowed_types = linkconfig.get_allowed_destination_types(
                    t_type)
                allowed = sql_allowed % '\', \''.join(allowed_types)
            else:
                debug(self, "No Key found for #%s#" % repr(t_type))
                allowed = ''

            sql_query = sql_query.substitute({'id': t_id, 'allowed': allowed})
            debug(self, "SQL: %s" % sql_query)
            cursor = db.cursor()
            cursor.execute(sql_query)

            results = []
            for row in cursor:
                if keyword.search(row[2] or ''):
                    results.append({
                        'id': row[0],
                        'type': row[1],
                        'summary': row[2]
                    })

            debug(self, "Search Results: %s" % str(results))
            return results

        except Exception, e:
            warning(self, e)
            msg = "[%s]: ERROR: Search module unable to complete query!" % \
                    self.__class__.__name__
            raise TracError(msg)
示例#2
0
 def get_tickets_matching(self, t_id, summary):
     """
     Returns a list of dictionaries (id: value, summary: value) matching the summary 
     request and excluding the requesting ticket having id = id.
     """
     try:
         t_id = int(t_id) # Make sure it is an int :-)
         keyword = re.compile(summary, re.IGNORECASE)
         db = self.env.get_db_cnx()
         
         from agilo.ticket.model import AgiloTicketModelManager
         sql = """SELECT id, type, summary FROM ticket WHERE id != $id $allowed 
               AND id NOT IN (SELECT dest FROM %s WHERE src = $id UNION
               SELECT src FROM %s WHERE dest = $id) ORDER BY summary""" \
                 % (LINKS_TABLE, LINKS_TABLE)
         sql_query = string.Template(sql)
         sql_allowed = "AND ticket.type IN ('%s')"
         t_type = AgiloTicketModelManager(self.env).get(tkt_id=t_id).get_type()
         linkconfig = LinksConfiguration(self.env)
         if linkconfig.is_allowed_source_type(t_type):
             allowed_types = linkconfig.get_allowed_destination_types(t_type)
             allowed = sql_allowed % '\', \''.join(allowed_types)
         else:
             debug(self, "No Key found for #%s#" % repr(t_type))
             allowed = ''
                 
         sql_query = sql_query.substitute({'id' : t_id, 'allowed' : allowed})
         debug(self, "SQL: %s" % sql_query)
         cursor = db.cursor()
         cursor.execute(sql_query)
         
         results = []
         for row in cursor:
             if keyword.search(row[2] or ''):
                 results.append({'id': row[0], 'type': row[1], 
                                 'summary': row[2]})  
         
         debug(self, "Search Results: %s" % str(results))
         return results
         
     except Exception, e:
         warning(self, e)
         msg = "[%s]: ERROR: Search module unable to complete query!" % \
                 self.__class__.__name__
         raise TracError(msg) 
示例#3
0
class LinksConfigurationCachingTest(AgiloTestCase):
    def setUp(self):
        self.super()
        self.links_configuration = LinksConfiguration(self.env)
    
    def test_initializes_at_init(self):
        self.assert_true(self.links_configuration.is_initialized())

    def test_handles_types_with_dashes(self):
        from_type = 'with-dashes'
        to_type = 'bug'
        custom_type = TicketType(self.env)
        custom_type.name = from_type
        custom_type.insert()

        config = AgiloConfig(self.env)
        config.change_option(from_type, "", section=AgiloConfig.AGILO_TYPES)
        config.reload()
        self.assert_true(from_type in config.get_available_types())

        section = config.get_section(AgiloConfig.AGILO_LINKS)
        allowed_links = section.get_list('allow')
        allowed_links.append('%s-%s' % (from_type, to_type))
        section.change_option('allow', ', '.join(allowed_links), save=True)
        self.links_configuration = LinksConfiguration(self.env)
        self.assert_equals(self.links_configuration.get_alloweds(from_type)[0].dest_type, to_type)

    def _requirement_links(self):
        return self.links_configuration.get_allowed_destination_types('requirement')
    
    def test_invalidating_the_cache_reloads_allowed_links_configuration(self):
        AgiloConfig(self.env).change_option('allow', 'requirement-task', section='agilo-links', save=True)
        self.links_configuration.reinitialize()
        self.assert_not_contains('story', self._requirement_links())
        self.assert_contains('task', self._requirement_links())

    def _bug_calculated_properties(self):
        return AgiloTicketSystem(self.env).get_agilo_properties('bug')[0].keys()

    def test_invalidating_the_cache_reloads_calculated_properties(self):
        self.assert_contains('total_remaining_time', self._bug_calculated_properties())
        AgiloConfig(self.env).change_option('bug.calculate', '', section='agilo-links', save=True)
        self.links_configuration.reinitialize()
        self.assert_not_contains('total_remaining_time', self._bug_calculated_properties())