Blame tests/test_pagure_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 04800a
import pagure.lib.model
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 c1b058
        self.assertEqual(2, items[0].id)
Pierre-Yves Chibon c1b058
        self.assertEqual('foo', items[0].user)
Pierre-Yves Chibon c1b058
        self.assertEqual('foo', items[0].username)
Pierre-Yves Chibon c1b058
        self.assertEqual([], items[1].groups)
Pierre-Yves Chibon c1b058
        self.assertEqual(1, items[1].id)
Pierre-Yves Chibon c1b058
        self.assertEqual('pingou', items[1].user)
Pierre-Yves Chibon c1b058
        self.assertEqual('pingou', 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 3c5ebc
        self.assertEqual(repo.open_tickets, 0)
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets_public, 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 c30680
        # Try adding again this extra user to project `foo`
Pierre-Yves Chibon c30680
        self.assertRaises(
Pierre-Yves Chibon c30680
            pagure.exceptions.PagureException,
Pierre-Yves Chibon c30680
            pagure.lib.add_user_to_project,
Pierre-Yves Chibon c30680
            session=self.session,
Pierre-Yves Chibon c30680
            project=repo,
Pierre-Yves Chibon c30680
            new_user='foo',
Pierre-Yves Chibon c30680
            user='pingou'
Pierre-Yves Chibon c30680
        )
Pierre-Yves Chibon c30680
        self.session.commit()
Pierre-Yves Chibon c30680
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon c30680
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 3c5ebc
        self.assertEqual(repo.open_tickets, 1)
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets_public, 1)
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 3c5ebc
        self.assertEqual(repo.open_tickets, 2)
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets_public, 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 29d753
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 3c5ebc
        self.assertEqual(repo.open_tickets, 2)
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets_public, 2)
Pierre-Yves Chibon 29d753
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 29d753
            private=True,
Pierre-Yves Chibon 7a762d
        )
Pierre-Yves Chibon a5099b
        self.session.commit()
Pierre-Yves Chibon dbb6f8
        self.assertEqual(msg, 'Successfully edited issue #2')
Pierre-Yves Chibon a5099b
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets, 1)
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets_public, 1)
Pierre-Yves Chibon 29d753
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 668fbd
    def test_add_tag_obj(self, p_send_email, p_ugt):
Pierre-Yves Chibon 668fbd
        """ Test the add_tag_obj 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 668fbd
        msg = pagure.lib.add_tag_obj(
Pierre-Yves Chibon 8393f9
            session=self.session,
Pierre-Yves Chibon 668fbd
            obj=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 668fbd
        msg = pagure.lib.add_tag_obj(
Pierre-Yves Chibon b4f437
            session=self.session,
Pierre-Yves Chibon 668fbd
            obj=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 668fbd
        self.test_add_tag_obj()
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 668fbd
    def test_remove_tags_obj(self, p_send_email, p_ugt):
Pierre-Yves Chibon 668fbd
        """ Test the remove_tags_obj 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 668fbd
        self.test_add_tag_obj()
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 668fbd
        msgs = pagure.lib.remove_tags_obj(
Pierre-Yves Chibon 248fd9
            session=self.session,
Pierre-Yves Chibon 668fbd
            obj=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 668fbd
        self.test_add_tag_obj()
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 78b814
        # Add a new tag
Pierre-Yves Chibon 668fbd
        msg = pagure.lib.add_tag_obj(
Pierre-Yves Chibon 78b814
            session=self.session,
Pierre-Yves Chibon 668fbd
            obj=issue,
Pierre-Yves Chibon 78b814
            tags='tag3',
Pierre-Yves Chibon 78b814
            user='pingou',
Pierre-Yves Chibon 78b814
            ticketfolder=None)
Pierre-Yves Chibon 78b814
        self.session.commit()
Pierre-Yves Chibon 78b814
        self.assertEqual(msg, 'Tag added: tag3')
Pierre-Yves Chibon 78b814
        self.assertEqual([tag.tag for tag in issue.tags], ['tag2', 'tag3'])
Pierre-Yves Chibon 78b814
Pierre-Yves Chibon 78b814
        # Rename an existing tag into another existing one
Pierre-Yves Chibon 78b814
        msgs = pagure.lib.edit_issue_tags(
Pierre-Yves Chibon 78b814
            session=self.session,
Pierre-Yves Chibon 78b814
            project=repo,
Pierre-Yves Chibon 78b814
            old_tag='tag2',
Pierre-Yves Chibon 78b814
            new_tag='tag3',
Pierre-Yves Chibon 78b814
            user='pingou',
Pierre-Yves Chibon 78b814
            ticketfolder=None,
Pierre-Yves Chibon 78b814
        )
Pierre-Yves Chibon 78b814
        self.session.commit()
Pierre-Yves Chibon 78b814
        self.assertEqual(msgs, ['Edited tag: tag2 to tag3'])
Pierre-Yves Chibon 78b814
        self.assertEqual([tag.tag for tag in issue.tags], ['tag3'])
Pierre-Yves Chibon 78b814
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 719848
        # Try creating a blacklisted project
Pierre-Yves Chibon 719848
        self.assertRaises(
Pierre-Yves Chibon 719848
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 719848
            pagure.lib.new_project,
Pierre-Yves Chibon 719848
            session=self.session,
Pierre-Yves Chibon 719848
            user='pingou',
Pierre-Yves Chibon 719848
            name='static',
Pierre-Yves Chibon 719848
            blacklist=['static'],
Pierre-Yves Chibon 719848
            gitfolder=gitfolder,
Pierre-Yves Chibon 719848
            docfolder=docfolder,
Pierre-Yves Chibon 719848
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 719848
            requestfolder=requestfolder,
Pierre-Yves Chibon 719848
            description='description for static',
Pierre-Yves Chibon 719848
            parent_id=None,
Pierre-Yves Chibon 719848
        )
Pierre-Yves Chibon 719848
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 91b4cf
                'Enforce_signed-off_commits_in_pull-request': False,
Pierre-Yves Chibon d4b9db
                'always_merge': False,
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 9d4bff
                'Only_assignee_can_merge_pull-request': None,
Pierre-Yves Chibon 9d4bff
                'Minimum_score_to_merge_pull-request': None,
Pierre-Yves Chibon 9d4bff
                'Web-hooks': '',
Pierre-Yves Chibon 91b4cf
                'Enforce_signed-off_commits_in_pull-request': False,
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 668fbd
        self.test_add_tag_obj()
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 25d2bb
            sorted(statuses),
Pierre-Yves Chibon 25d2bb
            ['Fixed', 'Insufficient data', 'Invalid', 'Open'])
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 c1b058
        self.assertEqual(2, items[0].id)
