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 fe5017
import pagure.lib
Pierre-Yves Chibon 538301
import tests
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
Pierre-Yves Chibon fe5017
class PagureLibtests(tests.Modeltests):
Pierre-Yves Chibon fe5017
    """ Tests for pagure.lib """
Pierre-Yves Chibon d88010
Pierre-Yves Chibon d88010
    def test_get_next_id(self):
Pierre-Yves Chibon fe5017
        """ Test the get_next_id function of pagure.lib. """
Pierre-Yves Chibon 538301
        tests.create_projects(self.session)
Pierre-Yves Chibon fe5017
        self.assertEqual(1, pagure.lib.get_next_id(self.session, 1))
Pierre-Yves Chibon d88010
Pierre-Yves Chibon f74336
    def test_search_user_all(self):
Pierre-Yves Chibon fe5017
        """ Test the search_user of pagure.lib. """
Pierre-Yves Chibon f74336
Pierre-Yves Chibon f74336
        # Retrieve all users
Pierre-Yves Chibon fe5017
        items = pagure.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 fe5017
        """ Test the search_user of pagure.lib. """
Pierre-Yves Chibon c7ee0c
Pierre-Yves Chibon c7ee0c
        # Retrieve user by username
Pierre-Yves Chibon fe5017
        item = pagure.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 fe5017
        item = pagure.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 fe5017
        """ Test the search_user of pagure.lib. """
Pierre-Yves Chibon f5cf0f
Pierre-Yves Chibon f5cf0f
        # Retrieve user by email
Pierre-Yves Chibon fe5017
        item = pagure.lib.search_user(self.session, email='foo@foo.com')
Pierre-Yves Chibon f5cf0f
        self.assertEqual(None, item)
Pierre-Yves Chibon f5cf0f
Pierre-Yves Chibon fe5017
        item = pagure.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 fe5017
        item = pagure.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 fe5017
        """ Test the search_user of pagure.lib. """
Pierre-Yves Chibon fe688c
Pierre-Yves Chibon fe688c
        # Retrieve user by token
Pierre-Yves Chibon fe5017
        item = pagure.lib.search_user(self.session, token='aaa')
Pierre-Yves Chibon fe688c
        self.assertEqual(None, item)
Pierre-Yves Chibon fe688c
Pierre-Yves Chibon fe5017
        item = pagure.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 0e3e63
            default_email='bar@pingou.com',
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 fe5017
        item = pagure.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 fe5017
        """ Test the search_user of pagure.lib. """
Pierre-Yves Chibon 04a157
Pierre-Yves Chibon 04a157
        # Retrieve user by pattern
Pierre-Yves Chibon fe5017
        item = pagure.lib.search_user(self.session, pattern='a*')
Pierre-Yves Chibon 04a157
        self.assertEqual([], item)
Pierre-Yves Chibon 04a157
Pierre-Yves Chibon fe5017
        item = pagure.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 0e3e63
            default_email='bar@pingou.com',
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 fe5017
        items = pagure.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 fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon a42f77
    def test_new_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the new_issue of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon a42f77
        # Before
Pierre-Yves Chibon fe5017
        issues = pagure.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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 71feec
            session=self.session,
Pierre-Yves Chibon 71feec
            project=repo,
Pierre-Yves Chibon a5a9ad
            new_user='foo',
Pierre-Yves Chibon a5a9ad
            user='pingou'
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 fe5017
        msg = pagure.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 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 91556a
Pierre-Yves Chibon fe5017
        msg = pagure.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 7812b6
            status='Open',
Pierre-Yves Chibon 91556a
            ticketfolder=None
Pierre-Yves Chibon 91556a
        )
Pierre-Yves Chibon 91556a
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue #2')
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon a42f77
        # After
Pierre-Yves Chibon fe5017
        issues = pagure.lib.search_issues(self.session, repo)
Pierre-Yves Chibon 91556a
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon a42f77
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon a5099b
    def test_edit_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the edit_issue of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a5099b
Pierre-Yves Chibon a5099b
        # Edit the issue
Pierre-Yves Chibon fe5017
        msg = pagure.lib.edit_issue(
Pierre-Yves Chibon a5099b
            session=self.session,
Pierre-Yves Chibon a5099b
            issue=issue,
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 7e6046
            ticketfolder=None)
Pierre-Yves Chibon 7e6046
        self.session.commit()
Pierre-Yves Chibon d22433
        self.assertEqual(msg, None)
