Ejemplo n.º 1
0
    def _test_find_by_criterion(self, attr, first_cb=None, matcher_cb=None):
        if matcher_cb is None:

            def matcher_cb(expected, actual):
                self.assertEquals(
                    expected.id, actual.id,
                    'different id on: %s != %s' % (expected, actual))

        if first_cb is None:

            def first_cb(obj):
                return bool(obj)

        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]

        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            criterion_obj = getattr(issue, attr)
            if first_cb(criterion_obj):
                break
        else:
            assert False, 'not a single issue has this criterion'

        setattr(q, attr, criterion_obj)

        some = False
        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            some = True
            fetched_obj = getattr(issue, attr)
            matcher_cb(criterion_obj, fetched_obj)
        assert some, 'the issue searched for was not found'
Ejemplo n.º 2
0
    def _test_find_by_criterion(self, attr, first_cb=None, matcher_cb=None):
        if matcher_cb is None:
            def matcher_cb(expected, actual):
                self.assertEquals(expected.id, actual.id, 'different id on: %s != %s' % (expected, actual))

        if first_cb is None:
            def first_cb(obj):
                return bool(obj)

        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]

        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            criterion_obj = getattr(issue, attr)
            if first_cb(criterion_obj):
                break
        else:
            assert False, 'not a single issue has this criterion'

        setattr(q, attr, criterion_obj)

        some = False
        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            some = True
            fetched_obj = getattr(issue, attr)
            matcher_cb(criterion_obj, fetched_obj)
        assert some, 'the issue searched for was not found'
Ejemplo n.º 3
0
 def test_search(self):
     query = Query()
     query.project = u'github/hubot'
     query.status = u'closed'
     query.title = u'fix'
     issues = self.backend.iter_issues(query)
     issue = issues.next()
     assert issue.status.name == 'closed'
Ejemplo n.º 4
0
 def test_search(self):
     query = Query()
     query.project = u'github/hubot'
     query.status = u'closed'
     query.title = u'fix'
     issues = self.backend.iter_issues(query)
     issue = issues.next()
     assert issue.status.name == 'closed'
Ejemplo n.º 5
0
 def test_search(self):
     query = Query()
     query.project = 'weboobie/testing'
     query.status = 'closed'
     query.title = 'fix'
     issues = iter(self.backend.iter_issues(query))
     issue = next(issues)
     assert issue.status.name == 'closed'
     assert 'fix' in issue.title
Ejemplo n.º 6
0
 def test_search(self):
     query = Query()
     query.project = 'weboobie/testing'
     query.status = 'closed'
     query.title = 'fix'
     issues = iter(self.backend.iter_issues(query))
     issue = next(issues)
     assert issue.status.name == 'closed'
     assert 'fix' in issue.title
Ejemplo n.º 7
0
 def iter_resources(self, objs, split_path):
     if Project in objs or Issue in objs:
         self._restrict_level(split_path, 1)
         if len(split_path) == 0:
             return [Collection([project.id], project.name)
                     for project in self.iter_projects()]
         elif len(split_path) == 1:
             query = Query()
             query.project = unicode(split_path[0])
             return self.iter_issues(query)
Ejemplo n.º 8
0
    def test_find_by_status(self):
        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]
        q.status = 'open'

        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            self.assertEquals(issue.status.name.lower(), 'open', issue.title)

        q.status = 'closed'
        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            self.assertEquals(issue.status.name.lower(), 'closed', issue.title)
Ejemplo n.º 9
0
    def test_find_by_status(self):
        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]
        q.status = 'open'

        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            self.assertEquals(issue.status.name.lower(), 'open', issue.title)

        q.status = 'closed'
        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            self.assertEquals(issue.status.name.lower(), 'closed', issue.title)
Ejemplo n.º 10
0
    def test_find_any_issues(self):
        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]

        issues = [issue for issue, _ in zip(self.backend.iter_issues(q), range(30))]
        self.assertTrue(issues)

        for issue in issues:
            self.assertTrue(issue.project)
            self.assertEquals(issue.project.id, projects[0].id)
            self.assertTrue(issue.title)
            self.assertFalse(empty(issue.body))
            self.assertTrue(issue.creation)

            self.assertTrue(issue.author, issue.title)