Pierre-Yves Chibon c1b058
        self.assertEqual('foo', items[0].user)
Pierre-Yves Chibon c1b058
        self.assertEqual(1, items[1].id)
Pierre-Yves Chibon c1b058
        self.assertEqual('pingou', 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',
Patrick Uiterwijk 0e5f4a
            default_email='skvidal@fp.o',
Patrick Uiterwijk 0e5f4a
            keydir=pagure.APP.config.get('GITOLITE_KEYDIR', None),
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 c1b058
        self.assertEqual(2, items[0].id)
Pierre-Yves Chibon c1b058
        self.assertEqual('foo', items[0].user)
Pierre-Yves Chibon c1b058
        self.assertEqual(1, items[1].id)
Pierre-Yves Chibon c1b058
        self.assertEqual('pingou', 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',
Patrick Uiterwijk 0e5f4a
            default_email='skvidal@fp.o',
Patrick Uiterwijk 0e5f4a
            keydir=pagure.APP.config.get('GITOLITE_KEYDIR', None),
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',
Patrick Uiterwijk 0e5f4a
            default_email='svidal@fp.o',
Patrick Uiterwijk 0e5f4a
            keydir=pagure.APP.config.get('GITOLITE_KEYDIR', None),
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
Patrick Uiterwijk 0e5f4a
        msg = pagure.lib.update_user_ssh(self.session, user, 'blah', keydir=None)
Pierre-Yves Chibon 1b47d5
        user = pagure.lib.search_user(self.session, username='foo')
Pierre-Yves Chibon 1b47d5
        self.assertEqual(user.public_ssh_key, 'blah')
Pierre-Yves Chibon c0cb4b
Patrick Uiterwijk 0e5f4a
        msg = pagure.lib.update_user_ssh(self.session, user, 'blah', keydir=None)
Pierre-Yves Chibon 1b47d5
        user = pagure.lib.search_user(self.session, username='foo')
Pierre-Yves Chibon 1b47d5
        self.assertEqual(user.public_ssh_key, 'blah')
Pierre-Yves Chibon c0cb4b
Patrick Uiterwijk 0e5f4a
        msg = pagure.lib.update_user_ssh(self.session, 'foo', None, keydir=None)
Pierre-Yves Chibon 1b47d5
        user = pagure.lib.search_user(self.session, username='foo')
Pierre-Yves Chibon 1b47d5
        self.assertEqual(user.public_ssh_key, None)
Pierre-Yves Chibon c0cb4b
Pierre-Yves Chibon c3ac2f
    def test_avatar_url_from_openid(self):
Pierre-Yves Chibon c3ac2f
        """ Test the avatar_url_from_openid of pagure.lib. """
Pierre-Yves Chibon c3ac2f
        output = pagure.lib.avatar_url_from_openid('pingou@fedoraproject.org')
Pierre-Yves Chibon b6874d
        self.assertEqual(
Pierre-Yves Chibon b6874d
            output,
Pierre-Yves Chibon b6874d
            'https://seccdn.libravatar.org/avatar/'
Pierre-Yves Chibon c3ac2f
            'b3ee7bb4de70b6522c2478df3b4cd6322b5ec5d62ac7ceb1128e3d4ff42f6928'
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 3c5ebc
        self.assertEqual(repo.open_requests, 0)
Pierre-Yves Chibon 29d753
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 f9c5f9
        req = 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 f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_requests, 1)
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 c18b96
            tree_id=None,
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 521fcd
        self.session.commit()
Pierre-Yves Chibon dc8159
Pierre-Yves Chibon 60a84c
        self.assertEqual(len(request.discussion), 0)
Pierre-Yves Chibon 521fcd
        self.assertEqual(len(request.comments), 1)
Pierre-Yves Chibon 577b63
        self.assertEqual(request.score, 0)
Pierre-Yves Chibon 60a84c
Pierre-Yves Chibon c34916
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon c34916
    def test_add_pull_request_flag(self, mockemail):
Pierre-Yves Chibon c34916
        """ Test add_pull_request_flag of pagure.lib. """
Pierre-Yves Chibon c34916
        mockemail.return_value = True
Pierre-Yves Chibon c34916
Pierre-Yves Chibon c34916
        self.test_new_pull_request()
Pierre-Yves Chibon c34916
Pierre-Yves Chibon c34916
        request = pagure.lib.search_pull_requests(self.session, requestid=1)
Pierre-Yves Chibon c34916
        self.assertEqual(len(request.flags), 0)
Pierre-Yves Chibon c34916
Pierre-Yves Chibon c34916
        msg = pagure.lib.add_pull_request_flag(
Pierre-Yves Chibon c34916
            session=self.session,
Pierre-Yves Chibon c34916
            request=request,
Pierre-Yves Chibon c34916
            username="jenkins",
Pierre-Yves Chibon c34916
            percent=100,
Pierre-Yves Chibon c34916
            comment="Build passes",
Pierre-Yves Chibon c34916
            url="http://jenkins.cloud.fedoraproject.org",
Pierre-Yves Chibon c34916
            uid="jenkins_build_pagure_34",
Pierre-Yves Chibon c34916
            user='foo',
Pierre-Yves Chibon c34916
            requestfolder=None,
Pierre-Yves Chibon c34916
        )
Pierre-Yves Chibon c34916
        self.assertEqual(msg, 'Flag added')
Pierre-Yves Chibon c34916
        self.session.commit()
Pierre-Yves Chibon c34916
Pierre-Yves Chibon c34916
        self.assertEqual(len(request.flags), 1)
Pierre-Yves Chibon c34916
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 c5d9f4
        # All non-assigned PR
Pierre-Yves Chibon c5d9f4
        prs = pagure.lib.search_pull_requests(
Pierre-Yves Chibon c5d9f4
            session=self.session,
Pierre-Yves Chibon c5d9f4
            assignee=False
Pierre-Yves Chibon c5d9f4
        )
Pierre-Yves Chibon c5d9f4
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon c5d9f4
Pierre-Yves Chibon c5d9f4
        prs[0].assignee_id = 1
Pierre-Yves Chibon c5d9f4
        self.session.add(prs[0])
Pierre-Yves Chibon c5d9f4
        self.session.commit()
Pierre-Yves Chibon c5d9f4
Pierre-Yves Chibon c5d9f4
        # All the PR assigned
Pierre-Yves Chibon c5d9f4
        prs = pagure.lib.search_pull_requests(
Pierre-Yves Chibon c5d9f4
            session=self.session,
Pierre-Yves Chibon c5d9f4
            assignee=True
Pierre-Yves Chibon c5d9f4
        )
Pierre-Yves Chibon c5d9f4
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon c5d9f4
Pierre-Yves Chibon c5d9f4
        # Basically the same as above but then for a specific user
Pierre-Yves Chibon c5d9f4
        prs = pagure.lib.search_pull_requests(
Pierre-Yves Chibon c5d9f4
            session=self.session,
Pierre-Yves Chibon c5d9f4
            assignee='pingou'
Pierre-Yves Chibon c5d9f4
        )
Pierre-Yves Chibon c5d9f4
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon c5d9f4
Pierre-Yves Chibon c5d9f4
        # All PR except those assigned to pingou
Pierre-Yves Chibon c5d9f4
        prs = pagure.lib.search_pull_requests(
Pierre-Yves Chibon c5d9f4
            session=self.session,
Pierre-Yves Chibon c5d9f4
            assignee='!pingou'
Pierre-Yves Chibon c5d9f4
        )
Pierre-Yves Chibon c5d9f4
        self.assertEqual(len(prs), 0)
Pierre-Yves Chibon c5d9f4
Pierre-Yves Chibon c5d9f4
        # All PR created by the specified author
Pierre-Yves Chibon c5d9f4
        prs = pagure.lib.search_pull_requests(
Pierre-Yves Chibon c5d9f4
            session=self.session,
Pierre-Yves Chibon c5d9f4
            author='pingou'
Pierre-Yves Chibon c5d9f4
        )
Pierre-Yves Chibon c5d9f4
        self.assertEqual(len(prs), 1)
Pierre-Yves Chibon c5d9f4
Pierre-Yves Chibon c5d9f4
        # Count the PR instead of listing them
Pierre-Yves Chibon c5d9f4
        prs = pagure.lib.search_pull_requests(
Pierre-Yves Chibon c5d9f4
            session=self.session,
Pierre-Yves Chibon c5d9f4
            author='pingou',
Pierre-Yves Chibon c5d9f4
            count=True
Pierre-Yves Chibon c5d9f4
        )
Pierre-Yves Chibon c5d9f4
        self.assertEqual(prs, 1)
Pierre-Yves Chibon c5d9f4
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 29d753
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_requests, 1)
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 29d753
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_requests, 0)
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 cb4bd1
    def test_update_tags(self, p_send_email, p_ugt):