Pierre-Yves Chibon 7e6046
Pierre-Yves Chibon fe5017
        msg = pagure.lib.edit_issue(
Pierre-Yves Chibon 7e6046
            session=self.session,
Pierre-Yves Chibon 7e6046
            issue=issue,
Pierre-Yves Chibon a5a9ad
            user='pingou',
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 d22433
        self.assertEqual(msg, None)
Pierre-Yves Chibon 7e6046
Pierre-Yves Chibon fe5017
        msg = pagure.lib.edit_issue(
Pierre-Yves Chibon 7e6046
            session=self.session,
Pierre-Yves Chibon 7e6046
            issue=issue,
Pierre-Yves Chibon a5a9ad
            user='pingou',
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 7a762d
            status='Invalid',
Pierre-Yves Chibon 7a762d
            private=True
Pierre-Yves Chibon 7a762d
        )
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 fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 688e74
    def test_add_issue_dependency(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the add_issue_dependency of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon fe5017
        issue_blocked = pagure.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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 fe5017
        msg = pagure.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 fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 8393f9
    def test_add_issue_tag(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the add_issue_tag of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.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 fe5017
        msg = pagure.lib.add_issue_tag(
Pierre-Yves Chibon 8393f9
            session=self.session,
Pierre-Yves Chibon 8393f9
            issue=issue,
Pierre-Yves Chibon df35d8
            tags='tag1',
Pierre-Yves Chibon 8393f9
            user='pingou',
Pierre-Yves Chibon 8393f9
            ticketfolder=None)
Pierre-Yves Chibon 8393f9
        self.session.commit()
Pierre-Yves Chibon df35d8
        self.assertEqual(msg, 'Tag added: tag1')
Pierre-Yves Chibon 8393f9
Pierre-Yves Chibon b4f437
        # Try a second time
Pierre-Yves Chibon df35d8
        msg = pagure.lib.add_issue_tag(
Pierre-Yves Chibon b4f437
            session=self.session,
Pierre-Yves Chibon b4f437
            issue=issue,
Pierre-Yves Chibon df35d8
            tags='tag1',
Pierre-Yves Chibon b4f437
            user='pingou',
Pierre-Yves Chibon b4f437
            ticketfolder=None)
Pierre-Yves Chibon df35d8
        self.session.commit()
Pierre-Yves Chibon df35d8
        self.assertEqual(msg, 'Nothing to add')
Pierre-Yves Chibon b4f437
Pierre-Yves Chibon fe5017
        issues = pagure.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 fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 5ea1e2
    def test_remove_tags(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the remove_tags of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon 07093f
        self.assertRaises(
Pierre-Yves Chibon fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.lib.remove_tags,
Pierre-Yves Chibon 07093f
            session=self.session,
Pierre-Yves Chibon 07093f
            project=repo,
Pierre-Yves Chibon 86840f
            tags='foo',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 86840f
            ticketfolder=None)
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon fe5017
        msgs = pagure.lib.remove_tags(
Pierre-Yves Chibon 07093f
            session=self.session,
Pierre-Yves Chibon 07093f
            project=repo,
Pierre-Yves Chibon 86840f
            tags='tag1',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 86840f
            ticketfolder=None)
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon 07093f
        self.assertEqual(msgs, [u'Removed tag: tag1'])
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 248fd9
    def test_remove_tags_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the remove_tags_issue of pagure.lib. """
Pierre-Yves Chibon 248fd9
        p_send_email.return_value = True
Pierre-Yves Chibon 248fd9
        p_ugt.return_value = True
Pierre-Yves Chibon 248fd9
Pierre-Yves Chibon 248fd9
        self.test_add_issue_tag()
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 248fd9
Pierre-Yves Chibon fe5017
        msgs = pagure.lib.remove_tags_issue(
Pierre-Yves Chibon 248fd9
            session=self.session,
Pierre-Yves Chibon 248fd9
            issue=issue,
Pierre-Yves Chibon 248fd9
            tags='tag1',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 248fd9
            ticketfolder=None)
Pierre-Yves Chibon 248fd9
Pierre-Yves Chibon df35d8
        self.assertEqual(msgs, 'Removed tag: tag1')
Pierre-Yves Chibon 248fd9
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon e1fce0
    def test_edit_issue_tags(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the edit_issue_tags of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon e1fce0
Pierre-Yves Chibon e1fce0
        self.assertRaises(
Pierre-Yves Chibon fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 86840f
            new_tag='bar',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 86840f
            ticketfolder=None,
Pierre-Yves Chibon 86840f
        )
Pierre-Yves Chibon e1fce0
Pierre-Yves Chibon fe5017
        msgs = pagure.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 86840f
            new_tag='tag2',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 86840f
            ticketfolder=None,
Pierre-Yves Chibon 86840f
        )
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 86840f
            new_tag='tag2',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 86840f
            ticketfolder=None,
Pierre-Yves Chibon 86840f
        )
Pierre-Yves Chibon 07093f
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 663645
    def test_search_issues(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the search_issues of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        # All issues
Pierre-Yves Chibon fe5017
        issues = pagure.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 fe5017
        issues = pagure.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 fe5017
        issues = pagure.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 fe5017
        issues = pagure.lib.search_issues(self.session, repo, tags='foo')
Pierre-Yves Chibon 663645
        self.assertEqual(len(issues), 0)
Pierre-Yves Chibon fe5017
        issues = pagure.lib.search_issues(self.session, repo, tags='!foo')
Pierre-Yves Chibon 68021a
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon 663645
Pierre-Yves Chibon 663645
        # Issue by id
Pierre-Yves Chibon fe5017
        issue = pagure.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 fe5017
        issues = pagure.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 68021a
        # Issues by assignee
Pierre-Yves Chibon fe5017
        issues = pagure.lib.search_issues(self.session, repo, assignee='foo')
Pierre-Yves Chibon 68021a
        self.assertEqual(len(issues), 0)
Pierre-Yves Chibon fe5017
        issues = pagure.lib.search_issues(self.session, repo, assignee='!foo')
Pierre-Yves Chibon 68021a
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon 68021a
Pierre-Yves Chibon fe5017
        issues = pagure.lib.search_issues(self.session, repo, private='foo')
Pierre-Yves Chibon 68021a
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon 68021a
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon a96644
    def test_add_issue_assignee(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the add_issue_assignee of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a96644
Pierre-Yves Chibon a96644
        # Before
Pierre-Yves Chibon fe5017
        issues = pagure.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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 fe5017
        msg = pagure.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 fe5017
        msg = pagure.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 fe5017
        issues = pagure.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 fe5017
        issues = pagure.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 fe5017
        issues = pagure.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 fe5017
        msg = pagure.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 fe5017
        issues = pagure.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 fe5017
        issues = pagure.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 fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon e30eee
    def test_add_issue_comment(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the add_issue_comment of pagure.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
        self.test_new_issue()
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e30eee
Pierre-Yves Chibon e30eee
        # Before
Pierre-Yves Chibon fe5017
        issue = pagure.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 fe5017
        msg = pagure.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 fe5017
        msg = pagure.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 fe5017
        issue = pagure.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 fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 228df2
    def test_add_user_to_project(self, p_send_email):
Pierre-Yves Chibon fe5017
        """ Test the add_user_to_project of pagure.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 fe5017
        repo = pagure.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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.lib.add_user_to_project,
Pierre-Yves Chibon 228df2
            session=self.session,
Pierre-Yves Chibon 228df2
            project=repo,
Pierre-Yves Chibon a5a9ad
            new_user='foobar',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 228df2
        )
Pierre-Yves Chibon 228df2
Pierre-Yves Chibon fe5017
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 228df2
            session=self.session,
Pierre-Yves Chibon 228df2
            project=repo,
Pierre-Yves Chibon a5a9ad
            new_user='foo',
Pierre-Yves Chibon a5a9ad
            user='pingou',
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 fe5017
        repo = pagure.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 fe5017
        """ Test the new_project of pagure.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 86840f
        requestfolder = os.path.join(self.path, 'requests')
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 86840f
        os.mkdir(requestfolder)
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon 4fbc78
        # Create a new project
Pierre-Yves Chibon fe5017
        msg = pagure.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 7b176d
            blacklist=[],
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 86840f
            requestfolder=requestfolder,
Pierre-Yves Chibon 4fbc78
            description='description for testproject',
Pierre-Yves Chibon 86840f
            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 fe5017
        repo = pagure.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 86840f
        requestrepo = os.path.join(requestfolder, 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 86840f
        self.assertTrue(os.path.exists(requestrepo))
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 7b176d
            blacklist=[],
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 86840f
            requestfolder=requestfolder,
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 86840f
        self.assertTrue(os.path.exists(requestrepo))
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 7b176d
            blacklist=[],
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 86840f
            requestfolder=requestfolder,
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 86840f
        self.assertTrue(os.path.exists(requestrepo))
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 7b176d
            blacklist=[],
Pierre-Yves Chibon 4fbc78
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fbc78
            docfolder=docfolder,
Pierre-Yves Chibon 4fbc78
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 86840f
            requestfolder=requestfolder,
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 86840f
        self.assertTrue(os.path.exists(requestrepo))
Pierre-Yves Chibon 86840f
Pierre-Yves Chibon 86840f
        # Drop the request repo and try again
Pierre-Yves Chibon 86840f
        shutil.rmtree(ticketrepo)
Pierre-Yves Chibon 86840f
        self.assertRaises(
Pierre-Yves Chibon fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.lib.new_project,
Pierre-Yves Chibon 86840f
            session=self.session,
Pierre-Yves Chibon 86840f
            user='pingou',
Pierre-Yves Chibon 86840f
            name='testproject',
Pierre-Yves Chibon 7b176d
            blacklist=[],
Pierre-Yves Chibon 86840f
            gitfolder=gitfolder,
Pierre-Yves Chibon 86840f
            docfolder=docfolder,
Pierre-Yves Chibon 86840f
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 86840f
            requestfolder=requestfolder,
Pierre-Yves Chibon 86840f
            description='description for testproject',
Pierre-Yves Chibon 86840f
            parent_id=None
Pierre-Yves Chibon 86840f
        )
Pierre-Yves Chibon 86840f
        self.session.rollback()
Pierre-Yves Chibon 86840f
        self.assertFalse(os.path.exists(gitrepo))
Pierre-Yves Chibon 86840f
        self.assertFalse(os.path.exists(docrepo))
Pierre-Yves Chibon 86840f
        self.assertFalse(os.path.exists(ticketrepo))
Pierre-Yves Chibon 86840f
        self.assertTrue(os.path.exists(requestrepo))
Pierre-Yves Chibon 4fbc78
Pierre-Yves Chibon b55847
    def test_update_project_settings(self):
Pierre-Yves Chibon fe5017
        """ Test the update_project_settings of pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test2')
Pierre-Yves Chibon 719bdd
        self.assertTrue(repo.settings['issue_tracker'])
Pierre-Yves Chibon 719bdd
        self.assertTrue(repo.settings['project_documentation'])
Pierre-Yves Chibon b55847
Pierre-Yves Chibon fe5017
        msg = pagure.lib.update_project_settings(
Pierre-Yves Chibon b55847
            session=self.session,
Pierre-Yves Chibon b55847
            repo=repo,
Pierre-Yves Chibon 719bdd
            settings={
Pierre-Yves Chibon 719bdd
                'issue_tracker': True,
Pierre-Yves Chibon 719bdd
                'project_documentation': True,
Pierre-Yves Chibon da0db9
                'pull_requests': True,
Pierre-Yves Chibon e2259d
                'Only_assignee_can_merge_pull-request': False,
Pierre-Yves Chibon e2259d
                'Minimum_score_to_merge_pull-request': -1,
Pierre-Yves Chibon e2259d
                'Web-hooks': None,
Pierre-Yves Chibon 719bdd
            },
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon b55847
        )
Pierre-Yves Chibon b55847
        self.assertEqual(msg, 'No settings to change')
Pierre-Yves Chibon b55847
Pierre-Yves Chibon fe5017
        msg = pagure.lib.update_project_settings(
Pierre-Yves Chibon b55847
            session=self.session,
Pierre-Yves Chibon b55847
            repo=repo,
Pierre-Yves Chibon 719bdd
            settings={
Pierre-Yves Chibon 719bdd
                'issue_tracker': False,
Pierre-Yves Chibon 719bdd
                'project_documentation': False,
Pierre-Yves Chibon e2259d
                'pull_requests': False,
Pierre-Yves Chibon e2259d
                'Only_assignee_can_merge_pull-request': False,
Pierre-Yves Chibon e2259d
                'Minimum_score_to_merge_pull-request': -1,
Pierre-Yves Chibon e2259d
                'Web-hooks': None,
Pierre-Yves Chibon 719bdd
            },
Pierre-Yves Chibon a5a9ad
            user='pingou',
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 fe5017
        repo = pagure.lib.get_project(self.session, 'test2')
Pierre-Yves Chibon 719bdd
        self.assertFalse(repo.settings['issue_tracker'])
Pierre-Yves Chibon 719bdd
        self.assertFalse(repo.settings['project_documentation'])
Pierre-Yves Chibon 719bdd
        self.assertFalse(repo.settings['pull_requests'])
Pierre-Yves Chibon b55847
Pierre-Yves Chibon d8f141
    def test_search_projects(self):
Pierre-Yves Chibon fe5017
        """ Test the search_projects of pagure.lib. """
Pierre-Yves Chibon d8f141
        tests.create_projects(self.session)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon fe5017
        projects = pagure.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 fe5017
        projects = pagure.lib.search_projects(self.session, username='foo')
Pierre-Yves Chibon d8f141
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon d8f141
Pierre-Yves Chibon fe5017
        projects = pagure.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 fe5017
        projects = pagure.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 fe5017
        projects = pagure.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 fe5017
        projects = pagure.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 fe5017
        """ Test the search_project for forked projects in pagure.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 fe5017
        item = pagure.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 e2259d
            hook_token='aaabbbttt',
Pierre-Yves Chibon d30465
        )
Pierre-Yves Chibon d30465
        self.session.add(item)
Pierre-Yves Chibon d30465
Pierre-Yves Chibon fe5017
        item = pagure.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 e2259d
            hook_token='aaabbbuuu',
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 fe5017
        projects = pagure.lib.search_projects(self.session, fork=True)
Pierre-Yves Chibon d30465
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon fe5017
        projects = pagure.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 fe5017
        """ Test the get_tags_of_project of pagure.lib. """
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon a2be4b
        self.test_add_issue_tag()
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon fe5017
        tags = pagure.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 fe5017
        tags = pagure.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 fe5017
        repo = pagure.lib.get_project(self.session, 'test2')
Pierre-Yves Chibon a2be4b
Pierre-Yves Chibon fe5017
        tags = pagure.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 fe5017
        """ Test the get_issue_statuses of pagure.lib. """
Pierre-Yves Chibon fe5017
        statuses = pagure.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 fe5017
        """ Test the set_up_user of pagure.lib. """
Pierre-Yves Chibon 6386c3
Pierre-Yves Chibon fe5017
        items = pagure.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 fe5017
        pagure.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 ec853d
            default_email='skvidal@fp.o'
Pierre-Yves Chibon 6386c3
        )
Pierre-Yves Chibon 6386c3
        self.session.commit()
Pierre-Yves Chibon 6386c3
Pierre-Yves Chibon fe5017
        items = pagure.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 fe5017
        pagure.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 ec853d
            default_email='skvidal@fp.o'
Pierre-Yves Chibon bd6684
        )
Pierre-Yves Chibon bd6684
        self.session.commit()
Pierre-Yves Chibon bd6684
        # Nothing changed
Pierre-Yves Chibon fe5017
        items = pagure.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 fe5017
        pagure.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 ec853d
            default_email='svidal@fp.o'
Pierre-Yves Chibon bd6684
        )
Pierre-Yves Chibon bd6684
        self.session.commit()
Pierre-Yves Chibon bd6684
        # Email added
Pierre-Yves Chibon fe5017
        items = pagure.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 fe5017
        """ Test the update_user_ssh of pagure.lib. """
Pierre-Yves Chibon c0cb4b
Pierre-Yves Chibon c0cb4b
        # Before
Pierre-Yves Chibon fe5017
        user = pagure.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 fe5017
        msg = pagure.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 fe5017
        msg = pagure.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 fe5017
        msg = pagure.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 fe5017
        """ Test the avatar_url of pagure.lib. """
Pierre-Yves Chibon fe5017
        output = pagure.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 fe5017
        """ Test the fork_project of pagure.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 86840f
        requestfolder = os.path.join(self.path, 'requests')
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 fe5017
        projects = pagure.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 fe5017
        msg = pagure.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 7b176d
            blacklist=[],
Pierre-Yves Chibon 4fe9b6
            gitfolder=gitfolder,
Pierre-Yves Chibon 4fe9b6
            docfolder=docfolder,
Pierre-Yves Chibon 4fe9b6
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 86840f
            requestfolder=requestfolder,
Pierre-Yves Chibon 4fe9b6
            description='description for testproject',
Pierre-Yves Chibon e2259d
            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 fe5017
        projects = pagure.lib.search_projects(self.session)
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon fe5017
        repo = pagure.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 86840f
        requestrepo = os.path.join(requestfolder, 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 86840f
        self.assertTrue(os.path.exists(requestrepo))
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 86840f
            requestfolder=requestfolder,
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 86840f
            requestfolder=requestfolder,
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 86840f
            requestfolder=requestfolder,
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 fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.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 86840f
            requestfolder=requestfolder,
Pierre-Yves Chibon 86840f
        )
Pierre-Yves Chibon 86840f
        self.session.rollback()
Pierre-Yves Chibon 86840f
        shutil.rmtree(grepo)
Pierre-Yves Chibon 86840f
Pierre-Yves Chibon 86840f
        # Request repo exists
Pierre-Yves Chibon 17eaea
        grepo = '%s.git' % os.path.join(requestfolder, 'foo', 'testproject')
Pierre-Yves Chibon 86840f
        os.makedirs(grepo)
Pierre-Yves Chibon 86840f
        self.assertRaises(
Pierre-Yves Chibon fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.lib.fork_project,
Pierre-Yves Chibon 86840f
            session=self.session,
Pierre-Yves Chibon 86840f
            user='foo',
Pierre-Yves Chibon 86840f
            repo=repo,
Pierre-Yves Chibon 86840f
            gitfolder=gitfolder,
Pierre-Yves Chibon 86840f
            forkfolder=forkfolder,
Pierre-Yves Chibon 86840f
            docfolder=docfolder,
Pierre-Yves Chibon 86840f
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 86840f
            requestfolder=requestfolder,
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 fe5017
        projects = pagure.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 fe5017
        msg = pagure.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 86840f
            requestfolder=requestfolder,
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 fe5017
        projects = pagure.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 fe5017
        repo = pagure.lib.get_project(
Pierre-Yves Chibon 4fe9b6
            self.session, 'testproject', user='foo')
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon fe5017
        msg = pagure.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 86840f
            requestfolder=requestfolder,
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 fe5017
        projects = pagure.lib.search_projects(self.session)
Pierre-Yves Chibon 4fe9b6
        self.assertEqual(len(projects), 3)
Pierre-Yves Chibon 4fe9b6
Pierre-Yves Chibon e6e56c
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon e6e56c
    def test_new_pull_request(self, mockemail):
Pierre-Yves Chibon fe5017
        """ test new_pull_request of pagure.lib. """
Pierre-Yves Chibon e6e56c
        mockemail.return_value = True
Pierre-Yves Chibon e6e56c
Pierre-Yves Chibon d62e1f
        tests.create_projects(self.session)
Pierre-Yves Chibon d62e1f
Pierre-Yves Chibon d62e1f
        # Create a forked repo
Pierre-Yves Chibon fe5017
        item = pagure.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 e2259d
            hook_token='aaabbbrrr',
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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon b3ed64
            session=self.session,
Pierre-Yves Chibon b3ed64
            project=repo,
Pierre-Yves Chibon a5a9ad
            new_user='foo',
Pierre-Yves Chibon a5a9ad
            user='pingou',
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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        forked_repo = pagure.lib.get_project(
Pierre-Yves Chibon d62e1f
            self.session, 'test', user='pingou')
Pierre-Yves Chibon d62e1f
Pierre-Yves Chibon fe5017
        msg = pagure.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 4726b7
            user='pingou',
Pierre-Yves Chibon 4726b7
            requestfolder=None,
Pierre-Yves Chibon d62e1f
        )
Pierre-Yves Chibon e2259d
        self.session.commit()
Pierre-Yves Chibon d62e1f
        self.assertEqual(msg, 'Request created')
Pierre-Yves Chibon d62e1f
Pierre-Yves Chibon e6e56c
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon e6e56c
    def test_add_pull_request_comment(self, mockemail):
Pierre-Yves Chibon fe5017
        """ Test add_pull_request_comment of pagure.lib. """
Pierre-Yves Chibon e6e56c
        mockemail.return_value = True
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon dc8159
        self.test_new_pull_request()
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon fe5017
        request = pagure.lib.search_pull_requests(self.session, requestid=1)
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon fe5017
        msg = pagure.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 4726b7
            user='foo',
Pierre-Yves Chibon 4726b7
            requestfolder=None,
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 fe5017
        """ Test search_pull_requests of pagure.lib. """
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon 566a8b
        self.test_new_pull_request()
Pierre-Yves Chibon 566a8b
Pierre-Yves Chibon fe5017
        prs = pagure.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 fe5017
        prs = pagure.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 fe5017
        prs = pagure.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 fe5017
        prs = pagure.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 fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon b9664f
    def test_close_pull_request(self, send_email):
Pierre-Yves Chibon fe5017
        """ Test close_pull_request of pagure.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 fe5017
        request = pagure.lib.search_pull_requests(self.session, requestid=1)
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon fe5017
        pagure.lib.close_pull_request(
Pierre-Yves Chibon 6dfdf2
            session=self.session,
Pierre-Yves Chibon 6dfdf2
            request=request,
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 4726b7
            requestfolder=None,
Pierre-Yves Chibon 4726b7
            merged=True,
Pierre-Yves Chibon 4726b7
        )
Pierre-Yves Chibon 6dfdf2
        self.session.commit()
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon fe5017
        prs = pagure.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 fe5017
        pagure.lib.close_pull_request(
Pierre-Yves Chibon 6dfdf2
            session=self.session,
Pierre-Yves Chibon 6dfdf2
            request=request,
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 4726b7
            requestfolder=None,
Pierre-Yves Chibon d3db5a
            merged=False,
Pierre-Yves Chibon 4726b7
        )
Pierre-Yves Chibon 6dfdf2
        self.session.commit()
Pierre-Yves Chibon 6dfdf2
Pierre-Yves Chibon fe5017
        prs = pagure.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 fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 9be8bd
    def test_remove_issue_dependency(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test remove_issue_dependency of pagure.lib. """
Pierre-Yves Chibon 9be8bd
        p_send_email.return_value = True
Pierre-Yves Chibon 9be8bd
        p_ugt.return_value = True
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon 9be8bd
        self.test_add_issue_dependency()
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon fe5017
        issue_blocked = pagure.lib.search_issues(
Pierre-Yves Chibon 9be8bd
            self.session, repo, issueid=2)
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon 9be8bd
        # Before
Pierre-Yves Chibon 9be8bd
        self.assertEqual(len(issue.parents), 1)
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue.parents[0].id, 2)
Pierre-Yves Chibon 9be8bd
        self.assertEqual(len(issue.children), 0)
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue.children, [])
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon 9be8bd
        self.assertEqual(len(issue_blocked.parents), 0)
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue_blocked.parents, [])
Pierre-Yves Chibon 9be8bd
        self.assertEqual(len(issue_blocked.children), 1)
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue_blocked.children[0].id, 1)
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon 9be8bd
        self.assertRaises(
Pierre-Yves Chibon fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.lib.remove_issue_dependency,
Pierre-Yves Chibon 9be8bd
            session=self.session,
Pierre-Yves Chibon 9be8bd
            issue=issue,
Pierre-Yves Chibon 9be8bd
            issue_blocked=issue,
Pierre-Yves Chibon 9be8bd
            user='pingou',
Pierre-Yves Chibon 9be8bd
            ticketfolder=None)
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon 9be8bd
        # Wrong order of issues
