Blame tests/test_progit_lib.py

Pierre-Yves Chibon 33b534
# -*- coding: utf-8 -*-
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
"""
Pierre-Yves Chibon d88010
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
 Authors:
Pierre-Yves Chibon d88010
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
"""
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon d88010
import pkg_resources
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
import unittest
Pierre-Yves Chibon 4fbc78
import shutil
Pierre-Yves Chibon d88010
import sys
Pierre-Yves Chibon d88010
import os
Pierre-Yves Chibon d88010
Pierre-Yves Chibon a42f77
from mock import patch
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon d88010
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon d88010
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
import progit.lib
Pierre-Yves Chibon 538301
import tests
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
Pierre-Yves Chibon 538301
class ProgitLibtests(tests.Modeltests):
Pierre-Yves Chibon d88010
    """ Tests for progit.lib """
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
    def test_get_next_id(self):
Pierre-Yves Chibon d88010
        """ Test the get_next_id function of progit.lib. """
Pierre-Yves Chibon 538301
        tests.create_projects(self.session)
Pierre-Yves Chibon d88010
        self.assertEqual(1, progit.lib.get_next_id(self.session, 1))
Pierre-Yves Chibon d88010
Pierre-Yves Chibon f74336
    def test_search_user_all(self):
Pierre-Yves Chibon f74336
        """ Test the search_user of progit.lib. """
Pierre-Yves Chibon f74336
Pierre-Yves Chibon f74336
        # Retrieve all users
Pierre-Yves Chibon f74336
        items = progit.lib.search_user(self.session)
Pierre-Yves Chibon f74336
        self.assertEqual(2, len(items))
Pierre-Yves Chibon f74336
        self.assertEqual(1, items[0].id)
Pierre-Yves Chibon f74336
        self.assertEqual('pingou', items[0].user)
Pierre-Yves Chibon f74336
        self.assertEqual('pingou', items[0].username)
Pierre-Yves Chibon f74336
        self.assertEqual([], items[0].groups)
Pierre-Yves Chibon f74336
        self.assertEqual(2, items[1].id)
Pierre-Yves Chibon f74336
        self.assertEqual('foo', items[1].user)
Pierre-Yves Chibon f74336
        self.assertEqual('foo', items[1].username)
Pierre-Yves Chibon f74336
        self.assertEqual([], items[1].groups)
Pierre-Yves Chibon f74336
Pierre-Yves Chibon c7ee0c
    def test_search_user_username(self):
Pierre-Yves Chibon c7ee0c
        """ Test the search_user of progit.lib. """
Pierre-Yves Chibon c7ee0c
Pierre-Yves Chibon c7ee0c
        # Retrieve user by username
Pierre-Yves Chibon c7ee0c
        item = progit.lib.search_user(self.session, username='foo')
Pierre-Yves Chibon c7ee0c
        self.assertEqual('foo', item.user)
Pierre-Yves Chibon c7ee0c
        self.assertEqual('foo', item.username)
Pierre-Yves Chibon c7ee0c
        self.assertEqual([], item.groups)
Pierre-Yves Chibon c7ee0c
Pierre-Yves Chibon c7ee0c
        item = progit.lib.search_user(self.session, username='bar')
Pierre-Yves Chibon c7ee0c
        self.assertEqual(None, item)
Pierre-Yves Chibon c7ee0c
Pierre-Yves Chibon f5cf0f
    def test_search_user_email(self):
Pierre-Yves Chibon f5cf0f
        """ Test the search_user of progit.lib. """
Pierre-Yves Chibon f5cf0f
Pierre-Yves Chibon f5cf0f
        # Retrieve user by email
Pierre-Yves Chibon f5cf0f
        item = progit.lib.search_user(self.session, email='foo@foo.com')
Pierre-Yves Chibon f5cf0f
        self.assertEqual(None, item)
Pierre-Yves Chibon f5cf0f
Pierre-Yves Chibon f5cf0f
        item = progit.lib.search_user(self.session, email='foo@bar.com')
Pierre-Yves Chibon f5cf0f
        self.assertEqual('foo', item.user)
Pierre-Yves Chibon f5cf0f
        self.assertEqual('foo', item.username)
Pierre-Yves Chibon f5cf0f
        self.assertEqual([], item.groups)
Pierre-Yves Chibon f5cf0f
        self.assertEqual(
Pierre-Yves Chibon f5cf0f
            ['foo@bar.com'], [email.email for email in item.emails])
Pierre-Yves Chibon f5cf0f
Pierre-Yves Chibon f5cf0f
        item = progit.lib.search_user(self.session, email='foo@pingou.com')
Pierre-Yves Chibon f5cf0f
        self.assertEqual('pingou', item.user)
Pierre-Yves Chibon f5cf0f
        self.assertEqual(
Pierre-Yves Chibon f5cf0f
            ['bar@pingou.com', 'foo@pingou.com'],
Pierre-Yves Chibon f5cf0f
            [email.email for email in item.emails])
Pierre-Yves Chibon f5cf0f
Pierre-Yves Chibon fe688c
    def test_search_user_token(self):
Pierre-Yves Chibon fe688c
        """ Test the search_user of progit.lib. """
Pierre-Yves Chibon fe688c
Pierre-Yves Chibon fe688c
        # Retrieve user by token
Pierre-Yves Chibon fe688c
        item = progit.lib.search_user(self.session, token='aaa')
Pierre-Yves Chibon fe688c
        self.assertEqual(None, item)
Pierre-Yves Chibon fe688c
Pierre-Yves Chibon fe688c
        item = progit.lib.model.User(
Pierre-Yves Chibon fe688c
            user='pingou2',
Pierre-Yves Chibon fe688c
            fullname='PY C',
Pierre-Yves Chibon fe688c
            token='aaabbb',
Pierre-Yves Chibon fe688c
        )
Pierre-Yves Chibon fe688c
        self.session.add(item)
Pierre-Yves Chibon fe688c
        self.session.commit()
Pierre-Yves Chibon fe688c
Pierre-Yves Chibon fe688c
        item = progit.lib.search_user(self.session, token='aaabbb')
Pierre-Yves Chibon fe688c
        self.assertEqual('pingou2', item.user)
Pierre-Yves Chibon fe688c
        self.assertEqual('PY C', item.fullname)
Pierre-Yves Chibon fe688c
Pierre-Yves Chibon 04a157
    def test_search_user_pattern(self):
Pierre-Yves Chibon 04a157
        """ Test the search_user of progit.lib. """
Pierre-Yves Chibon 04a157
Pierre-Yves Chibon 04a157
        # Retrieve user by pattern
Pierre-Yves Chibon 04a157
        item = progit.lib.search_user(self.session, pattern='a*')
Pierre-Yves Chibon 04a157
        self.assertEqual([], item)
Pierre-Yves Chibon 04a157
Pierre-Yves Chibon 04a157
        item = progit.lib.model.User(
Pierre-Yves Chibon 04a157
            user='pingou2',
Pierre-Yves Chibon 04a157
            fullname='PY C',
Pierre-Yves Chibon 04a157
            token='aaabbb',
Pierre-Yves Chibon 04a157
        )
Pierre-Yves Chibon 04a157
        self.session.add(item)
Pierre-Yves Chibon 04a157
        self.session.commit()
Pierre-Yves Chibon 04a157
Pierre-Yves Chibon 04a157
        items = progit.lib.search_user(self.session, pattern='p*')
Pierre-Yves Chibon 04a157
        self.assertEqual(2, len(items))
Pierre-Yves Chibon 04a157
        self.assertEqual(1, items[0].id)
Pierre-Yves Chibon 04a157
        self.assertEqual('pingou', items[0].user)
Pierre-Yves Chibon 04a157
        self.assertEqual('pingou', items[0].username)
Pierre-Yves Chibon 04a157
        self.assertEqual([], items[0].groups)
Pierre-Yves Chibon 04a157
        self.assertEqual(
Pierre-Yves Chibon 04a157
            ['bar@pingou.com', 'foo@pingou.com'],
Pierre-Yves Chibon 04a157
            [email.email for email in items[0].emails])
Pierre-Yves Chibon 04a157
        self.assertEqual(3, items[1].id)
Pierre-Yves Chibon 04a157
        self.assertEqual('pingou2', items[1].user)
Pierre-Yves Chibon 04a157
        self.assertEqual('pingou2', items[1].username)
Pierre-Yves Chibon 04a157
        self.assertEqual([], items[1].groups)
Pierre-Yves Chibon 04a157
        self.assertEqual(
Pierre-Yves Chibon 04a157
            [], [email.email for email in items[1].emails])
