Blame tests/test_progit_lib_link.py

Pierre-Yves Chibon 35fa85
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
"""
Pierre-Yves Chibon 35fa85
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
 Authors:
Pierre-Yves Chibon 35fa85
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
"""
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 35fa85
import pkg_resources
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
import json
Pierre-Yves Chibon 35fa85
import unittest
Pierre-Yves Chibon 35fa85
import shutil
Pierre-Yves Chibon 35fa85
import sys
Pierre-Yves Chibon 35fa85
import os
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
import pygit2
Pierre-Yves Chibon 35fa85
from mock import patch
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 35fa85
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
import progit.lib.link
Pierre-Yves Chibon 35fa85
import tests
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
COMMENTS = [
Pierre-Yves Chibon 35fa85
    'Did you see #1?',
Pierre-Yves Chibon 35fa85
    'This is a duplicate of #2',
Pierre-Yves Chibon 35fa85
    'This is a fixes #3',
Pierre-Yves Chibon 35fa85
    'Might be worth looking at https://fedorahosted.org/progit/tests2/issue/4',
Pierre-Yves Chibon 35fa85
    'This relates to #5',
Pierre-Yves Chibon 35fa85
    'Could this be related to https://fedorahosted.org/progit/tests2/issue/6',
Pierre-Yves Chibon 35fa85
]
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
class ProgitLibLinktests(tests.Modeltests):
Pierre-Yves Chibon 35fa85
    """ Tests for progit.lib.link """
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
    def test_get_relation_relates(self):
Pierre-Yves Chibon 35fa85
        """ Test the get_relation function of progit.lib.link with relates.
Pierre-Yves Chibon 35fa85
        """
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        self.assertEqual(
Pierre-Yves Chibon 35fa85
            progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
                self.session,
Pierre-Yves Chibon 35fa85
                'test',
Pierre-Yves Chibon 35fa85
                None,
Pierre-Yves Chibon 35fa85
                COMMENTS[0],
Pierre-Yves Chibon 35fa85
                'relates',
Pierre-Yves Chibon 35fa85
            ),
Pierre-Yves Chibon 35fa85
            []
Pierre-Yves Chibon 35fa85
        )
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        tests.create_projects(self.session)
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        link = progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
            self.session, 'test', None, COMMENTS[4], 'relates')
Pierre-Yves Chibon 35fa85
        self.assertEqual(link, [])
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        # Create the issue
Pierre-Yves Chibon 35fa85
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 35fa85
        progit.lib.new_issue(
Pierre-Yves Chibon 35fa85
            self.session,
Pierre-Yves Chibon 35fa85
            repo,
Pierre-Yves Chibon 35fa85
            title='foo',
Pierre-Yves Chibon 35fa85
            content='bar',
Pierre-Yves Chibon 35fa85
            user='pingou',
Pierre-Yves Chibon 35fa85
            ticketfolder=None,
Pierre-Yves Chibon 35fa85
            issue_id=5,
Pierre-Yves Chibon 35fa85
            notify=False)
Pierre-Yves Chibon 35fa85
        self.session.commit()
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        for idx, comment in enumerate(COMMENTS):
Pierre-Yves Chibon 35fa85
            link = progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
                self.session, 'test', None, comment, 'relates')
Pierre-Yves Chibon 35fa85
            if idx == 4:
Pierre-Yves Chibon 35fa85
                self.assertEqual(
Pierre-Yves Chibon 35fa85
                    str(link),
Pierre-Yves Chibon 35fa85
                    '[Issue(5, project:test, user:pingou, title:foo)]')
Pierre-Yves Chibon 35fa85
            else:
Pierre-Yves Chibon 35fa85
                self.assertEqual(link, [])
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        link = progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
            self.session, 'test', None, COMMENTS[5], 'relates')