Pierre-Yves Chibon fe5017
        msg = pagure.lib.remove_issue_dependency(
Pierre-Yves Chibon 9be8bd
            session=self.session,
Pierre-Yves Chibon 9be8bd
            issue=issue,
Pierre-Yves Chibon 9be8bd
            issue_blocked=issue_blocked,
Pierre-Yves Chibon 9be8bd
            user='pingou',
Pierre-Yves Chibon 9be8bd
            ticketfolder=None)
Pierre-Yves Chibon 9be8bd
        self.session.commit()
Pierre-Yves Chibon 9be8bd
        self.assertEqual(msg, None)
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon 9be8bd
        # Drop deps
Pierre-Yves Chibon fe5017
        msg = pagure.lib.remove_issue_dependency(
Pierre-Yves Chibon 9be8bd
            session=self.session,
Pierre-Yves Chibon 9be8bd
            issue=issue_blocked,
Pierre-Yves Chibon 9be8bd
            issue_blocked=issue,
Pierre-Yves Chibon 9be8bd
            user='pingou',
Pierre-Yves Chibon 9be8bd
            ticketfolder=None)
Pierre-Yves Chibon 9be8bd
        self.session.commit()
Pierre-Yves Chibon 9be8bd
        self.assertEqual(msg, 'Dependency removed')
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon 9be8bd
        # After
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue.parents, [])
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue.children, [])
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue_blocked.parents, [])
Pierre-Yves Chibon 9be8bd
        self.assertEqual(issue_blocked.children, [])