Pierre-Yves Chibon 04a157
Pierre-Yves Chibon a42f77
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon f2c72b
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon a42f77
    def test_new_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon a42f77
        """ Test the new_issue of progit.lib. """
Pierre-Yves Chibon a42f77
        p_send_email.return_value = True
Pierre-Yves Chibon a42f77
        p_ugt.return_value = True
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon a42f77
        tests.create_projects(self.session)
Pierre-Yves Chibon a42f77
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon a42f77
        # Before
Pierre-Yves Chibon a42f77
        issues = progit.lib.search_issues(self.session, repo)
Pierre-Yves Chibon a42f77
        self.assertEqual(len(issues), 0)
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon 91556a
        # See where it fails
Pierre-Yves Chibon 91556a
        self.assertRaises(
Pierre-Yves Chibon 91556a
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 91556a
            progit.lib.new_issue,
Pierre-Yves Chibon 91556a
            session=self.session,
Pierre-Yves Chibon 91556a
            repo=repo,
Pierre-Yves Chibon 91556a
            title='Test issue',
Pierre-Yves Chibon 91556a
            content='We should work on this',
Pierre-Yves Chibon 91556a
            user='blah',
Pierre-Yves Chibon 91556a
            ticketfolder=None
Pierre-Yves Chibon 91556a
        )
Pierre-Yves Chibon 91556a
Pierre-Yves Chibon 71feec
        # Add an extra user to project `foo`
Pierre-Yves Chibon 71feec
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 71feec
        msg = progit.lib.add_user_to_project(
Pierre-Yves Chibon 71feec
            session=self.session,
Pierre-Yves Chibon 71feec
            project=repo,
Pierre-Yves Chibon 71feec
            user='foo',
Pierre-Yves Chibon 71feec
        )
Pierre-Yves Chibon 71feec
        self.session.commit()
Pierre-Yves Chibon 71feec
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 71feec
Pierre-Yves Chibon 91556a
        # Create issues to play with
Pierre-Yves Chibon a42f77
        msg = progit.lib.new_issue(
Pierre-Yves Chibon a42f77
            session=self.session,
Pierre-Yves Chibon a42f77
            repo=repo,
Pierre-Yves Chibon a42f77
            title='Test issue',
Pierre-Yves Chibon a42f77
            content='We should work on this',
Pierre-Yves Chibon a42f77
            user='pingou',
Pierre-Yves Chibon a42f77
            ticketfolder=None
Pierre-Yves Chibon a42f77
        )
Pierre-Yves Chibon 91556a
        self.session.commit()
Pierre-Yves Chibon 91556a
        self.assertEqual(msg, 'Issue created')
Pierre-Yves Chibon 91556a
Pierre-Yves Chibon 91556a
        msg = progit.lib.new_issue(
Pierre-Yves Chibon 91556a
            session=self.session,
Pierre-Yves Chibon 91556a
            repo=repo,
Pierre-Yves Chibon 7e6046
            title='Test issue #2',
Pierre-Yves Chibon 7e6046
            content='We should work on this for the second time',
Pierre-Yves Chibon 91556a
            user='foo',
Pierre-Yves Chibon 91556a
            ticketfolder=None
Pierre-Yves Chibon 91556a
        )
Pierre-Yves Chibon 91556a
        self.session.commit()
Pierre-Yves Chibon a42f77
        self.assertEqual(msg, 'Issue created')
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon a42f77
        # After
Pierre-Yves Chibon a42f77
        issues = progit.lib.search_issues(self.session, repo)
Pierre-Yves Chibon 91556a
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon a5099b
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon a5099b
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon a5099b
    def test_edit_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon a5099b
        """ Test the edit_issue of progit.lib. """
Pierre-Yves Chibon a5099b
        p_send_email.return_value = True
Pierre-Yves Chibon a5099b
        p_ugt.return_value = True
Pierre-Yves Chibon a5099b
Pierre-Yves Chibon a5099b
        self.test_new_issue()
Pierre-Yves Chibon a5099b
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon a5099b
        issue = progit.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a5099b
Pierre-Yves Chibon a5099b
        # Edit the issue
Pierre-Yves Chibon a5099b
        msg = progit.lib.edit_issue(
Pierre-Yves Chibon a5099b
            session=self.session,
Pierre-Yves Chibon a5099b
            issue=issue,
Pierre-Yves Chibon 7e6046
            ticketfolder=None)
Pierre-Yves Chibon 7e6046
        self.session.commit()
Pierre-Yves Chibon 7e6046
        self.assertEqual(msg, 'No changes to edit')
Pierre-Yves Chibon 7e6046
Pierre-Yves Chibon 7e6046
        msg = progit.lib.edit_issue(
Pierre-Yves Chibon 7e6046
            session=self.session,
Pierre-Yves Chibon 7e6046
            issue=issue,
Pierre-Yves Chibon 7e6046
            ticketfolder=None,
Pierre-Yves Chibon 7e6046
            title='Test issue #2',
Pierre-Yves Chibon 7e6046
            content='We should work on this for the second time',
Pierre-Yves Chibon 7e6046
            status='Open',
Pierre-Yves Chibon 7e6046
        )
Pierre-Yves Chibon 7e6046
        self.session.commit()
Pierre-Yves Chibon 7e6046
        self.assertEqual(msg, 'No changes to edit')
Pierre-Yves Chibon 7e6046
Pierre-Yves Chibon 7e6046
        msg = progit.lib.edit_issue(
Pierre-Yves Chibon 7e6046
            session=self.session,
Pierre-Yves Chibon 7e6046
            issue=issue,
Pierre-Yves Chibon a5099b
            ticketfolder=None,
Pierre-Yves Chibon 7e6046
            title='Foo issue #2',
Pierre-Yves Chibon 7e6046
            content='We should work on this period',
Pierre-Yves Chibon a5099b
            status='Invalid')
Pierre-Yves Chibon a5099b
        self.session.commit()
Pierre-Yves Chibon a5099b
        self.assertEqual(msg, 'Edited successfully issue #2')
Pierre-Yves Chibon a5099b
Pierre-Yves Chibon 663645
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon 663645
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon 688e74
    def test_add_issue_dependency(self, p_send_email, p_ugt):
Pierre-Yves Chibon 688e74
        """ Test the add_issue_dependency of progit.lib. """
Pierre-Yves Chibon 688e74
        p_send_email.return_value = True
Pierre-Yves Chibon 688e74
        p_ugt.return_value = True
Pierre-Yves Chibon 688e74
Pierre-Yves Chibon 688e74
        self.test_new_issue()
Pierre-Yves Chibon 688e74
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 688e74
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 688e74
        issue_blocked = progit.lib.search_issues(
Pierre-Yves Chibon 688e74
            self.session, repo, issueid=2)
Pierre-Yves Chibon 688e74
Pierre-Yves Chibon 688e74
        # Before
Pierre-Yves Chibon 688e74
        self.assertEqual(issue.parents, [])
Pierre-Yves Chibon 688e74
        self.assertEqual(issue.children, [])
Pierre-Yves Chibon 688e74
        self.assertEqual(issue_blocked.parents, [])
Pierre-Yves Chibon 688e74
        self.assertEqual(issue_blocked.children, [])
Pierre-Yves Chibon 688e74
Pierre-Yves Chibon 961b99
        self.assertRaises(
Pierre-Yves Chibon 961b99
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 961b99
            progit.lib.add_issue_dependency,
Pierre-Yves Chibon 961b99
            session=self.session,
Pierre-Yves Chibon 961b99
            issue=issue,
Pierre-Yves Chibon 961b99
            issue_blocked=issue,
Pierre-Yves Chibon 961b99
            user='pingou',
Pierre-Yves Chibon 961b99
            ticketfolder=None)
Pierre-Yves Chibon 961b99
Pierre-Yves Chibon 688e74
        msg = progit.lib.add_issue_dependency(
Pierre-Yves Chibon 688e74
            session=self.session,
Pierre-Yves Chibon 688e74
            issue=issue,
Pierre-Yves Chibon 688e74
            issue_blocked=issue_blocked,
Pierre-Yves Chibon 688e74
            user='pingou',
Pierre-Yves Chibon 688e74
            ticketfolder=None)
Pierre-Yves Chibon 688e74
        self.session.commit()
Pierre-Yves Chibon 688e74
        self.assertEqual(msg, 'Dependency added')
Pierre-Yves Chibon 688e74
Pierre-Yves Chibon 688e74
        # After
Pierre-Yves Chibon 688e74
        self.assertEqual(len(issue.parents), 1)
Pierre-Yves Chibon 688e74
        self.assertEqual(issue.parents[0].id, 2)