Ejemplo n.º 11
0
    def test_find_any_issues(self):
        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]

        issues = [
            issue for issue, _ in zip(self.backend.iter_issues(q), range(30))
        ]
        self.assertTrue(issues)

        for issue in issues:
            self.assertTrue(issue.project)
            self.assertEquals(issue.project.id, projects[0].id)
            self.assertTrue(issue.title)
            self.assertFalse(empty(issue.body))
            self.assertTrue(issue.creation)

            self.assertTrue(issue.author, issue.title)
Ejemplo n.º 12
0
    def test_read_comments(self):
        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]

        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            self.backend.fillobj(issue, ['history'])
            self.assertNotEmpty(issue.history)
            if issue.history:
                for update in issue.history:
                    self.assertTrue(update.author)
                    self.assertTrue(update.author.id)
                    self.assertTrue(update.author.name)
                    self.assertTrue(update.date)
                    self.assertTrue(update.message)
                    self.assertNotEmpty(update.changes)

                break
        else:
            assert 0, 'no issue had history'
Ejemplo n.º 13
0
    def test_read_comments(self):
        projects = list(self.backend.iter_projects())
        self.assertTrue(projects)

        q = Query()
        q.project = projects[0]

        for issue, _ in zip(self.backend.iter_issues(q), range(30)):
            self.backend.fillobj(issue, ['history'])
            self.assertNotEmpty(issue.history)
            if issue.history:
                for update in issue.history:
                    self.assertTrue(update.author)
                    self.assertTrue(update.author.id)
                    self.assertTrue(update.author.name)
                    self.assertTrue(update.date)
                    self.assertTrue(update.message)
                    self.assertNotEmpty(update.changes)

                break
        else:
            assert 0, 'no issue had history'
Ejemplo n.º 14
0
    def do_search(self, line):
        """
        search PROJECT

        List issues for a project.

        You can use these filters from command line:
           --author AUTHOR
           --title TITLE_PATTERN
           --assignee ASSIGNEE
           --target-version VERSION
           --category CATEGORY
           --status STATUS
        """
        query = Query()

        path = self.working_path.get()
        backends = []
        if line.strip():
            query.project, backends = self.parse_id(line, unique_backend=True)
        elif len(path) > 0:
            query.project = path[0]
        else:
            print >>sys.stderr, 'Please enter a project name'
            return 1

        query.author = self.options.author
        query.title = self.options.title
        query.assignee = self.options.assignee
        query.version = self.options.version
        query.category = self.options.category
        query.status = self.options.status

        self.change_path([query.project, u'search'])
        for backend, issue in self.do('iter_issues', query, backends=backends):
            self.add_object(issue)
            self.format(issue)
        self.flush()
Ejemplo n.º 15
0
    def do_search(self, line):
        """
        search PROJECT

        List issues for a project.

        You can use these filters from command line:
           --author AUTHOR
           --title TITLE_PATTERN
           --assignee ASSIGNEE
           --target-version VERSION
           --category CATEGORY
           --status STATUS
        """
        query = Query()

        path = self.working_path.get()
        backends = []
        if line.strip():
            query.project, backends = self.parse_id(line, unique_backend=True)
        elif len(path) > 0:
            query.project = path[0]
        else:
            print >> sys.stderr, "Please enter a project name"
            return 1

        query.author = self.options.author
        query.title = self.options.title
        query.assignee = self.options.assignee
        query.version = self.options.version
        query.category = self.options.category
        query.status = self.options.status

        self.change_path([query.project, u"search"])
        for backend, issue in self.do("iter_issues", query, backends=backends):
            self.add_object(issue)
            self.format(issue)
        self.flush()
Ejemplo n.º 16
0
def string_to_queries(s):
    # TODO rewrite all when there are finer criteria
    # and when more complex expressions can be written

    tokens = shlex.split(s)  # raises ValueError

    criteria = {}

    for tok in tokens:
        m = KWD_MATCH.match(tok)
        if not m:
            raise ValueError('%r is not a valid criterion' % tok)

        k, v = m.groups()
        criteria.setdefault(k, []).append(v)

    queries = [Query()]
    for k, values in criteria.items():
        if k == 'tags':
            values = [tuple(val.split(',')) for val in values]

        if len(values) == 1:
            v, = values
            for q in queries:
                setattr(q, k, v)
        else:
            dupq = {}
            for v in values:
                dupq[v] = []
                for q in queries:
                    q = q.copy()
                    setattr(q, k, v)
                    dupq[v].append(q)

            queries = sum(dupq.values(), [])

    return queries