Pierre-Yves Chibon 9be8bd
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon f553ea
    def test_get_issue_comment(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the get_issue_comment of pagure.lib. """
Pierre-Yves Chibon f553ea
        p_send_email.return_value = True
Pierre-Yves Chibon f553ea
        p_ugt.return_value = True
Pierre-Yves Chibon f553ea
Pierre-Yves Chibon f553ea
        self.test_add_issue_comment()
Pierre-Yves Chibon f553ea
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon f553ea
Pierre-Yves Chibon f553ea
        self.assertEqual(
Pierre-Yves Chibon fe5017
            pagure.lib.get_issue_comment(self.session, issue.uid, 10),
Pierre-Yves Chibon f553ea
            None
Pierre-Yves Chibon f553ea
        )
Pierre-Yves Chibon f553ea
Pierre-Yves Chibon fe5017
        comment = pagure.lib.get_issue_comment(self.session, issue.uid, 1)
Pierre-Yves Chibon f553ea
        self.assertEqual(comment.comment, 'Hey look a comment!')
Pierre-Yves Chibon f553ea
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 901a51
    def test_get_issue_by_uid(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the get_issue_by_uid of pagure.lib. """
Pierre-Yves Chibon 901a51
        p_send_email.return_value = True
Pierre-Yves Chibon 901a51
        p_ugt.return_value = True
Pierre-Yves Chibon 901a51
Pierre-Yves Chibon 901a51
        self.test_new_issue()
Pierre-Yves Chibon 901a51
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 901a51
Pierre-Yves Chibon 901a51
        self.assertEqual(
Pierre-Yves Chibon fe5017
            pagure.lib.get_issue_by_uid(self.session, 'foobar'),
Pierre-Yves Chibon 901a51
            None
Pierre-Yves Chibon 901a51
        )
Pierre-Yves Chibon 901a51
Pierre-Yves Chibon fe5017
        new_issue = pagure.lib.get_issue_by_uid(self.session, issue.uid)
Pierre-Yves Chibon 901a51
        self.assertEqual(issue, new_issue)
Pierre-Yves Chibon 901a51
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon f93600
    def test_update_tags_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the update_tags_issue of pagure.lib. """
Pierre-Yves Chibon f93600
        p_send_email.return_value = True
Pierre-Yves Chibon f93600
        p_ugt.return_value = True
Pierre-Yves Chibon f93600
Pierre-Yves Chibon f93600
        self.test_new_issue()
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon f93600
Pierre-Yves Chibon f93600
        # before
Pierre-Yves Chibon f93600
        self.assertEqual(issue.tags_text, [])
Pierre-Yves Chibon f93600
Pierre-Yves Chibon fe5017
        messages = pagure.lib.update_tags_issue(
Pierre-Yves Chibon f93600
            self.session, issue, 'tag', 'pingou', ticketfolder=None)
Pierre-Yves Chibon df35d8
        self.assertEqual(messages, ['Tag added: tag'])
Pierre-Yves Chibon fe5017
        messages = pagure.lib.update_tags_issue(
Pierre-Yves Chibon f93600
            self.session, issue, ['tag2', 'tag3'], 'pingou',
Pierre-Yves Chibon f93600
            ticketfolder=None)
Pierre-Yves Chibon f93600
        self.assertEqual(
Pierre-Yves Chibon df35d8
            messages, ['Tag added: tag2, tag3', 'Removed tag: tag'])
Pierre-Yves Chibon f93600
Pierre-Yves Chibon f93600
        # after
Pierre-Yves Chibon f93600
        self.assertEqual(issue.tags_text, ['tag2', 'tag3'])
Pierre-Yves Chibon bd6684
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 13128f
    def test_update_dependency_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the update_dependency_issue of pagure.lib. """
Pierre-Yves Chibon 13128f
        p_send_email.return_value = True
Pierre-Yves Chibon 13128f
        p_ugt.return_value = True
Pierre-Yves Chibon 13128f
Pierre-Yves Chibon 13128f
        self.test_new_issue()
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 13128f
Pierre-Yves Chibon 13128f
        # Create issues to play with
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 13128f
            session=self.session,
Pierre-Yves Chibon 13128f
            repo=repo,
Pierre-Yves Chibon 13128f
            title='Test issue #3',
Pierre-Yves Chibon 13128f
            content='We should work on this (3rd time!)',
Pierre-Yves Chibon 13128f
            user='pingou',
Pierre-Yves Chibon 13128f
            ticketfolder=None,
Pierre-Yves Chibon 13128f
            private=True,
Pierre-Yves Chibon 13128f
        )