Pierre-Yves Chibon 688e74
        self.assertEqual(len(issue.children), 0)
Pierre-Yves Chibon 688e74
        self.assertEqual(issue.children, [])
Pierre-Yves Chibon 688e74
Pierre-Yves Chibon 688e74
        self.assertEqual(len(issue_blocked.parents), 0)
Pierre-Yves Chibon 688e74
        self.assertEqual(issue_blocked.parents, [])
Pierre-Yves Chibon 688e74
        self.assertEqual(len(issue_blocked.children), 1)
Pierre-Yves Chibon 688e74
        self.assertEqual(issue_blocked.children[0].id, 1)
Pierre-Yves Chibon 688e74
Pierre-Yves Chibon 688e74
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon 688e74
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon 8393f9
    def test_add_issue_tag(self, p_send_email, p_ugt):
Pierre-Yves Chibon 8393f9
        """ Test the add_issue_tag of progit.lib. """
Pierre-Yves Chibon 8393f9
        p_send_email.return_value = True
Pierre-Yves Chibon 8393f9
        p_ugt.return_value = True
Pierre-Yves Chibon 8393f9
Pierre-Yves Chibon 8393f9
        self.test_edit_issue()
Pierre-Yves Chibon 8393f9
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 8393f9
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 8393f9
Pierre-Yves Chibon 8393f9
        # Add a tag to the issue
Pierre-Yves Chibon 8393f9
        msg = progit.lib.add_issue_tag(
Pierre-Yves Chibon 8393f9
            session=self.session,
Pierre-Yves Chibon 8393f9
            issue=issue,
Pierre-Yves Chibon 8393f9
            tag='tag1',
Pierre-Yves Chibon 8393f9
            user='pingou',
Pierre-Yves Chibon 8393f9
            ticketfolder=None)
Pierre-Yves Chibon 8393f9
        self.session.commit()
Pierre-Yves Chibon 8393f9
        self.assertEqual(msg, 'Tag added')
Pierre-Yves Chibon 8393f9
Pierre-Yves Chibon b4f437
        # Try a second time
Pierre-Yves Chibon 731160
        self.assertRaises(
Pierre-Yves Chibon 731160
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 731160
            progit.lib.add_issue_tag,
Pierre-Yves Chibon b4f437
            session=self.session,
Pierre-Yves Chibon b4f437
            issue=issue,
Pierre-Yves Chibon b4f437
            tag='tag1',
Pierre-Yves Chibon b4f437
            user='pingou',
Pierre-Yves Chibon b4f437
            ticketfolder=None)
Pierre-Yves Chibon b4f437
Pierre-Yves Chibon 8393f9
        issues = progit.lib.search_issues(self.session, repo, tags='tag1')
Pierre-Yves Chibon 8393f9
        self.assertEqual(len(issues), 1)
Pierre-Yves Chibon 8393f9
        self.assertEqual(issues[0].id, 1)
Pierre-Yves Chibon 8393f9
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon 8393f9
        self.assertEqual(issues[0].status, 'Open')
Pierre-Yves Chibon 8393f9
        self.assertEqual([tag.tag for tag in issues[0].tags], ['tag1'])
Pierre-Yves Chibon 8393f9
Pierre-Yves Chibon 8393f9
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon 8393f9
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon 07093f
    def test_remove_issue_tags(self, p_send_email, p_ugt):
Pierre-Yves Chibon 07093f
        """ Test the remove_issue_tags of progit.lib. """
Pierre-Yves Chibon 07093f
        p_send_email.return_value = True
Pierre-Yves Chibon 07093f
        p_ugt.return_value = True
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon 07093f
        self.test_add_issue_tag()
Pierre-Yves Chibon 07093f
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 07093f
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon 07093f
        self.assertRaises(
Pierre-Yves Chibon 07093f
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 07093f
            progit.lib.remove_issue_tags,
Pierre-Yves Chibon 07093f
            session=self.session,
Pierre-Yves Chibon 07093f
            project=repo,
Pierre-Yves Chibon 07093f
            tags='foo')
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon 07093f
        msgs = progit.lib.remove_issue_tags(
Pierre-Yves Chibon 07093f
            session=self.session,
Pierre-Yves Chibon 07093f
            project=repo,
Pierre-Yves Chibon 07093f
            tags='tag1')
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon 07093f
        self.assertEqual(msgs, [u'Removed tag: tag1'])
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon e1fce0
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon e1fce0
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon e1fce0
    def test_edit_issue_tags(self, p_send_email, p_ugt):
Pierre-Yves Chibon e1fce0
        """ Test the edit_issue_tags of progit.lib. """
Pierre-Yves Chibon e1fce0
        p_send_email.return_value = True
Pierre-Yves Chibon e1fce0
        p_ugt.return_value = True
Pierre-Yves Chibon e1fce0
Pierre-Yves Chibon e1fce0
        self.test_add_issue_tag()
Pierre-Yves Chibon e1fce0
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e1fce0
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon e1fce0
Pierre-Yves Chibon e1fce0
        self.assertRaises(
Pierre-Yves Chibon e1fce0
            progit.exceptions.ProgitException,
Pierre-Yves Chibon e1fce0
            progit.lib.edit_issue_tags,
Pierre-Yves Chibon e1fce0
            session=self.session,
Pierre-Yves Chibon e1fce0
            project=repo,
Pierre-Yves Chibon e1fce0
            old_tag='foo',
Pierre-Yves Chibon e1fce0
            new_tag='bar')
Pierre-Yves Chibon e1fce0
Pierre-Yves Chibon e1fce0
        msgs = progit.lib.edit_issue_tags(
Pierre-Yves Chibon e1fce0
            session=self.session,
Pierre-Yves Chibon e1fce0
            project=repo,
Pierre-Yves Chibon e1fce0
            old_tag='tag1',
Pierre-Yves Chibon e1fce0
            new_tag='tag2')
Pierre-Yves Chibon e1fce0
        self.session.commit()
Pierre-Yves Chibon e1fce0
        self.assertEqual(msgs, ['Edited tag: tag1 to tag2'])
Pierre-Yves Chibon e1fce0
Pierre-Yves Chibon e1fce0
        self.assertRaises(
Pierre-Yves Chibon e1fce0
            progit.exceptions.ProgitException,
Pierre-Yves Chibon e1fce0
            progit.lib.edit_issue_tags,
Pierre-Yves Chibon e1fce0
            session=self.session,
Pierre-Yves Chibon e1fce0
            project=repo,
Pierre-Yves Chibon e1fce0
            old_tag='tag2',
Pierre-Yves Chibon e1fce0
            new_tag='tag2')
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon 07093f
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon 07093f
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon 663645
    def test_search_issues(self, p_send_email, p_ugt):
Pierre-Yves Chibon 663645
        """ Test the search_issues of progit.lib. """
Pierre-Yves Chibon 663645
        p_send_email.return_value = True
Pierre-Yves Chibon 663645
        p_ugt.return_value = True
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        self.test_edit_issue()
Pierre-Yves Chibon 663645
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        # All issues
Pierre-Yves Chibon 663645
        issues = progit.lib.search_issues(self.session, repo)
Pierre-Yves Chibon 663645
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].id, 1)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].status, 'Open')
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].tags, [])
Pierre-Yves Chibon 663645
        self.assertEqual(issues[1].id, 2)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[1].project_id, 1)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[1].status, 'Invalid')
Pierre-Yves Chibon 663645
        self.assertEqual(issues[1].tags, [])
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        # Issues by status
Pierre-Yves Chibon 663645
        issues = progit.lib.search_issues(
Pierre-Yves Chibon 663645
            self.session, repo, status='Invalid')
Pierre-Yves Chibon 663645
        self.assertEqual(len(issues), 1)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].id, 2)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].status, 'Invalid')
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].tags, [])
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        # Issues closed
Pierre-Yves Chibon 663645
        issues = progit.lib.search_issues(
Pierre-Yves Chibon 663645
            self.session, repo, closed=True)
Pierre-Yves Chibon 663645
        self.assertEqual(len(issues), 1)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].id, 2)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].status, 'Invalid')
Pierre-Yves Chibon 663645
        self.assertEqual(issues[0].tags, [])
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        # Issues by tag
Pierre-Yves Chibon 663645
        issues = progit.lib.search_issues(self.session, repo, tags='foo')
Pierre-Yves Chibon 663645
        self.assertEqual(len(issues), 0)
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        # Issue by id
Pierre-Yves Chibon 663645
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 663645
        self.assertEqual(issue.title, 'Test issue')
Pierre-Yves Chibon 663645
        self.assertEqual(issue.user.user, 'pingou')