Pierre-Yves Chibon cb4bd1
        """ Test the update_tags 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 cb4bd1
        messages = pagure.lib.update_tags(
Pierre-Yves Chibon f93600
            self.session, issue, 'tag', 'pingou', ticketfolder=None)
Pierre-Yves Chibon df35d8
        self.assertEqual(messages, ['Tag added: tag'])
Pierre-Yves Chibon cb4bd1
        messages = pagure.lib.update_tags(
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 3c5ebc
        self.assertEqual(repo.open_tickets, 2)
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets_public, 2)
Pierre-Yves Chibon 29d753
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 3c5ebc
        self.assertEqual(repo.open_tickets, 3)
Pierre-Yves Chibon 3c5ebc
        self.assertEqual(repo.open_tickets_public, 2)
Pierre-Yves Chibon 29d753
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 356ddd
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 356ddd
    def test_add_pull_request_assignee(self, mockemail):
Pierre-Yves Chibon 356ddd
        """ Test add_pull_request_assignee of pagure.lib. """
Pierre-Yves Chibon 356ddd
        mockemail.return_value = True
Pierre-Yves Chibon 356ddd
Pierre-Yves Chibon 356ddd
        self.test_new_pull_request()
Pierre-Yves Chibon 356ddd
Pierre-Yves Chibon 356ddd
        request = pagure.lib.search_pull_requests(self.session, requestid=1)
Pierre-Yves Chibon 356ddd
Pierre-Yves Chibon 356ddd
        self.assertRaises(
Pierre-Yves Chibon 356ddd
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 356ddd
            pagure.lib.add_pull_request_assignee,
Pierre-Yves Chibon 356ddd
            session=self.session,
Pierre-Yves Chibon 356ddd
            request=request,
Pierre-Yves Chibon 356ddd
            assignee='bar',
Pierre-Yves Chibon 356ddd
            user='foo',
Pierre-Yves Chibon 356ddd
            requestfolder=None,
Pierre-Yves Chibon 356ddd
        )
Pierre-Yves Chibon 356ddd
Pierre-Yves Chibon 356ddd
        # Assign
Pierre-Yves Chibon 356ddd
        msg = pagure.lib.add_pull_request_assignee(
Pierre-Yves Chibon 356ddd
            session=self.session,
Pierre-Yves Chibon 356ddd
            request=request,
Pierre-Yves Chibon 356ddd
            assignee='pingou',
Pierre-Yves Chibon 356ddd
            user='foo',
Pierre-Yves Chibon 356ddd
            requestfolder=None,
Pierre-Yves Chibon 356ddd
        )
Pierre-Yves Chibon 356ddd
        self.assertEqual(msg, 'Request assigned')
Pierre-Yves Chibon 356ddd
Pierre-Yves Chibon 356ddd
        # Reset
Pierre-Yves Chibon 356ddd
        msg = pagure.lib.add_pull_request_assignee(
Pierre-Yves Chibon 356ddd
            session=self.session,
Pierre-Yves Chibon 356ddd
            request=request,
Pierre-Yves Chibon 356ddd
            assignee=None,
Pierre-Yves Chibon 356ddd
            user='foo',
Pierre-Yves Chibon 356ddd
            requestfolder=None,
Pierre-Yves Chibon 356ddd
        )
Pierre-Yves Chibon 356ddd
        self.assertEqual(msg, 'Request reset')
Pierre-Yves Chibon 356ddd
Pierre-Yves Chibon 356ddd
        # Try resetting again
Pierre-Yves Chibon 356ddd
        msg = pagure.lib.add_pull_request_assignee(
Pierre-Yves Chibon 356ddd
            session=self.session,
Pierre-Yves Chibon 356ddd
            request=request,
Pierre-Yves Chibon 356ddd
            assignee=None,
Pierre-Yves Chibon 356ddd
            user='foo',
Pierre-Yves Chibon 356ddd
            requestfolder=None,
Pierre-Yves Chibon 356ddd
        )
Pierre-Yves Chibon 356ddd
        self.assertEqual(msg, None)
Pierre-Yves Chibon 356ddd
Pierre-Yves Chibon 04800a
    def test_search_pending_email(self):
Pierre-Yves Chibon 04800a
        """ Test search_pending_email of pagure.lib. """
Pierre-Yves Chibon 04800a
Pierre-Yves Chibon 04800a
        self.assertEqual(
Pierre-Yves Chibon 04800a
            pagure.lib.search_pending_email(self.session), None)
Pierre-Yves Chibon 04800a
Pierre-Yves Chibon 04800a
        user = pagure.lib.search_user(self.session, username='pingou')
Pierre-Yves Chibon 04800a
Pierre-Yves Chibon 04800a
        email_pend = pagure.lib.model.UserEmailPending(
Pierre-Yves Chibon 04800a
            user_id=user.id,
Pierre-Yves Chibon 04800a
            email='foo@fp.o',
Pierre-Yves Chibon 04800a
            token='abcdef',
Pierre-Yves Chibon 04800a
        )
Pierre-Yves Chibon 04800a
        self.session.add(email_pend)
Pierre-Yves Chibon 04800a
        self.session.commit()
Pierre-Yves Chibon 04800a
Pierre-Yves Chibon 04800a
        self.assertNotEqual(
Pierre-Yves Chibon 04800a
            pagure.lib.search_pending_email(self.session), None)
Pierre-Yves Chibon 04800a
        self.assertNotEqual(
Pierre-Yves Chibon 04800a
            pagure.lib.search_pending_email(self.session, token='abcdef'),
Pierre-Yves Chibon 04800a
            None)
Pierre-Yves Chibon 04800a
Pierre-Yves Chibon 04800a
        pend = pagure.lib.search_pending_email(self.session, token='abcdef')
Pierre-Yves Chibon 04800a
        self.assertEqual(pend.user.username, 'pingou')
Pierre-Yves Chibon 04800a
        self.assertEqual(pend.email, 'foo@fp.o')
Pierre-Yves Chibon 04800a
        self.assertEqual(pend.token, 'abcdef')
Pierre-Yves Chibon 04800a
Pierre-Yves Chibon 04800a
        pend = pagure.lib.search_pending_email(self.session, email='foo@fp.o')
Pierre-Yves Chibon 04800a
        self.assertEqual(pend.user.username, 'pingou')
Pierre-Yves Chibon 04800a
        self.assertEqual(pend.email, 'foo@fp.o')
Pierre-Yves Chibon 04800a
        self.assertEqual(pend.token, 'abcdef')
Pierre-Yves Chibon 04800a
Pierre-Yves Chibon f2452d
    def test_generate_hook_token(self):
Pierre-Yves Chibon f2452d
        """ Test generate_hook_token of pagure.lib. """
Pierre-Yves Chibon f2452d
Pierre-Yves Chibon f2452d
        tests.create_projects(self.session)
Pierre-Yves Chibon f2452d
Pierre-Yves Chibon f2452d
        projects = pagure.lib.search_projects(self.session)
Pierre-Yves Chibon f2452d
        for proj in projects:
Pierre-Yves Chibon f2452d
            self.assertIn(proj.hook_token, ['aaabbbccc', 'aaabbbddd'])
Pierre-Yves Chibon f2452d
Pierre-Yves Chibon f2452d
        pagure.lib.generate_hook_token(self.session)
Pierre-Yves Chibon f2452d
Pierre-Yves Chibon f2452d
        projects = pagure.lib.search_projects(self.session)
Pierre-Yves Chibon f2452d
        for proj in projects:
Pierre-Yves Chibon f2452d
            self.assertNotIn(proj.hook_token, ['aaabbbccc', 'aaabbbddd'])
Pierre-Yves Chibon f2452d
Pierre-Yves Chibon 35482d
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 35482d
    def test_pull_request_score(self, mockemail):
Pierre-Yves Chibon 35482d
        """ Test PullRequest.score of pagure.lib.model. """
Pierre-Yves Chibon 35482d
        mockemail.return_value = True
Pierre-Yves Chibon 35482d
Pierre-Yves Chibon 35482d
        self.test_new_pull_request()
Pierre-Yves Chibon 35482d
Pierre-Yves Chibon 35482d
        request = pagure.lib.search_pull_requests(self.session, requestid=1)
Pierre-Yves Chibon 35482d
Pierre-Yves Chibon 35482d
        msg = pagure.lib.add_pull_request_comment(
Pierre-Yves Chibon 35482d
            session=self.session,
Pierre-Yves Chibon 35482d
            request=request,
Pierre-Yves Chibon 35482d
            commit=None,
Pierre-Yves Chibon c18b96
            tree_id=None,
Pierre-Yves Chibon 35482d
            filename=None,
Pierre-Yves Chibon 35482d
            row=None,
Pierre-Yves Chibon 35482d
            comment='This looks great :thumbsup:',
Pierre-Yves Chibon 35482d
            user='foo',
Pierre-Yves Chibon 35482d
            requestfolder=None,
Pierre-Yves Chibon 35482d
        )
Pierre-Yves Chibon 35482d
        self.session.commit()
Pierre-Yves Chibon 35482d
        self.assertEqual(msg, 'Comment added')
Pierre-Yves Chibon 35482d
Pierre-Yves Chibon 35482d
        msg = pagure.lib.add_pull_request_comment(
Pierre-Yves Chibon 35482d
            session=self.session,
Pierre-Yves Chibon 35482d
            request=request,
Pierre-Yves Chibon 35482d
            commit=None,
Pierre-Yves Chibon c18b96
            tree_id=None,
Pierre-Yves Chibon 35482d
            filename=None,
Pierre-Yves Chibon 35482d
            row=None,
Pierre-Yves Chibon 35482d
            comment='I disagree -1',
Pierre-Yves Chibon 35482d
            user='pingou',
Pierre-Yves Chibon 35482d
            requestfolder=None,
Pierre-Yves Chibon 35482d
        )
Pierre-Yves Chibon 35482d
        self.session.commit()
Pierre-Yves Chibon 35482d
        self.assertEqual(msg, 'Comment added')
Pierre-Yves Chibon 35482d
Pierre-Yves Chibon 35482d
        msg = pagure.lib.add_pull_request_comment(
Pierre-Yves Chibon 35482d
            session=self.session,
Pierre-Yves Chibon 35482d
            request=request,
Pierre-Yves Chibon 35482d
            commit=None,
Pierre-Yves Chibon c18b96
            tree_id=None,
Pierre-Yves Chibon 35482d
            filename=None,
Pierre-Yves Chibon 35482d
            row=None,
Pierre-Yves Chibon 35482d
            comment='NM this looks great now +1000',
Pierre-Yves Chibon 35482d
            user='pingou',
Pierre-Yves Chibon 35482d
            requestfolder=None,
Pierre-Yves Chibon 35482d
        )
Pierre-Yves Chibon 35482d
        self.session.commit()
Pierre-Yves Chibon 35482d
        self.assertEqual(msg, 'Comment added')
Pierre-Yves Chibon 35482d
Pierre-Yves Chibon 35482d
        self.assertEqual(len(request.discussion), 3)
Pierre-Yves Chibon 35482d
        self.assertEqual(request.score, 1)
Pierre-Yves Chibon 35482d
Pierre-Yves Chibon f95fbb
    def test_add_group(self):
Pierre-Yves Chibon f95fbb
        """ Test the add_group method of pagure.lib. """
Pierre-Yves Chibon f95fbb
        groups = pagure.lib.search_groups(self.session)
Pierre-Yves Chibon f95fbb
        self.assertEqual(len(groups), 0)
Pierre-Yves Chibon f95fbb
        self.assertEqual(groups, [])
Pierre-Yves Chibon f95fbb
Pierre-Yves Chibon f95fbb
        # Invalid type
Pierre-Yves Chibon f95fbb
        self.assertRaises(
Pierre-Yves Chibon f95fbb
            pagure.exceptions.PagureException,
Pierre-Yves Chibon f95fbb
            pagure.lib.add_group,
Pierre-Yves Chibon f95fbb
            self.session,
Pierre-Yves Chibon f95fbb
            group_name='foo',
Pierre-Yves Chibon f95fbb
            group_type='bar',
Pierre-Yves Chibon f95fbb
            user='pingou',
Pierre-Yves Chibon f95fbb
            is_admin=True,
Pierre-Yves Chibon f95fbb
        )
Pierre-Yves Chibon b5714b
        groups = pagure.lib.search_groups(self.session)
Pierre-Yves Chibon b5714b
        self.assertEqual(len(groups), 0)
Pierre-Yves Chibon b5714b
        self.assertEqual(groups, [])
Pierre-Yves Chibon f95fbb
Pierre-Yves Chibon f95fbb
        # Invalid user
Pierre-Yves Chibon f95fbb
        self.assertRaises(
Pierre-Yves Chibon f95fbb
            pagure.exceptions.PagureException,
Pierre-Yves Chibon f95fbb
            pagure.lib.add_group,
Pierre-Yves Chibon f95fbb
            self.session,
Pierre-Yves Chibon f95fbb
            group_name='foo',
Pierre-Yves Chibon f95fbb
            group_type='user',
Pierre-Yves Chibon f95fbb
            user='test',
Pierre-Yves Chibon f95fbb
            is_admin=False,
Pierre-Yves Chibon f95fbb
        )
Pierre-Yves Chibon b5714b
        groups = pagure.lib.search_groups(self.session)
Pierre-Yves Chibon b5714b
        self.assertEqual(len(groups), 0)
Pierre-Yves Chibon b5714b
        self.assertEqual(groups, [])
Pierre-Yves Chibon f95fbb
Pierre-Yves Chibon f95fbb
        msg = pagure.lib.add_group(
Pierre-Yves Chibon f95fbb
            self.session,
Pierre-Yves Chibon f95fbb
            group_name='foo',
Pierre-Yves Chibon f95fbb
            group_type='bar',
Pierre-Yves Chibon f95fbb
            user='pingou',
Pierre-Yves Chibon f95fbb
            is_admin=False,
Pierre-Yves Chibon f95fbb
        )
Pierre-Yves Chibon d1387c
        self.session.commit()
Pierre-Yves Chibon f95fbb
        self.assertEqual(msg, 'User `pingou` added to the group `foo`.')
Pierre-Yves Chibon f95fbb
Pierre-Yves Chibon f95fbb
        groups = pagure.lib.search_groups(self.session)
Pierre-Yves Chibon f95fbb
        self.assertEqual(len(groups), 1)
Pierre-Yves Chibon f95fbb
        self.assertEqual(groups[0].group_name, 'foo')
Pierre-Yves Chibon f95fbb
Pierre-Yves Chibon b5714b
        # Group with this name already exists
Pierre-Yves Chibon b5714b
        self.assertRaises(
Pierre-Yves Chibon b5714b
            pagure.exceptions.PagureException,
Pierre-Yves Chibon b5714b
            pagure.lib.add_group,
Pierre-Yves Chibon b5714b
            self.session,
Pierre-Yves Chibon b5714b
            group_name='foo',
Pierre-Yves Chibon b5714b
            group_type='bar',
Pierre-Yves Chibon b5714b
            user='pingou',
Pierre-Yves Chibon b5714b
            is_admin=False,
Pierre-Yves Chibon b5714b
        )
Pierre-Yves Chibon b5714b
Pierre-Yves Chibon 6633b6
    def test_add_user_to_group(self):
Pierre-Yves Chibon 6633b6
        """ Test the add_user_to_group method of pagure.lib. """
Pierre-Yves Chibon 6633b6
        self.test_add_group()
Pierre-Yves Chibon 6633b6
        group = pagure.lib.search_groups(self.session, group_name='foo')
Pierre-Yves Chibon 6633b6
        self.assertNotEqual(group, None)
Pierre-Yves Chibon 6633b6
        self.assertEqual(group.group_name, 'foo')
Pierre-Yves Chibon 6633b6
Pierre-Yves Chibon 6633b6
        # Invalid new user
Pierre-Yves Chibon 6633b6
        self.assertRaises(
Pierre-Yves Chibon 6633b6
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 6633b6
            pagure.lib.add_user_to_group,
Pierre-Yves Chibon 6633b6
            self.session,
Pierre-Yves Chibon 6633b6
            username='foobar',
Pierre-Yves Chibon 6633b6
            group=group,
Pierre-Yves Chibon 6633b6
            user='foo',
Pierre-Yves Chibon 6633b6
            is_admin=False,
Pierre-Yves Chibon 6633b6
        )
Pierre-Yves Chibon 6633b6
Pierre-Yves Chibon 6633b6
        # Invalid user
Pierre-Yves Chibon 6633b6
        self.assertRaises(
Pierre-Yves Chibon 6633b6
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 6633b6
            pagure.lib.add_user_to_group,
Pierre-Yves Chibon 6633b6
            self.session,
Pierre-Yves Chibon 6633b6
            username='foo',
Pierre-Yves Chibon 6633b6
            group=group,
Pierre-Yves Chibon 6633b6
            user='foobar',
Pierre-Yves Chibon 6633b6
            is_admin=False,
Pierre-Yves Chibon 6633b6
        )
Pierre-Yves Chibon 6633b6
Pierre-Yves Chibon 6633b6
        # User not allowed
Pierre-Yves Chibon 6633b6
        self.assertRaises(
Pierre-Yves Chibon 6633b6
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 6633b6
            pagure.lib.add_user_to_group,
Pierre-Yves Chibon 6633b6
            self.session,
Pierre-Yves Chibon 6633b6
            username='foo',
Pierre-Yves Chibon 6633b6
            group=group,
Pierre-Yves Chibon 6633b6
            user='foo',
Pierre-Yves Chibon 6633b6
            is_admin=False,
Pierre-Yves Chibon 6633b6
        )
Pierre-Yves Chibon 6633b6
Pierre-Yves Chibon 6633b6
        msg = pagure.lib.add_user_to_group(
Pierre-Yves Chibon 6633b6
            self.session,
Pierre-Yves Chibon 6633b6
            username='foo',
Pierre-Yves Chibon 6633b6
            group=group,
Pierre-Yves Chibon 6633b6
            user='pingou',
Pierre-Yves Chibon 6633b6
            is_admin=False,
Pierre-Yves Chibon 6633b6
        )
Pierre-Yves Chibon d1387c
        self.session.commit()
Pierre-Yves Chibon 6633b6
        self.assertEqual(msg, 'User `foo` added to the group `foo`.')
Pierre-Yves Chibon 6633b6
Pierre-Yves Chibon 47e762
        msg = pagure.lib.add_user_to_group(
Pierre-Yves Chibon 47e762
            self.session,
Pierre-Yves Chibon 47e762
            username='foo',
Pierre-Yves Chibon 47e762
            group=group,
Pierre-Yves Chibon 47e762
            user='pingou',
Pierre-Yves Chibon 47e762
            is_admin=False,
Pierre-Yves Chibon 47e762
        )
Pierre-Yves Chibon 47e762
        self.session.commit()
Pierre-Yves Chibon 47e762
        self.assertEqual(
Pierre-Yves Chibon 47e762
            msg, 'User `foo` already in the group, nothing to change.')
Pierre-Yves Chibon 47e762
Pierre-Yves Chibon 842d49
    def test_is_group_member(self):
Pierre-Yves Chibon 842d49
        """ Test the is_group_member method of pagure.lib. """
Pierre-Yves Chibon 842d49
        self.test_add_group()
Pierre-Yves Chibon 842d49
Pierre-Yves Chibon 842d49
        self.assertFalse(
Pierre-Yves Chibon 842d49
            pagure.lib.is_group_member(self.session, None, 'foo'))
Pierre-Yves Chibon 842d49
Pierre-Yves Chibon 842d49
        self.assertFalse(
Pierre-Yves Chibon 842d49
            pagure.lib.is_group_member(self.session, 'bar', 'foo'))
Pierre-Yves Chibon 842d49
Pierre-Yves Chibon 842d49
        self.assertFalse(
Pierre-Yves Chibon 842d49
            pagure.lib.is_group_member(self.session, 'foo', 'foo'))
Pierre-Yves Chibon 842d49
Pierre-Yves Chibon 842d49
        self.assertTrue(
Pierre-Yves Chibon 842d49
            pagure.lib.is_group_member(self.session, 'pingou', 'foo'))
Pierre-Yves Chibon 842d49
Pierre-Yves Chibon 9b9de8
    def test_get_user_group(self):
Pierre-Yves Chibon 9b9de8
        """ Test the get_user_group method of pagure.lib. """
Pierre-Yves Chibon 9b9de8
Pierre-Yves Chibon 9b9de8
        self.test_add_group()
Pierre-Yves Chibon 9b9de8
Pierre-Yves Chibon 9b9de8
        item = pagure.lib.get_user_group(self.session, 1, 1)
Pierre-Yves Chibon 9b9de8
        self.assertEqual(item.user_id, 1)
Pierre-Yves Chibon 9b9de8
        self.assertEqual(item.group_id, 1)
Pierre-Yves Chibon 9b9de8
Pierre-Yves Chibon 9b9de8
        item = pagure.lib.get_user_group(self.session, 1, 2)
Pierre-Yves Chibon 9b9de8
        self.assertEqual(item, None)
Pierre-Yves Chibon 9b9de8
Pierre-Yves Chibon 9b9de8
        item = pagure.lib.get_user_group(self.session, 2, 1)
Pierre-Yves Chibon 9b9de8
        self.assertEqual(item, None)
Pierre-Yves Chibon 9b9de8
Pierre-Yves Chibon 04c71a
    def test_get_group_types(self):
Pierre-Yves Chibon 04c71a
        """ Test the get_group_types method of pagure.lib. """
Pierre-Yves Chibon 04c71a
Pierre-Yves Chibon 04c71a
        self.test_add_group()
Pierre-Yves Chibon 04c71a
Pierre-Yves Chibon 04c71a
        groups = pagure.lib.get_group_types(self.session, 'user')
Pierre-Yves Chibon 04c71a
        self.assertEqual(len(groups), 1)
Pierre-Yves Chibon 04c71a
        self.assertEqual(groups[0].group_type, 'user')
Pierre-Yves Chibon 04c71a
Pierre-Yves Chibon 04c71a
        groups = pagure.lib.get_group_types(self.session)
Pierre-Yves Chibon 04c71a
        self.assertEqual(len(groups), 2)
Pierre-Yves Chibon 04c71a
        self.assertEqual(groups[0].group_type, 'admin')
Pierre-Yves Chibon 04c71a
        self.assertEqual(groups[1].group_type, 'user')
Pierre-Yves Chibon 04c71a
Pierre-Yves Chibon db1c81
    def test_search_groups(self):
Pierre-Yves Chibon db1c81
        """ Test the search_groups method of pagure.lib. """
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        self.assertEqual(pagure.lib.search_groups(self.session), [])
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        msg = pagure.lib.add_group(
Pierre-Yves Chibon db1c81
            self.session,
Pierre-Yves Chibon db1c81
            group_name='foo',
Pierre-Yves Chibon db1c81
            group_type='bar',
Pierre-Yves Chibon db1c81
            user='pingou',
Pierre-Yves Chibon db1c81
            is_admin=False,
Pierre-Yves Chibon db1c81
        )
Pierre-Yves Chibon db1c81
        self.session.commit()
Pierre-Yves Chibon db1c81
        self.assertEqual(msg, 'User `pingou` added to the group `foo`.')
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        groups = pagure.lib.search_groups(self.session)
Pierre-Yves Chibon db1c81
        self.assertEqual(len(groups), 1)
Pierre-Yves Chibon db1c81
        self.assertEqual(groups[0].group_name, 'foo')
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        msg = pagure.lib.add_group(
Pierre-Yves Chibon db1c81
            self.session,
Pierre-Yves Chibon db1c81
            group_name='bar',
Pierre-Yves Chibon db1c81
            group_type='admin',
Pierre-Yves Chibon db1c81
            user='pingou',
Pierre-Yves Chibon db1c81
            is_admin=True,
Pierre-Yves Chibon db1c81
        )
Pierre-Yves Chibon db1c81
        self.session.commit()
Pierre-Yves Chibon db1c81
        self.assertEqual(msg, 'User `pingou` added to the group `bar`.')
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        groups = pagure.lib.search_groups(self.session)
Pierre-Yves Chibon db1c81
        self.assertEqual(len(groups), 2)
Pierre-Yves Chibon db1c81
        self.assertEqual(groups[0].group_name, 'bar')
Pierre-Yves Chibon db1c81
        self.assertEqual(groups[1].group_name, 'foo')
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        groups = pagure.lib.search_groups(self.session, group_type='user')
Pierre-Yves Chibon db1c81
        self.assertEqual(len(groups), 1)
Pierre-Yves Chibon db1c81
        self.assertEqual(groups[0].group_name, 'foo')
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        groups = pagure.lib.search_groups(self.session, group_type='admin')
Pierre-Yves Chibon db1c81
        self.assertEqual(len(groups), 1)
Pierre-Yves Chibon db1c81
        self.assertEqual(groups[0].group_name, 'bar')
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon db1c81
        groups = pagure.lib.search_groups(self.session, group_name='foo')
Pierre-Yves Chibon db1c81
        self.assertEqual(groups.group_name, 'foo')
Pierre-Yves Chibon db1c81
Pierre-Yves Chibon 07e6f8
    def test_delete_user_of_group(self):
Pierre-Yves Chibon 07e6f8
        """ Test the delete_user_of_group method of pagure.lib. """
Pierre-Yves Chibon 07e6f8
        self.test_add_user_to_group()
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        groups = pagure.lib.search_groups(self.session)
Pierre-Yves Chibon 07e6f8
        self.assertEqual(len(groups), 1)
Pierre-Yves Chibon 07e6f8
        self.assertEqual(groups[0].group_name, 'foo')
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        # Invalid username
Pierre-Yves Chibon 07e6f8
        self.assertRaises(
Pierre-Yves Chibon 07e6f8
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 07e6f8
            pagure.lib.delete_user_of_group,
Pierre-Yves Chibon 07e6f8
            self.session,
Pierre-Yves Chibon 07e6f8
            username='bar',
Pierre-Yves Chibon 07e6f8
            groupname='foo',
Pierre-Yves Chibon 07e6f8
            user='pingou',
Pierre-Yves Chibon 07e6f8
            is_admin=False,
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        # Invalid groupname
Pierre-Yves Chibon 07e6f8
        self.assertRaises(
Pierre-Yves Chibon 07e6f8
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 07e6f8
            pagure.lib.delete_user_of_group,
Pierre-Yves Chibon 07e6f8
            self.session,
Pierre-Yves Chibon 07e6f8
            username='foo',
Pierre-Yves Chibon 07e6f8
            groupname='bar',
Pierre-Yves Chibon 07e6f8
            user='pingou',
Pierre-Yves Chibon 07e6f8
            is_admin=False,
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        # Invalid user
Pierre-Yves Chibon 07e6f8
        self.assertRaises(
Pierre-Yves Chibon 07e6f8
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 07e6f8
            pagure.lib.delete_user_of_group,
Pierre-Yves Chibon 07e6f8
            self.session,
Pierre-Yves Chibon 07e6f8
            username='foo',
Pierre-Yves Chibon 07e6f8
            groupname='foo',
Pierre-Yves Chibon 07e6f8
            user='test',
Pierre-Yves Chibon 07e6f8
            is_admin=False,
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        # User not in the group
Pierre-Yves Chibon 07e6f8
        item = pagure.lib.model.User(
Pierre-Yves Chibon 07e6f8
            user='bar',
Pierre-Yves Chibon 07e6f8
            fullname='bar',
Pierre-Yves Chibon 07e6f8
            password='foo',
Pierre-Yves Chibon 07e6f8
            default_email='bar@bar.com',
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
        self.session.add(item)
Pierre-Yves Chibon 07e6f8
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon 07e6f8
            user_id=3,
Pierre-Yves Chibon 07e6f8
            email='bar@bar.com')
Pierre-Yves Chibon 07e6f8
        self.session.add(item)
Pierre-Yves Chibon 07e6f8
        self.session.commit()
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        self.assertRaises(
Pierre-Yves Chibon 07e6f8
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 07e6f8
            pagure.lib.delete_user_of_group,
Pierre-Yves Chibon 07e6f8
            self.session,
Pierre-Yves Chibon 07e6f8
            username='bar',
Pierre-Yves Chibon 07e6f8
            groupname='foo',
Pierre-Yves Chibon 07e6f8
            user='pingou',
Pierre-Yves Chibon 07e6f8
            is_admin=False,
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        # User is not allowed to remove the username
Pierre-Yves Chibon 07e6f8
        self.assertRaises(
Pierre-Yves Chibon 07e6f8
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 07e6f8
            pagure.lib.delete_user_of_group,
Pierre-Yves Chibon 07e6f8
            self.session,
Pierre-Yves Chibon 07e6f8
            username='foo',
Pierre-Yves Chibon 07e6f8
            groupname='foo',
Pierre-Yves Chibon 07e6f8
            user='bar',
Pierre-Yves Chibon 07e6f8
            is_admin=False,
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        # Username is the creator of the group
Pierre-Yves Chibon 07e6f8
        self.assertRaises(
Pierre-Yves Chibon 07e6f8
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 07e6f8
            pagure.lib.delete_user_of_group,
Pierre-Yves Chibon 07e6f8
            self.session,
Pierre-Yves Chibon 07e6f8
            username='pingou',
Pierre-Yves Chibon 07e6f8
            groupname='foo',
Pierre-Yves Chibon 07e6f8
            user='pingou',
Pierre-Yves Chibon 07e6f8
            is_admin=False,
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        # All good
Pierre-Yves Chibon 07e6f8
        group = pagure.lib.search_groups(self.session, group_name='foo')
Pierre-Yves Chibon 07e6f8
        self.assertEqual(len(group.users), 2)
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        pagure.lib.delete_user_of_group(
Pierre-Yves Chibon 07e6f8
            self.session,
Pierre-Yves Chibon 07e6f8
            username='foo',
Pierre-Yves Chibon 07e6f8
            groupname='foo',
Pierre-Yves Chibon 07e6f8
            user='pingou',
Pierre-Yves Chibon 07e6f8
            is_admin=False,
Pierre-Yves Chibon 07e6f8
        )
Pierre-Yves Chibon 07e6f8
        self.session.commit()
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 07e6f8
        group = pagure.lib.search_groups(self.session, group_name='foo')
Pierre-Yves Chibon 07e6f8
        self.assertEqual(len(group.users), 1)
Pierre-Yves Chibon 07e6f8
Pierre-Yves Chibon 421eb9
    def test_add_group_to_project(self):
Pierre-Yves Chibon 421eb9
        """ Test the add_group_to_project method of pagure.lib. """
Pierre-Yves Chibon 421eb9
        tests.create_projects(self.session)
Pierre-Yves Chibon 421eb9
        self.test_add_group()
Pierre-Yves Chibon 421eb9
Pierre-Yves Chibon 421eb9
        project = pagure.lib.get_project(self.session, 'test2')
Pierre-Yves Chibon 421eb9
Pierre-Yves Chibon 421eb9
        # Group does not exist
Pierre-Yves Chibon 421eb9
        self.assertRaises(
Pierre-Yves Chibon 421eb9
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 421eb9
            pagure.lib.add_group_to_project,
Pierre-Yves Chibon 421eb9
            session=self.session,
Pierre-Yves Chibon 421eb9
            project=project,
Pierre-Yves Chibon 421eb9
            new_group='bar',
Pierre-Yves Chibon 421eb9
            user='foo',
Pierre-Yves Chibon 421eb9
        )
Pierre-Yves Chibon 421eb9
Pierre-Yves Chibon 421eb9
        # User does not exist
Pierre-Yves Chibon 421eb9
        self.assertRaises(
Pierre-Yves Chibon 421eb9
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 421eb9
            pagure.lib.add_group_to_project,
Pierre-Yves Chibon 421eb9
            session=self.session,
Pierre-Yves Chibon 421eb9
            project=project,
Pierre-Yves Chibon 421eb9
            new_group='foo',
Pierre-Yves Chibon 421eb9
            user='bar',
Pierre-Yves Chibon 421eb9
        )
Pierre-Yves Chibon 421eb9
Pierre-Yves Chibon 421eb9
        # User not allowed
Pierre-Yves Chibon 421eb9
        self.assertRaises(
Pierre-Yves Chibon 421eb9
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 421eb9
            pagure.lib.add_group_to_project,
Pierre-Yves Chibon 421eb9
            session=self.session,
Pierre-Yves Chibon 421eb9
            project=project,
Pierre-Yves Chibon 421eb9
            new_group='foo',
Pierre-Yves Chibon 421eb9
            user='foo',
Pierre-Yves Chibon 421eb9
        )
Pierre-Yves Chibon 421eb9
Pierre-Yves Chibon 421eb9
        # All good
Pierre-Yves Chibon 421eb9
        msg = pagure.lib.add_group_to_project(
Pierre-Yves Chibon 421eb9
            session=self.session,
Pierre-Yves Chibon 421eb9
            project=project,
Pierre-Yves Chibon 421eb9
            new_group='foo',
Pierre-Yves Chibon 421eb9
            user='pingou',
Pierre-Yves Chibon 421eb9
        )
Pierre-Yves Chibon 421eb9
        self.session.commit()
Pierre-Yves Chibon 421eb9
        self.assertEqual(msg, 'Group added')
Pierre-Yves Chibon 421eb9
Pierre-Yves Chibon 421eb9
        # Group already associated with the project
Pierre-Yves Chibon 421eb9
        self.assertRaises(
Pierre-Yves Chibon 421eb9
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 421eb9
            pagure.lib.add_group_to_project,
Pierre-Yves Chibon 421eb9
            session=self.session,
Pierre-Yves Chibon 421eb9
            project=project,
Pierre-Yves Chibon 421eb9
            new_group='foo',
Pierre-Yves Chibon 421eb9
            user='pingou',
Pierre-Yves Chibon 421eb9
        )
Pierre-Yves Chibon 421eb9
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)