Pierre-Yves Chibon 13128f
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue #3')
Pierre-Yves Chibon 13128f
Pierre-Yves Chibon 13128f
        # before
Pierre-Yves Chibon 13128f
        self.assertEqual(issue.tags_text, [])
Pierre-Yves Chibon 13128f
        self.assertEqual(issue.depends_text, [])
Pierre-Yves Chibon 13128f
        self.assertEqual(issue.blocks_text, [])
Pierre-Yves Chibon 13128f
Pierre-Yves Chibon fe5017
        messages = pagure.lib.update_dependency_issue(
Pierre-Yves Chibon 13128f
            self.session, repo, issue, '2', 'pingou', ticketfolder=None)
Pierre-Yves Chibon 13128f
        self.assertEqual(messages, ['Dependency added'])
Pierre-Yves Chibon fe5017
        messages = pagure.lib.update_dependency_issue(
Pierre-Yves Chibon 544331
            self.session, repo, issue, ['3', '4', 5], 'pingou',
Pierre-Yves Chibon 13128f
            ticketfolder=None)
Pierre-Yves Chibon 13128f
        self.assertEqual(
Pierre-Yves Chibon 13128f
            messages, ['Dependency added', 'Dependency removed'])
Pierre-Yves Chibon 13128f
Pierre-Yves Chibon 13128f
        # after