Pierre-Yves Chibon 663645
        self.assertEqual(issue.tags, [])
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 4b6666
        # Issues by authors
Pierre-Yves Chibon 4b6666
        issues = progit.lib.search_issues(self.session, repo, author='foo')
Pierre-Yves Chibon 4b6666
        self.assertEqual(len(issues), 1)
Pierre-Yves Chibon 4b6666
        self.assertEqual(issues[0].id, 2)
Pierre-Yves Chibon 4b6666
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon 4b6666
        self.assertEqual(issues[0].status, 'Invalid')
Pierre-Yves Chibon 4b6666
        self.assertEqual(issues[0].tags, [])
Pierre-Yves Chibon 4b6666
Pierre-Yves Chibon a96644
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon a96644
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon a96644
    def test_add_issue_assignee(self, p_send_email, p_ugt):
Pierre-Yves Chibon a96644
        """ Test the add_issue_assignee of progit.lib. """
Pierre-Yves Chibon a96644
        p_send_email.return_value = True
Pierre-Yves Chibon a96644
        p_ugt.return_value = True
Pierre-Yves Chibon a96644
Pierre-Yves Chibon a96644
        self.test_new_issue()
Pierre-Yves Chibon a96644
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon a96644
        issue = progit.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a96644
Pierre-Yves Chibon a96644
        # Before
Pierre-Yves Chibon a96644
        issues = progit.lib.search_issues(
Pierre-Yves Chibon a96644
            self.session, repo, assignee='pingou')
Pierre-Yves Chibon a96644
        self.assertEqual(len(issues), 0)
Pierre-Yves Chibon a96644
Pierre-Yves Chibon 13b9f7
        # Test when it fails
Pierre-Yves Chibon 13b9f7
        self.assertRaises(
Pierre-Yves Chibon 13b9f7
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 13b9f7
            progit.lib.add_issue_assignee,
Pierre-Yves Chibon 13b9f7
            session=self.session,
Pierre-Yves Chibon 13b9f7
            issue=issue,
Pierre-Yves Chibon 13b9f7
            assignee='foo@foobar.com',
Pierre-Yves Chibon 13b9f7
            user='foo@pingou.com',
Pierre-Yves Chibon 13b9f7
            ticketfolder=None
Pierre-Yves Chibon 13b9f7
        )
Pierre-Yves Chibon 13b9f7
Pierre-Yves Chibon 13b9f7
        self.assertRaises(
Pierre-Yves Chibon 13b9f7
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 13b9f7
            progit.lib.add_issue_assignee,
Pierre-Yves Chibon 13b9f7
            session=self.session,
Pierre-Yves Chibon 13b9f7
            issue=issue,
Pierre-Yves Chibon 13b9f7
            assignee='foo@bar.com',
Pierre-Yves Chibon 13b9f7
            user='foo@foopingou.com',
Pierre-Yves Chibon 13b9f7
            ticketfolder=None
Pierre-Yves Chibon 13b9f7
        )
Pierre-Yves Chibon 13b9f7
Pierre-Yves Chibon d14691
        # Set the assignee by its email
Pierre-Yves Chibon d14691
        msg = progit.lib.add_issue_assignee(
Pierre-Yves Chibon d14691
            session=self.session,
Pierre-Yves Chibon d14691
            issue=issue,
Pierre-Yves Chibon d14691
            assignee='foo@bar.com',
Pierre-Yves Chibon 13b9f7
            user='foo@pingou.com',
Pierre-Yves Chibon d14691
            ticketfolder=None)
Pierre-Yves Chibon d14691
        self.session.commit()
Pierre-Yves Chibon d14691
        self.assertEqual(msg, 'Issue assigned')
Pierre-Yves Chibon d14691
Pierre-Yves Chibon d14691
        # Change the assignee to someone else by its username
Pierre-Yves Chibon a96644
        msg = progit.lib.add_issue_assignee(
Pierre-Yves Chibon a96644
            session=self.session,
Pierre-Yves Chibon a96644
            issue=issue,
Pierre-Yves Chibon a96644
            assignee='pingou',
Pierre-Yves Chibon a96644
            user='pingou',
Pierre-Yves Chibon a96644
            ticketfolder=None)
Pierre-Yves Chibon a96644
        self.session.commit()
Pierre-Yves Chibon a96644
        self.assertEqual(msg, 'Issue assigned')
Pierre-Yves Chibon a96644
Pierre-Yves Chibon a96644
        # After  -- Searches by assignee
Pierre-Yves Chibon a96644
        issues = progit.lib.search_issues(
Pierre-Yves Chibon a96644
            self.session, repo, assignee='pingou')
Pierre-Yves Chibon a96644
        self.assertEqual(len(issues), 1)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].id, 2)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].status, 'Open')
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].tags, [])
Pierre-Yves Chibon a96644
Pierre-Yves Chibon a96644
        issues = progit.lib.search_issues(
Pierre-Yves Chibon a96644
            self.session, repo, assignee=True)
Pierre-Yves Chibon a96644
        self.assertEqual(len(issues), 1)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].id, 2)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].title, 'Test issue #2')
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].status, 'Open')
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].tags, [])
Pierre-Yves Chibon a96644
Pierre-Yves Chibon a96644
        issues = progit.lib.search_issues(
Pierre-Yves Chibon a96644
            self.session, repo, assignee=False)
Pierre-Yves Chibon a96644
        self.assertEqual(len(issues), 1)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].id, 1)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].title, 'Test issue')
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].project_id, 1)
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].status, 'Open')
Pierre-Yves Chibon a96644
        self.assertEqual(issues[0].tags, [])
Pierre-Yves Chibon a96644
Pierre-Yves Chibon d14691
        # Reset the assignee to no-one
Pierre-Yves Chibon d14691
        msg = progit.lib.add_issue_assignee(
Pierre-Yves Chibon d14691
            session=self.session,
Pierre-Yves Chibon d14691
            issue=issue,
Pierre-Yves Chibon d14691
            assignee=None,
Pierre-Yves Chibon d14691
            user='pingou',
Pierre-Yves Chibon d14691
            ticketfolder=None)
Pierre-Yves Chibon d14691
        self.session.commit()
Pierre-Yves Chibon d14691
        self.assertEqual(msg, 'Assignee reset')
Pierre-Yves Chibon d14691
Pierre-Yves Chibon d14691
        issues = progit.lib.search_issues(
Pierre-Yves Chibon d14691
            self.session, repo, assignee=False)
Pierre-Yves Chibon d14691
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon d14691
        self.assertEqual(issues[0].id, 1)
Pierre-Yves Chibon d14691
        self.assertEqual(issues[1].id, 2)
Pierre-Yves Chibon d14691
Pierre-Yves Chibon d14691
        issues = progit.lib.search_issues(
Pierre-Yves Chibon d14691
            self.session, repo, assignee=True)
Pierre-Yves Chibon d14691
        self.assertEqual(len(issues), 0)
Pierre-Yves Chibon d14691
Pierre-Yves Chibon e30eee
    @patch('progit.lib.git.update_git_ticket')
Pierre-Yves Chibon e30eee
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon e30eee
    def test_add_issue_comment(self, p_send_email, p_ugt):
Pierre-Yves Chibon e30eee
        """ Test the add_issue_comment of progit.lib. """
Pierre-Yves Chibon e30eee
        p_send_email.return_value = True
Pierre-Yves Chibon e30eee
        p_ugt.return_value = True
Pierre-Yves Chibon e30eee
Pierre-Yves Chibon e30eee
        tests.create_projects(self.session)
Pierre-Yves Chibon e30eee
        self.test_new_issue()
Pierre-Yves Chibon e30eee
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e30eee
Pierre-Yves Chibon e30eee
        # Before
Pierre-Yves Chibon e30eee
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon e30eee
        self.assertEqual(len(issue.comments), 0)
Pierre-Yves Chibon e30eee
Pierre-Yves Chibon 9f069c
        # Set the assignee by its email
Pierre-Yves Chibon 9f069c
        msg = progit.lib.add_issue_assignee(
Pierre-Yves Chibon 9f069c
            session=self.session,
Pierre-Yves Chibon 9f069c
            issue=issue,
Pierre-Yves Chibon 9f069c
            assignee='foo@bar.com',
Pierre-Yves Chibon 9f069c
            user='foo@pingou.com',
Pierre-Yves Chibon 9f069c
            ticketfolder=None)
Pierre-Yves Chibon 9f069c
        self.session.commit()
Pierre-Yves Chibon 9f069c
        self.assertEqual(msg, 'Issue assigned')
Pierre-Yves Chibon 9f069c
Pierre-Yves Chibon e30eee
        # Add a comment to that issue