Pierre-Yves Chibon 35fa85
        self.assertEqual(link, [])
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        # Create the issue
Pierre-Yves Chibon 35fa85
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 35fa85
        progit.lib.new_issue(
Pierre-Yves Chibon 35fa85
            self.session,
Pierre-Yves Chibon 35fa85
            repo,
Pierre-Yves Chibon 35fa85
            title='another foo',
Pierre-Yves Chibon 35fa85
            content='another bar',
Pierre-Yves Chibon 35fa85
            user='pingou',
Pierre-Yves Chibon 35fa85
            ticketfolder=None,
Pierre-Yves Chibon 35fa85
            issue_id=6,
Pierre-Yves Chibon 35fa85
            notify=False)
Pierre-Yves Chibon 35fa85
        self.session.commit()
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        for idx, comment in enumerate(COMMENTS):
Pierre-Yves Chibon 35fa85
            link = progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
                self.session, 'test', None, comment, 'relates')
Pierre-Yves Chibon 35fa85
            if idx == 4:
Pierre-Yves Chibon 35fa85
                self.assertEqual(
Pierre-Yves Chibon 35fa85
                    str(link),
Pierre-Yves Chibon 35fa85
                    '[Issue(5, project:test, user:pingou, title:foo)]')
Pierre-Yves Chibon 35fa85
            elif idx == 5:
Pierre-Yves Chibon 35fa85
                self.assertEqual(
Pierre-Yves Chibon 35fa85
                    str(link),
Pierre-Yves Chibon 35fa85
                    '[Issue(6, project:test, user:pingou, title:another foo)]')
Pierre-Yves Chibon 35fa85
            else:
Pierre-Yves Chibon 35fa85
                self.assertEqual(link, [])
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
    def test_get_relation_fixes(self):
Pierre-Yves Chibon 35fa85
        """ Test the get_relation function of progit.lib.link with fixes.
Pierre-Yves Chibon 35fa85
        """
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        self.assertEqual(
Pierre-Yves Chibon 35fa85
            progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
                self.session,
Pierre-Yves Chibon 35fa85
                'test',
Pierre-Yves Chibon 35fa85
                None,
Pierre-Yves Chibon 35fa85
                COMMENTS[0],
Pierre-Yves Chibon 35fa85
                'fixes',
Pierre-Yves Chibon 35fa85
            ),
Pierre-Yves Chibon 35fa85
            []
Pierre-Yves Chibon 35fa85
        )
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        tests.create_projects(self.session)
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        link = progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
            self.session, 'test', None, COMMENTS[2], 'fixes')
Pierre-Yves Chibon 35fa85
        self.assertEqual(link, [])
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        # Create the issue
Pierre-Yves Chibon 35fa85
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 35fa85
        progit.lib.new_issue(
Pierre-Yves Chibon 35fa85
            self.session,
Pierre-Yves Chibon 35fa85
            repo,
Pierre-Yves Chibon 35fa85
            title='issue 3',
Pierre-Yves Chibon 35fa85
            content='content issue 3',
Pierre-Yves Chibon 35fa85
            user='pingou',
Pierre-Yves Chibon 35fa85
            ticketfolder=None,
Pierre-Yves Chibon 35fa85
            issue_id=3,
Pierre-Yves Chibon 35fa85
            notify=False)
Pierre-Yves Chibon 35fa85
        self.session.commit()
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
        for idx, comment in enumerate(COMMENTS):
Pierre-Yves Chibon 35fa85
            link = progit.lib.link.get_relation(
Pierre-Yves Chibon 35fa85
                self.session, 'test', None, comment, 'fixes')
Pierre-Yves Chibon 35fa85
            if idx == 2:
Pierre-Yves Chibon 35fa85
                self.assertEqual(
Pierre-Yves Chibon 35fa85
                    str(link),
Pierre-Yves Chibon 35fa85
                    '[Issue(3, project:test, user:pingou, title:issue 3)]')
Pierre-Yves Chibon 35fa85
            else:
Pierre-Yves Chibon 35fa85
                self.assertEqual(link, [])
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
Pierre-Yves Chibon 35fa85
if __name__ == '__main__':
Pierre-Yves Chibon 35fa85
    SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitLibLinktests)
Pierre-Yves Chibon 35fa85
    unittest.TextTestRunner(verbosity=2).run(SUITE)