Pierre-Yves Chibon 13128f
        self.assertEqual(issue.tags_text, [])
Pierre-Yves Chibon 13128f
        self.assertEqual(issue.depends_text, [3])
Pierre-Yves Chibon 13128f
        self.assertEqual(issue.blocks_text, [])
Pierre-Yves Chibon 13128f
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 7476fa
    def test_update_blocked_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon fe5017
        """ Test the update_blocked_issue of pagure.lib. """
Pierre-Yves Chibon 7476fa
        p_send_email.return_value = True
Pierre-Yves Chibon 7476fa
        p_ugt.return_value = True
Pierre-Yves Chibon 7476fa
Pierre-Yves Chibon 7476fa
        self.test_new_issue()
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 7476fa
Pierre-Yves Chibon 7476fa
        # Create issues to play with
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 7476fa
            session=self.session,
Pierre-Yves Chibon 7476fa
            repo=repo,
Pierre-Yves Chibon 7476fa
            title='Test issue #3',
Pierre-Yves Chibon 7476fa
            content='We should work on this (3rd time!)',
Pierre-Yves Chibon 7476fa
            user='pingou',
Pierre-Yves Chibon 7476fa
            ticketfolder=None,
Pierre-Yves Chibon 7476fa
            private=True,
Pierre-Yves Chibon 7476fa
        )