Pierre-Yves Chibon e30eee
        msg = progit.lib.add_issue_comment(
Pierre-Yves Chibon e30eee
            session=self.session,
Pierre-Yves Chibon e30eee
            issue=issue,
Pierre-Yves Chibon e30eee
            comment='Hey look a comment!',
Pierre-Yves Chibon e30eee
            user='foo',
Pierre-Yves Chibon e30eee
            ticketfolder=None
Pierre-Yves Chibon e30eee
        )
Pierre-Yves Chibon e30eee
        self.session.commit()
Pierre-Yves Chibon e30eee
        self.assertEqual(msg, 'Comment added')
Pierre-Yves Chibon e30eee
Pierre-Yves Chibon e30eee
        # After
Pierre-Yves Chibon e30eee
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon e30eee
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon e30eee
        self.assertEqual(issue.comments[0].comment, 'Hey look a comment!')
Pierre-Yves Chibon e30eee
        self.assertEqual(issue.comments[0].user.user, 'foo')
Pierre-Yves Chibon e30eee
Pierre-Yves Chibon 228df2
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon 228df2
    def test_add_user_to_project(self, p_send_email):
Pierre-Yves Chibon 228df2
        """ Test the add_user_to_project of progit.lib. """
Pierre-Yves Chibon 228df2
        p_send_email.return_value = True
Pierre-Yves Chibon 228df2
Pierre-Yves Chibon 228df2
        tests.create_projects(self.session)
Pierre-Yves Chibon 228df2
Pierre-Yves Chibon 228df2
        # Before
Pierre-Yves Chibon 228df2
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 228df2
        self.assertEqual(len(repo.users), 0)
Pierre-Yves Chibon 228df2
Pierre-Yves Chibon 228df2
        # Add an user to a project
Pierre-Yves Chibon 228df2
        self.assertRaises(
Pierre-Yves Chibon 228df2
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 228df2
            progit.lib.add_user_to_project,
Pierre-Yves Chibon 228df2
            session=self.session,
Pierre-Yves Chibon 228df2
            project=repo,
Pierre-Yves Chibon 228df2
            user='foobar',
Pierre-Yves Chibon 228df2
        )
Pierre-Yves Chibon 228df2
Pierre-Yves Chibon 228df2
        msg = progit.lib.add_user_to_project(
Pierre-Yves Chibon 228df2
            session=self.session,
Pierre-Yves Chibon 228df2
            project=repo,
Pierre-Yves Chibon 228df2
            user='foo',
Pierre-Yves Chibon 228df2
        )
Pierre-Yves Chibon 228df2
        self.session.commit()
Pierre-Yves Chibon 228df2
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 228df2
Pierre-Yves Chibon 228df2
        # After
Pierre-Yves Chibon 228df2
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 228df2
        self.assertEqual(len(repo.users), 1)
Pierre-Yves Chibon 228df2
        self.assertEqual(repo.users[0].user, 'foo')
Pierre-Yves Chibon 228df2
Pierre-Yves Chibon 4fbc78
    def test_new_project(self):
Pierre-Yves Chibon 4fbc78
        """ Test the new_project of progit.lib. """
Pierre-Yves Chibon 4fbc78
        gitfolder = os.path.join(self.path, 'repos')
Pierre-Yves Chibon 4fbc78
        docfolder = os.path.join(self.path, 'docs')
Pierre-Yves Chibon 4fbc78
        ticketfolder = os.path.join(self.path, 'tickets')
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        os.mkdir(gitfolder)
Pierre-Yves Chibon 4fbc78
        os.mkdir(docfolder)
Pierre-Yves Chibon 4fbc78
        os.mkdir(ticketfolder)
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        # Create a new project
Pierre-Yves Chibon 4fbc78
        msg = progit.lib.new_project(
Pierre-Yves Chibon 4fbc78
            session=self.session,
Pierre-Yves Chibon 4fbc78
            user='pingou',
Pierre-Yves Chibon 4fbc78
            name='testproject',
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fbc78
            description='description for testproject',
Pierre-Yves Chibon 4fbc78
            parent_id=None
Pierre-Yves Chibon 4fbc78
        )
Pierre-Yves Chibon 4fbc78
        self.session.commit()
Pierre-Yves Chibon 4fbc78
        self.assertEqual(msg, 'Project "testproject" created')
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        repo = progit.lib.get_project(self.session, 'testproject')
Pierre-Yves Chibon 4fbc78
        self.assertEqual(repo.path, 'testproject.git')
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        gitrepo = os.path.join(gitfolder, repo.path)
Pierre-Yves Chibon 4fbc78
        docrepo = os.path.join(docfolder, repo.path)
Pierre-Yves Chibon 4fbc78
        ticketrepo = os.path.join(ticketfolder, repo.path)
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(gitrepo))
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(docrepo))
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(ticketrepo))
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        # Try re-creating it but all repos are existing
Pierre-Yves Chibon 4fbc78
        self.assertRaises(
Pierre-Yves Chibon 4fbc78
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 4fbc78
            progit.lib.new_project,
Pierre-Yves Chibon 4fbc78
            session=self.session,
Pierre-Yves Chibon 4fbc78
            user='pingou',
Pierre-Yves Chibon 4fbc78
            name='testproject',
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fbc78
            description='description for testproject',
Pierre-Yves Chibon 4fbc78
            parent_id=None
Pierre-Yves Chibon 4fbc78
        )
Pierre-Yves Chibon 4fbc78
        self.session.rollback()
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(gitrepo))
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(docrepo))
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(ticketrepo))
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        # Drop the main git repo and try again
Pierre-Yves Chibon 4fbc78
        shutil.rmtree(gitrepo)
Pierre-Yves Chibon 4fbc78
        self.assertRaises(
Pierre-Yves Chibon 4fbc78
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 4fbc78
            progit.lib.new_project,
Pierre-Yves Chibon 4fbc78
            session=self.session,
Pierre-Yves Chibon 4fbc78
            user='pingou',
Pierre-Yves Chibon 4fbc78
            name='testproject',
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fbc78
            description='description for testproject',
Pierre-Yves Chibon 4fbc78
            parent_id=None
Pierre-Yves Chibon 4fbc78
        )
Pierre-Yves Chibon 4fbc78
        self.session.rollback()
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        self.assertFalse(os.path.exists(gitrepo))
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(docrepo))
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(ticketrepo))
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        # Drop the doc repo and try again
Pierre-Yves Chibon 4fbc78
        shutil.rmtree(docrepo)
Pierre-Yves Chibon 4fbc78
        self.assertRaises(
Pierre-Yves Chibon 4fbc78
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 4fbc78
            progit.lib.new_project,
Pierre-Yves Chibon 4fbc78
            session=self.session,
Pierre-Yves Chibon 4fbc78
            user='pingou',
Pierre-Yves Chibon 4fbc78
            name='testproject',
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fbc78
            description='description for testproject',
Pierre-Yves Chibon 4fbc78
            parent_id=None
Pierre-Yves Chibon 4fbc78
        )
Pierre-Yves Chibon 4fbc78
        self.session.rollback()
Pierre-Yves Chibon 4fbc78
        self.assertFalse(os.path.exists(gitrepo))
Pierre-Yves Chibon 4fbc78
        self.assertFalse(os.path.exists(docrepo))
Pierre-Yves Chibon 4fbc78
        self.assertTrue(os.path.exists(ticketrepo))
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon b55847
    def test_update_project_settings(self):
Pierre-Yves Chibon b55847
        """ Test the update_project_settings of progit.lib. """
Pierre-Yves Chibon b55847
Pierre-Yves Chibon b55847
        tests.create_projects(self.session)
Pierre-Yves Chibon b55847
Pierre-Yves Chibon b55847
        # Before
Pierre-Yves Chibon b55847
        repo = progit.lib.get_project(self.session, 'test2')
Pierre-Yves Chibon b55847
        self.assertTrue(repo.issue_tracker)
Pierre-Yves Chibon b55847
        self.assertTrue(repo.project_docs)
Pierre-Yves Chibon b55847
Pierre-Yves Chibon b55847
        msg = progit.lib.update_project_settings(
Pierre-Yves Chibon b55847
            session=self.session,
Pierre-Yves Chibon b55847
            repo=repo,
Pierre-Yves Chibon b55847
            issue_tracker=True,
Pierre-Yves Chibon b55847
            project_docs=True
Pierre-Yves Chibon b55847
        )
Pierre-Yves Chibon b55847
        self.assertEqual(msg, 'No settings to change')
Pierre-Yves Chibon b55847
Pierre-Yves Chibon b55847
        msg = progit.lib.update_project_settings(
Pierre-Yves Chibon b55847
            session=self.session,
Pierre-Yves Chibon b55847
            repo=repo,
Pierre-Yves Chibon b55847
            issue_tracker=False,
Pierre-Yves Chibon b55847
            project_docs=False
Pierre-Yves Chibon b55847
        )
Pierre-Yves Chibon b55847
        self.assertEqual(msg, 'Edited successfully settings of repo: test2')
Pierre-Yves Chibon b55847
Pierre-Yves Chibon b55847
        # After
Pierre-Yves Chibon b55847
        repo = progit.lib.get_project(self.session, 'test2')
Pierre-Yves Chibon b55847
        self.assertFalse(repo.issue_tracker)
Pierre-Yves Chibon b55847
        self.assertFalse(repo.project_docs)
Pierre-Yves Chibon b55847
Pierre-Yves Chibon d8f141
    def test_search_projects(self):
Pierre-Yves Chibon d8f141
        """ Test the search_projects of progit.lib. """
Pierre-Yves Chibon d8f141
        tests.create_projects(self.session)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon d8f141
        projects = progit.lib.search_projects(self.session)
Pierre-Yves Chibon d8f141
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon d8f141
        self.assertEqual(projects[0].id, 1)
Pierre-Yves Chibon d8f141
        self.assertEqual(projects[1].id, 2)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon d8f141
        projects = progit.lib.search_projects(self.session, username='foo')
Pierre-Yves Chibon d8f141
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon d8f141
        projects = progit.lib.search_projects(self.session, username='pingou')
Pierre-Yves Chibon d8f141
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon d8f141
        self.assertEqual(projects[0].id, 1)
Pierre-Yves Chibon d8f141
        self.assertEqual(projects[1].id, 2)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon d8f141
        projects = progit.lib.search_projects(self.session, start=1)
Pierre-Yves Chibon d8f141
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon d8f141
        self.assertEqual(projects[0].id, 2)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon d8f141
        projects = progit.lib.search_projects(self.session, limit=1)
Pierre-Yves Chibon d8f141
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon d8f141
        self.assertEqual(projects[0].id, 1)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon d8f141
        projects = progit.lib.search_projects(self.session, count=True)
Pierre-Yves Chibon d8f141
        self.assertEqual(projects, 2)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon d30465
    def test_search_project_forked(self):
Pierre-Yves Chibon d30465
        """ Test the search_project for forked projects in progit.lib. """
Pierre-Yves Chibon d30465
        tests.create_projects(self.session)
Pierre-Yves Chibon d30465
Pierre-Yves Chibon d30465
        # Create two forked repo
Pierre-Yves Chibon d30465
        item = progit.lib.model.Project(
Pierre-Yves Chibon bad130
            user_id=2,  # foo
Pierre-Yves Chibon d30465
            name='test',
Pierre-Yves Chibon d30465
            description='test project #1',
Pierre-Yves Chibon d30465
            parent_id=1,
Pierre-Yves Chibon d30465
        )
Pierre-Yves Chibon d30465
        self.session.add(item)
Pierre-Yves Chibon d30465
Pierre-Yves Chibon d30465
        item = progit.lib.model.Project(
Pierre-Yves Chibon bad130
            user_id=2,  # foo
Pierre-Yves Chibon d30465
            name='test2',
Pierre-Yves Chibon d30465
            description='test project #2',
Pierre-Yves Chibon d30465
            parent_id=2,
Pierre-Yves Chibon d30465
        )
Pierre-Yves Chibon d30465
        self.session.add(item)
Pierre-Yves Chibon d30465
Pierre-Yves Chibon d30465
        # Since we have two forks, let's search them
Pierre-Yves Chibon d30465
        projects = progit.lib.search_projects(self.session, fork=True)
Pierre-Yves Chibon d30465
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon d30465
        projects = progit.lib.search_projects(self.session, fork=False)
Pierre-Yves Chibon d30465
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon d30465
Pierre-Yves Chibon a2be4b
    def test_get_tags_of_project(self):
Pierre-Yves Chibon a2be4b
        """ Test the get_tags_of_project of progit.lib. """
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon a2be4b
        self.test_add_issue_tag()
Pierre-Yves Chibon a2be4b
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon a2be4b
        tags = progit.lib.get_tags_of_project(self.session, repo)
Pierre-Yves Chibon a2be4b
        self.assertEqual([tag.tag for tag in tags], ['tag1'])
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon a2be4b
        tags = progit.lib.get_tags_of_project(
Pierre-Yves Chibon a2be4b
            self.session, repo, pattern='T*')
Pierre-Yves Chibon a2be4b
        self.assertEqual([tag.tag for tag in tags], ['tag1'])
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon a2be4b
        repo = progit.lib.get_project(self.session, 'test2')
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon a2be4b
        tags = progit.lib.get_tags_of_project(self.session, repo)
Pierre-Yves Chibon a2be4b
        self.assertEqual([tag.tag for tag in tags], [])
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon e35a86
    def test_get_issue_statuses(self):
Pierre-Yves Chibon e35a86
        """ Test the get_issue_statuses of progit.lib. """
Pierre-Yves Chibon e35a86
        statuses = progit.lib.get_issue_statuses(self.session)
Pierre-Yves Chibon e35a86
        self.assertEqual(
Pierre-Yves Chibon e35a86
            statuses, ['Open', 'Invalid', 'Insufficient data', 'Fixed'])
Pierre-Yves Chibon e35a86
Pierre-Yves Chibon 6386c3
    def test_set_up_user(self):
Pierre-Yves Chibon 6386c3
        """ Test the set_up_user of progit.lib. """
Pierre-Yves Chibon 6386c3
Pierre-Yves Chibon 6386c3
        items = progit.lib.search_user(self.session)
Pierre-Yves Chibon 6386c3
        self.assertEqual(2, len(items))
Pierre-Yves Chibon 6386c3
        self.assertEqual(1, items[0].id)
Pierre-Yves Chibon 6386c3
        self.assertEqual('pingou', items[0].user)
Pierre-Yves Chibon 6386c3
        self.assertEqual(2, items[1].id)
Pierre-Yves Chibon 6386c3
        self.assertEqual('foo', items[1].user)
Pierre-Yves Chibon 6386c3
Pierre-Yves Chibon 6386c3
        progit.lib.set_up_user(
Pierre-Yves Chibon 6386c3
            session=self.session,
Pierre-Yves Chibon 6386c3
            username='skvidal',
Pierre-Yves Chibon 6386c3
            fullname='Seth',
Pierre-Yves Chibon 6386c3
            user_email='skvidal@fp.o'
Pierre-Yves Chibon 6386c3
        )
Pierre-Yves Chibon 6386c3
        self.session.commit()
Pierre-Yves Chibon 6386c3
Pierre-Yves Chibon 6386c3
        items = progit.lib.search_user(self.session)
Pierre-Yves Chibon 6386c3
        self.assertEqual(3, len(items))
Pierre-Yves Chibon 6386c3
        self.assertEqual(1, items[0].id)
Pierre-Yves Chibon 6386c3
        self.assertEqual('pingou', items[0].user)
Pierre-Yves Chibon 6386c3
        self.assertEqual(2, items[1].id)
Pierre-Yves Chibon 6386c3
        self.assertEqual('foo', items[1].user)
Pierre-Yves Chibon 6386c3
        self.assertEqual(3, items[2].id)
Pierre-Yves Chibon 6386c3
        self.assertEqual('skvidal', items[2].user)
Pierre-Yves Chibon 65515c
        self.assertEqual('Seth', items[2].fullname)
Pierre-Yves Chibon 6386c3
        self.assertEqual(
Pierre-Yves Chibon 6386c3
            ['skvidal@fp.o'], [email.email for email in items[2].emails])
Pierre-Yves Chibon d88010
Pierre-Yves Chibon bd6684
        # Add the user a second time
Pierre-Yves Chibon bd6684
        progit.lib.set_up_user(
Pierre-Yves Chibon bd6684
            session=self.session,
Pierre-Yves Chibon bd6684
            username='skvidal',
Pierre-Yves Chibon 65515c
            fullname='Seth V',
Pierre-Yves Chibon bd6684
            user_email='skvidal@fp.o'
Pierre-Yves Chibon bd6684
        )
Pierre-Yves Chibon bd6684
        self.session.commit()
Pierre-Yves Chibon bd6684
        # Nothing changed
Pierre-Yves Chibon bd6684
        items = progit.lib.search_user(self.session)
Pierre-Yves Chibon bd6684
        self.assertEqual(3, len(items))
Pierre-Yves Chibon bd6684
        self.assertEqual('skvidal', items[2].user)