Pierre-Yves Chibon 7476fa
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue #3')
Pierre-Yves Chibon 7476fa
Pierre-Yves Chibon 7476fa
        # before
Pierre-Yves Chibon 7476fa
        self.assertEqual(issue.tags_text, [])
Pierre-Yves Chibon 7476fa
        self.assertEqual(issue.depends_text, [])
Pierre-Yves Chibon 7476fa
        self.assertEqual(issue.blocks_text, [])
Pierre-Yves Chibon 7476fa
Pierre-Yves Chibon fe5017
        messages = pagure.lib.update_blocked_issue(
Pierre-Yves Chibon 7476fa
            self.session, repo, issue, '2', 'pingou', ticketfolder=None)
Pierre-Yves Chibon 7476fa
        self.assertEqual(messages, ['Dependency added'])
Pierre-Yves Chibon fe5017
        messages = pagure.lib.update_blocked_issue(
Pierre-Yves Chibon 7476fa
            self.session, repo, issue, ['3', '4', 5], 'pingou',
Pierre-Yves Chibon 7476fa
            ticketfolder=None)
Pierre-Yves Chibon 7476fa
        self.assertEqual(
Pierre-Yves Chibon 7476fa
            messages, ['Dependency added', 'Dependency removed'])
Pierre-Yves Chibon 7476fa
Pierre-Yves Chibon 7476fa
        # after
Pierre-Yves Chibon 7476fa
        self.assertEqual(issue.tags_text, [])
Pierre-Yves Chibon 7476fa
        self.assertEqual(issue.depends_text, [])
Pierre-Yves Chibon 7476fa
        self.assertEqual(issue.blocks_text, [3])
Pierre-Yves Chibon 7476fa
Pierre-Yves Chibon 13128f
Pierre-Yves Chibon d88010
if __name__ == '__main__':
Pierre-Yves Chibon fe5017
    SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibtests)
Pierre-Yves Chibon d88010
    unittest.TextTestRunner(verbosity=2).run(SUITE)