Pierre-Yves Chibon 65515c
        self.assertEqual('Seth V', items[2].fullname)
Pierre-Yves Chibon bd6684
        self.assertEqual(
Pierre-Yves Chibon bd6684
            ['skvidal@fp.o'], [email.email for email in items[2].emails])
Pierre-Yves Chibon bd6684
Pierre-Yves Chibon bd6684
        # Add the user a third time with a different email
Pierre-Yves Chibon bd6684
        progit.lib.set_up_user(
Pierre-Yves Chibon bd6684
            session=self.session,
Pierre-Yves Chibon bd6684
            username='skvidal',
Pierre-Yves Chibon bd6684
            fullname='Seth',
Pierre-Yves Chibon bd6684
            user_email='svidal@fp.o'
Pierre-Yves Chibon bd6684
        )
Pierre-Yves Chibon bd6684
        self.session.commit()
Pierre-Yves Chibon bd6684
        # Email added
Pierre-Yves Chibon bd6684
        items = progit.lib.search_user(self.session)
Pierre-Yves Chibon bd6684
        self.assertEqual(3, len(items))
Pierre-Yves Chibon bd6684
        self.assertEqual('skvidal', items[2].user)
Pierre-Yves Chibon bd6684
        self.assertEqual(
Pierre-Yves Chibon bd6684
            ['skvidal@fp.o', 'svidal@fp.o'],
Pierre-Yves Chibon bd6684
            [email.email for email in items[2].emails])
Pierre-Yves Chibon bd6684
Pierre-Yves Chibon c0cb4b
    def test_update_user_ssh(self):
Pierre-Yves Chibon c0cb4b
        """ Test the update_user_ssh of progit.lib. """
Pierre-Yves Chibon c0cb4b
Pierre-Yves Chibon c0cb4b
        # Before
Pierre-Yves Chibon c0cb4b
        user = progit.lib.search_user(self.session, username='foo')
Pierre-Yves Chibon c0cb4b
        self.assertEqual(user.public_ssh_key, None)
Pierre-Yves Chibon c0cb4b
Pierre-Yves Chibon c0cb4b
        msg = progit.lib.update_user_ssh(self.session, user, 'blah')
Pierre-Yves Chibon c0cb4b
        self.assertEqual(msg, 'Public ssh key updated')
Pierre-Yves Chibon c0cb4b
Pierre-Yves Chibon c0cb4b
        msg = progit.lib.update_user_ssh(self.session, user, 'blah')
Pierre-Yves Chibon c0cb4b
        self.assertEqual(msg, 'Nothing to update')
Pierre-Yves Chibon c0cb4b
Pierre-Yves Chibon 65515c
        msg = progit.lib.update_user_ssh(self.session, 'foo', None)
Pierre-Yves Chibon c0cb4b
        self.assertEqual(msg, 'Public ssh key updated')
Pierre-Yves Chibon c0cb4b
Pierre-Yves Chibon b6874d
    def test_avatar_url(self):
Pierre-Yves Chibon b6874d
        """ Test the avatar_url of progit.lib. """
Pierre-Yves Chibon b6874d
        output = progit.lib.avatar_url('pingou')
Pierre-Yves Chibon b6874d
        self.assertEqual(
Pierre-Yves Chibon b6874d
            output,
Pierre-Yves Chibon b6874d
            'https://seccdn.libravatar.org/avatar/'
Pierre-Yves Chibon b6874d
            '01fe73d687f4db328da1183f2a1b5b22962ca9d9c50f0728aafeac974856311c'
Pierre-Yves Chibon b6874d
            '?s=64&d=retro')
Pierre-Yves Chibon b6874d
Pierre-Yves Chibon 4fe9b6
    def test_fork_project(self):
Pierre-Yves Chibon 4fe9b6
        """ Test the fork_project of progit.lib. """
Pierre-Yves Chibon 4fe9b6
        gitfolder = os.path.join(self.path, 'repos')
Pierre-Yves Chibon 4fe9b6
        docfolder = os.path.join(self.path, 'docs')
Pierre-Yves Chibon 4fe9b6
        ticketfolder = os.path.join(self.path, 'tickets')
Pierre-Yves Chibon 4fe9b6
        forkfolder = os.path.join(self.path, 'forks')
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        os.mkdir(gitfolder)
Pierre-Yves Chibon 4fe9b6
        os.mkdir(docfolder)
Pierre-Yves Chibon 4fe9b6
        os.mkdir(ticketfolder)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        projects = progit.lib.search_projects(self.session)
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Create a new project
Pierre-Yves Chibon 4fe9b6
        msg = progit.lib.new_project(
Pierre-Yves Chibon 4fe9b6
            session=self.session,
Pierre-Yves Chibon 4fe9b6
            user='pingou',
Pierre-Yves Chibon 4fe9b6
            name='testproject',
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fe9b6
            description='description for testproject',
Pierre-Yves Chibon 4fe9b6
            parent_id=None
Pierre-Yves Chibon 4fe9b6
        )
Pierre-Yves Chibon 4fe9b6
        self.session.commit()
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(msg, 'Project "testproject" created')
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        projects = progit.lib.search_projects(self.session)
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        repo = progit.lib.get_project(self.session, 'testproject')
Pierre-Yves Chibon 4fe9b6
        gitrepo = os.path.join(gitfolder, repo.path)
Pierre-Yves Chibon 4fe9b6
        docrepo = os.path.join(docfolder, repo.path)
Pierre-Yves Chibon 4fe9b6
        ticketrepo = os.path.join(ticketfolder, repo.path)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        self.assertTrue(os.path.exists(gitrepo))
Pierre-Yves Chibon 4fe9b6
        self.assertTrue(os.path.exists(docrepo))
Pierre-Yves Chibon 4fe9b6
        self.assertTrue(os.path.exists(ticketrepo))
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Fail to fork
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Cannot fail your own project
Pierre-Yves Chibon 4fe9b6
        self.assertRaises(
Pierre-Yves Chibon 4fe9b6
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 4fe9b6
            progit.lib.fork_project,
Pierre-Yves Chibon 4fe9b6
            session=self.session,
Pierre-Yves Chibon 4fe9b6
            user='pingou',
Pierre-Yves Chibon 4fe9b6
            repo=repo,
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            forkfolder=forkfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fe9b6
        )
Pierre-Yves Chibon 4fe9b6
        self.session.rollback()
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Git repo exists
Pierre-Yves Chibon 4fe9b6
        grepo = '%s.git' % os.path.join(forkfolder, 'foo', 'testproject')
Pierre-Yves Chibon 4fe9b6
        os.makedirs(grepo)
Pierre-Yves Chibon 4fe9b6
        self.assertRaises(
Pierre-Yves Chibon 4fe9b6
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 4fe9b6
            progit.lib.fork_project,
Pierre-Yves Chibon 4fe9b6
            session=self.session,
Pierre-Yves Chibon 4fe9b6
            user='foo',
Pierre-Yves Chibon 4fe9b6
            repo=repo,
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            forkfolder=forkfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fe9b6
        )
Pierre-Yves Chibon 4fe9b6
        self.session.rollback()
Pierre-Yves Chibon 4fe9b6
        shutil.rmtree(grepo)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Doc repo exists
Pierre-Yves Chibon 4fe9b6
        grepo = '%s.git' % os.path.join(docfolder, 'foo', 'testproject')
Pierre-Yves Chibon 4fe9b6
        os.makedirs(grepo)
Pierre-Yves Chibon 4fe9b6
        self.assertRaises(
Pierre-Yves Chibon 4fe9b6
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 4fe9b6
            progit.lib.fork_project,
Pierre-Yves Chibon 4fe9b6
            session=self.session,
Pierre-Yves Chibon 4fe9b6
            user='foo',
Pierre-Yves Chibon 4fe9b6
            repo=repo,
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            forkfolder=forkfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fe9b6
        )
Pierre-Yves Chibon 4fe9b6
        self.session.rollback()
Pierre-Yves Chibon 4fe9b6
        shutil.rmtree(grepo)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Ticket repo exists
Pierre-Yves Chibon 4fe9b6
        grepo = '%s.git' % os.path.join(ticketfolder, 'foo', 'testproject')
Pierre-Yves Chibon 4fe9b6
        os.makedirs(grepo)
Pierre-Yves Chibon 4fe9b6
        self.assertRaises(
Pierre-Yves Chibon 4fe9b6
            progit.exceptions.ProgitException,
Pierre-Yves Chibon 4fe9b6
            progit.lib.fork_project,
Pierre-Yves Chibon 4fe9b6
            session=self.session,
Pierre-Yves Chibon 4fe9b6
            user='foo',
Pierre-Yves Chibon 4fe9b6
            repo=repo,
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            forkfolder=forkfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fe9b6
        )
Pierre-Yves Chibon 4fe9b6
        self.session.rollback()
Pierre-Yves Chibon 4fe9b6
        shutil.rmtree(grepo)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        projects = progit.lib.search_projects(self.session)
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Fork worked
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        msg = progit.lib.fork_project(
Pierre-Yves Chibon 4fe9b6
            session=self.session,
Pierre-Yves Chibon 4fe9b6
            user='foo',
Pierre-Yves Chibon 4fe9b6
            repo=repo,
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            forkfolder=forkfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fe9b6
        )
Pierre-Yves Chibon 4fe9b6
        self.session.commit()
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(
Pierre-Yves Chibon 4fe9b6
            msg, 'Repo "testproject" cloned to "foo/testproject"')
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        projects = progit.lib.search_projects(self.session)
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        # Fork a fork
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        repo = progit.lib.get_project(
Pierre-Yves Chibon 4fe9b6
            self.session, 'testproject', user='foo')
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        msg = progit.lib.fork_project(
Pierre-Yves Chibon 4fe9b6
            session=self.session,
Pierre-Yves Chibon 4fe9b6
            user='pingou',
Pierre-Yves Chibon 4fe9b6
            repo=repo,
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            forkfolder=forkfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 4fe9b6
        )
Pierre-Yves Chibon 4fe9b6
        self.session.commit()
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(
Pierre-Yves Chibon 4fe9b6
            msg, 'Repo "testproject" cloned to "pingou/testproject"')
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon 4fe9b6
        projects = progit.lib.search_projects(self.session)
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(len(projects), 3)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon d62e1f
    def test_new_pull_request(self):
Pierre-Yves Chibon d62e1f
        """ test new_pull_request of progit.lib. """
Pierre-Yves Chibon d62e1f
        tests.create_projects(self.session)
Pierre-Yves Chibon d62e1f
Pierre-Yves Chibon d62e1f
        # Create a forked repo
Pierre-Yves Chibon d62e1f
        item = progit.lib.model.Project(
Pierre-Yves Chibon d62e1f
            user_id=1,  # pingou
Pierre-Yves Chibon d62e1f
            name='test',
Pierre-Yves Chibon d62e1f
            description='test project #1',
Pierre-Yves Chibon d62e1f
            parent_id=1,
Pierre-Yves Chibon d62e1f
        )
Pierre-Yves Chibon d62e1f
        self.session.commit()
Pierre-Yves Chibon d62e1f
        self.session.add(item)
Pierre-Yves Chibon d62e1f
Pierre-Yves Chibon b3ed64
        # Add an extra user to project `foo`
Pierre-Yves Chibon b3ed64
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon b3ed64
        msg = progit.lib.add_user_to_project(
Pierre-Yves Chibon b3ed64
            session=self.session,
Pierre-Yves Chibon b3ed64
            project=repo,
Pierre-Yves Chibon b3ed64
            user='foo',
Pierre-Yves Chibon b3ed64
        )
Pierre-Yves Chibon b3ed64
        self.session.commit()
Pierre-Yves Chibon b3ed64
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon b3ed64
Pierre-Yves Chibon d62e1f
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon d62e1f
        forked_repo = progit.lib.get_project(
Pierre-Yves Chibon d62e1f
            self.session, 'test', user='pingou')
Pierre-Yves Chibon d62e1f
Pierre-Yves Chibon d62e1f
        msg = progit.lib.new_pull_request(
Pierre-Yves Chibon d62e1f
            session=self.session,
Pierre-Yves Chibon d62e1f
            repo_from=forked_repo,
Pierre-Yves Chibon d62e1f
            branch_from='master',
Pierre-Yves Chibon d62e1f
            repo_to=repo,
Pierre-Yves Chibon d62e1f
            branch_to='master',
Pierre-Yves Chibon d62e1f
            title='test pull-request',
Pierre-Yves Chibon d62e1f
            user='pingou'
Pierre-Yves Chibon d62e1f
        )
Pierre-Yves Chibon d62e1f
        self.assertEqual(msg, 'Request created')
Pierre-Yves Chibon d62e1f
Pierre-Yves Chibon dc8159
    def test_add_pull_request_comment(self):
Pierre-Yves Chibon dc8159
        """ Test add_pull_request_comment of progit.lib. """
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon dc8159
        self.test_new_pull_request()
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon dc8159
        request = progit.lib.search_pull_requests(self.session, requestid=1)
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon dc8159
        msg = progit.lib.add_pull_request_comment(
Pierre-Yves Chibon dc8159
            session=self.session,
Pierre-Yves Chibon dc8159
            request=request,
Pierre-Yves Chibon dc8159
            commit='commithash',
Pierre-Yves Chibon dc8159
            filename='file',
Pierre-Yves Chibon dc8159
            row=None,
Pierre-Yves Chibon dc8159
            comment='This is awesome, I got to remember it!',
Pierre-Yves Chibon dc8159
            user='foo'
Pierre-Yves Chibon dc8159
        )
Pierre-Yves Chibon dc8159
        self.assertEqual(msg, 'Comment added')
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon 566a8b
    def test_search_pull_requests(self):
Pierre-Yves Chibon 566a8b
        """ Test search_pull_requests of progit.lib. """
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon 566a8b
        self.test_new_pull_request()
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon 566a8b
        prs = progit.lib.search_pull_requests(
Pierre-Yves Chibon 566a8b
            session=self.session
Pierre-Yves Chibon 566a8b
        )
Pierre-Yves Chibon 566a8b
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon 566a8b
        prs = progit.lib.search_pull_requests(
Pierre-Yves Chibon 566a8b
            session=self.session,
Pierre-Yves Chibon 566a8b
            project_id=1
Pierre-Yves Chibon 566a8b
        )
Pierre-Yves Chibon 566a8b
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon 566a8b
        prs = progit.lib.search_pull_requests(
Pierre-Yves Chibon 566a8b
            session=self.session,
Pierre-Yves Chibon 566a8b
            project_id_from=3
Pierre-Yves Chibon 566a8b
        )
Pierre-Yves Chibon 566a8b
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon 566a8b
        prs = progit.lib.search_pull_requests(
Pierre-Yves Chibon 566a8b
            session=self.session,
Pierre-Yves Chibon 468c90
            status=False
Pierre-Yves Chibon 566a8b
        )
Pierre-Yves Chibon 566a8b
        self.assertEqual(len(prs), 0)
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon b9664f
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon b9664f
    def test_close_pull_request(self, send_email):
Pierre-Yves Chibon 6dfdf2
        """ Test close_pull_request of progit.lib. """
Pierre-Yves Chibon b9664f
        send_email.return_value = True
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon 6dfdf2
        self.test_new_pull_request()
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon 6dfdf2
        request = progit.lib.search_pull_requests(self.session, requestid=1)
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon 6dfdf2
        progit.lib.close_pull_request(
Pierre-Yves Chibon 6dfdf2
            session=self.session,
Pierre-Yves Chibon 6dfdf2
            request=request,
Pierre-Yves Chibon b9664f
            user=tests.FakeUser(),
Pierre-Yves Chibon 6dfdf2
            merged=True)
Pierre-Yves Chibon 6dfdf2
        self.session.commit()
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon 6dfdf2
        prs = progit.lib.search_pull_requests(
Pierre-Yves Chibon 6dfdf2
            session=self.session,
Pierre-Yves Chibon 6dfdf2
            status=False
Pierre-Yves Chibon 6dfdf2
        )
Pierre-Yves Chibon 6dfdf2
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon 6dfdf2
        # Does not change much, just the notification sent
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon 6dfdf2
        progit.lib.close_pull_request(
Pierre-Yves Chibon 6dfdf2
            session=self.session,
Pierre-Yves Chibon 6dfdf2
            request=request,
Pierre-Yves Chibon b9664f
            user=tests.FakeUser(),
Pierre-Yves Chibon 6dfdf2
            merged=False)
Pierre-Yves Chibon 6dfdf2
        self.session.commit()
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon 6dfdf2
        prs = progit.lib.search_pull_requests(
Pierre-Yves Chibon 6dfdf2
            session=self.session,
Pierre-Yves Chibon 6dfdf2
            status=False
Pierre-Yves Chibon 6dfdf2
        )
Pierre-Yves Chibon 6dfdf2
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon bd6684
Pierre-Yves Chibon d88010
if __name__ == '__main__':
Pierre-Yves Chibon d88010
    SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitLibtests)
Pierre-Yves Chibon d88010
    unittest.TextTestRunner(verbosity=2).run(SUITE)