Blame tests/test_pagure_lib_watch_list.py

Pierre-Yves Chibon fc049c
# -*- coding: utf-8 -*-
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
"""
Pierre-Yves Chibon fc049c
 (c) 2016 - Copyright Red Hat Inc
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
 Authors:
Pierre-Yves Chibon fc049c
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
"""
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon fc049c
import pkg_resources
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
import unittest
Pierre-Yves Chibon fc049c
import shutil
Pierre-Yves Chibon fc049c
import sys
Pierre-Yves Chibon fc049c
import os
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
import mock
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon fc049c
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
import pagure.lib
Pierre-Yves Chibon fc049c
import pagure.lib.model
Pierre-Yves Chibon fc049c
import tests
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
@mock.patch(
Pierre-Yves Chibon fc049c
        'pagure.lib.git.update_git', mock.MagicMock(return_value=True))
Pierre-Yves Chibon fc049c
@mock.patch(
Pierre-Yves Chibon fc049c
    'pagure.lib.notify.send_email', mock.MagicMock(return_value=True))
Pierre-Yves Chibon fc049c
class PagureLibGetWatchListtests(tests.Modeltests):
Pierre-Yves Chibon fc049c
    """ Tests for pagure.lib.get_watch_list """
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_invalid_object(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when given an invalid object """
Pierre-Yves Chibon fc049c
        # Create a project ns/test
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertRaises(
Pierre-Yves Chibon fc049c
            pagure.exceptions.InvalidObjectException,
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list,
Pierre-Yves Chibon fc049c
            self.session,
Pierre-Yves Chibon fc049c
            item
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_simple(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when the creator of the ticket is the
Pierre-Yves Chibon fc049c
        creator of the project """
Pierre-Yves Chibon fc049c
        # Create a project ns/test
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create the ticket
Pierre-Yves Chibon fc049c
        iss = pagure.lib.new_issue(
Pierre-Yves Chibon fc049c
            issue_id=4,
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            repo=item,
Pierre-Yves Chibon fc049c
            title='test issue',
Pierre-Yves Chibon fc049c
            content='content test issue',
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
            ticketfolder=None,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.id, 4)
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.title, 'test issue')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list(self.session, iss),
Pierre-Yves Chibon fc049c
            set(['pingou'])
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_different_creator(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when the creator of the ticket is not the
Pierre-Yves Chibon fc049c
        creator of the project """
Pierre-Yves Chibon fc049c
        # Create a project ns/test
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create the ticket
Pierre-Yves Chibon fc049c
        iss = pagure.lib.new_issue(
Pierre-Yves Chibon fc049c
            issue_id=4,
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            repo=item,
Pierre-Yves Chibon fc049c
            title='test issue',
Pierre-Yves Chibon fc049c
            content='content test issue',
Pierre-Yves Chibon fc049c
            user='foo',
Pierre-Yves Chibon fc049c
            ticketfolder=None,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.id, 4)
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.title, 'test issue')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list(self.session, iss),
Pierre-Yves Chibon fc049c
            set(['pingou', 'foo'])
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_project_w_contributor(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when the project has more than one
Pierre-Yves Chibon fc049c
        contributor """
Pierre-Yves Chibon fc049c
        # Create a project ns/test3
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Add a contributor to the project
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.User(
Pierre-Yves Chibon fc049c
            user='bar',
Pierre-Yves Chibon fc049c
            fullname='bar foo',
Pierre-Yves Chibon fc049c
            password='foo',
Pierre-Yves Chibon fc049c
            default_email='bar@bar.com',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon fc049c
            user_id=3,
Pierre-Yves Chibon fc049c
            email='bar@bar.com')
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        project = pagure.lib.get_project(
Pierre-Yves Chibon fc049c
            self.session, 'test3', namespace='ns')
Pierre-Yves Chibon fc049c
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            project=project,
Pierre-Yves Chibon fc049c
            new_user='bar',
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create the ticket
Pierre-Yves Chibon fc049c
        iss = pagure.lib.new_issue(
Pierre-Yves Chibon fc049c
            issue_id=4,
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            repo=project,
Pierre-Yves Chibon fc049c
            title='test issue',
Pierre-Yves Chibon fc049c
            content='content test issue',
Pierre-Yves Chibon fc049c
            user='foo',
Pierre-Yves Chibon fc049c
            ticketfolder=None,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.id, 4)
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.title, 'test issue')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list(self.session, iss),
Pierre-Yves Chibon fc049c
            set(['pingou', 'foo', 'bar'])
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_user_in_group(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when the project has groups of contributors
Pierre-Yves Chibon fc049c
        """
Pierre-Yves Chibon fc049c
        # Create a project ns/test3
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create a third user
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.User(
Pierre-Yves Chibon fc049c
            user='bar',
Pierre-Yves Chibon fc049c
            fullname='bar foo',
Pierre-Yves Chibon fc049c
            password='foo',
Pierre-Yves Chibon fc049c
            default_email='bar@bar.com',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon fc049c
            user_id=3,
Pierre-Yves Chibon fc049c
            email='bar@bar.com')
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create a group
Pierre-Yves Chibon fc049c
        msg = pagure.lib.add_group(
Pierre-Yves Chibon fc049c
            self.session,
Pierre-Yves Chibon fc049c
            group_name='foo',
Pierre-Yves Chibon fc049c
            display_name='foo group',
Pierre-Yves Chibon fc049c
            description=None,
Pierre-Yves Chibon fc049c
            group_type='bar',
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
            is_admin=False,
Pierre-Yves Chibon fc049c
            blacklist=[],
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'User `pingou` added to the group `foo`.')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Add user to group
Pierre-Yves Chibon fc049c
        group = pagure.lib.search_groups(self.session, group_name='foo')
Pierre-Yves Chibon fc049c
        msg = pagure.lib.add_user_to_group(
Pierre-Yves Chibon fc049c
            self.session,
Pierre-Yves Chibon fc049c
            username='bar',
Pierre-Yves Chibon fc049c
            group=group,
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
            is_admin=False,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'User `bar` added to the group `foo`.')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        project = pagure.lib.get_project(
Pierre-Yves Chibon fc049c
            self.session, 'test3', namespace='ns')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Add group to project
Pierre-Yves Chibon fc049c
        msg = pagure.lib.add_group_to_project(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            project=project,
Pierre-Yves Chibon fc049c
            new_group='foo',
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'Group added')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create the ticket
Pierre-Yves Chibon fc049c
        iss = pagure.lib.new_issue(
Pierre-Yves Chibon fc049c
            issue_id=4,
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            repo=project,
Pierre-Yves Chibon fc049c
            title='test issue',
Pierre-Yves Chibon fc049c
            content='content test issue',
Pierre-Yves Chibon fc049c
            user='foo',
Pierre-Yves Chibon fc049c
            ticketfolder=None,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.id, 4)
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.title, 'test issue')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list(self.session, iss),
Pierre-Yves Chibon fc049c
            set(['pingou', 'foo', 'bar'])
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_project_w_contributor_out(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when the project has one contributor not
Pierre-Yves Chibon fc049c
        watching the project """
Pierre-Yves Chibon fc049c
        # Create a project ns/test3
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Add a contributor to the project
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.User(
Pierre-Yves Chibon fc049c
            user='bar',
Pierre-Yves Chibon fc049c
            fullname='bar foo',
Pierre-Yves Chibon fc049c
            password='foo',
Pierre-Yves Chibon fc049c
            default_email='bar@bar.com',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon fc049c
            user_id=3,
Pierre-Yves Chibon fc049c
            email='bar@bar.com')
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        project = pagure.lib.get_project(
Pierre-Yves Chibon fc049c
            self.session, 'test3', namespace='ns')
Pierre-Yves Chibon fc049c
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            project=project,
Pierre-Yves Chibon fc049c
            new_user='bar',
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Set the user `pingou` to not watch the project
Pierre-Yves Chibon fc049c
        msg = pagure.lib.update_watch_status(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            project=project,
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
            watch=False,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'You are no longer watching this repo.')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create the ticket
Pierre-Yves Chibon fc049c
        iss = pagure.lib.new_issue(
Pierre-Yves Chibon fc049c
            issue_id=4,
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            repo=project,
Pierre-Yves Chibon fc049c
            title='test issue',
Pierre-Yves Chibon fc049c
            content='content test issue',
Pierre-Yves Chibon fc049c
            user='foo',
Pierre-Yves Chibon fc049c
            ticketfolder=None,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.id, 4)
Pierre-Yves Chibon fc049c
        self.assertEqual(iss.title, 'test issue')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list(self.session, iss),
Pierre-Yves Chibon fc049c
            set(['foo', 'bar'])
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_project_w_contributor_out_pr(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when the project has one contributor not
Pierre-Yves Chibon fc049c
        watching the pull-request """
Pierre-Yves Chibon fc049c
        # Create a project ns/test3
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Add a contributor to the project
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.User(
Pierre-Yves Chibon fc049c
            user='bar',
Pierre-Yves Chibon fc049c
            fullname='bar foo',
Pierre-Yves Chibon fc049c
            password='foo',
Pierre-Yves Chibon fc049c
            default_email='bar@bar.com',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon fc049c
            user_id=3,
Pierre-Yves Chibon fc049c
            email='bar@bar.com')
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        project = pagure.lib.get_project(
Pierre-Yves Chibon fc049c
            self.session, 'test3', namespace='ns')
Pierre-Yves Chibon fc049c
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            project=project,
Pierre-Yves Chibon fc049c
            new_user='bar',
Pierre-Yves Chibon fc049c
            user='pingou',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create the pull-request
Pierre-Yves Chibon fc049c
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            repo_from=project,
Pierre-Yves Chibon fc049c
            branch_from='dev',
Pierre-Yves Chibon fc049c
            repo_to=project,
Pierre-Yves Chibon fc049c
            branch_to='master',
Pierre-Yves Chibon fc049c
            title='test pull-request',
Pierre-Yves Chibon fc049c
            user='foo',
Pierre-Yves Chibon fc049c
            requestfolder=None,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon fc049c
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Set the user `pingou` to not watch the pull-request
Pierre-Yves Chibon fc049c
        out = pagure.lib.set_watch_obj(self.session, 'pingou', req, False)
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            out, 'You are no longer watching this pull-request')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list(self.session, req),
Pierre-Yves Chibon fc049c
            set(['foo', 'bar'])
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
    def test_get_watch_list_project_w_contributor_watching_project(self):
Pierre-Yves Chibon fc049c
        """ Test get_watch_list when the project has one contributor watching
Pierre-Yves Chibon fc049c
        the project """
Pierre-Yves Chibon fc049c
        # Create a project ns/test3
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.Project(
Pierre-Yves Chibon fc049c
            user_id=1,  # pingou
Pierre-Yves Chibon fc049c
            name='test3',
Pierre-Yves Chibon fc049c
            namespace='ns',
Pierre-Yves Chibon fc049c
            description='test project #1',
Pierre-Yves Chibon fc049c
            hook_token='aaabbbcccdd',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Add a new user
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.User(
Pierre-Yves Chibon fc049c
            user='bar',
Pierre-Yves Chibon fc049c
            fullname='bar foo',
Pierre-Yves Chibon fc049c
            password='foo',
Pierre-Yves Chibon fc049c
            default_email='bar@bar.com',
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon fc049c
            user_id=3,
Pierre-Yves Chibon fc049c
            email='bar@bar.com')
Pierre-Yves Chibon fc049c
        self.session.add(item)
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Set the user `bar` to watch the project
Pierre-Yves Chibon fc049c
        project = pagure.lib.get_project(
Pierre-Yves Chibon fc049c
            self.session, 'test3', namespace='ns')
Pierre-Yves Chibon fc049c
        msg = pagure.lib.update_watch_status(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            project=project,
Pierre-Yves Chibon fc049c
            user='bar',
Pierre-Yves Chibon fc049c
            watch=True,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(msg, 'You are now watching this repo.')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        # Create the pull-request
Pierre-Yves Chibon fc049c
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon fc049c
            session=self.session,
Pierre-Yves Chibon fc049c
            repo_from=project,
Pierre-Yves Chibon fc049c
            branch_from='dev',
Pierre-Yves Chibon fc049c
            repo_to=project,
Pierre-Yves Chibon fc049c
            branch_to='master',
Pierre-Yves Chibon fc049c
            title='test pull-request',
Pierre-Yves Chibon fc049c
            user='foo',
Pierre-Yves Chibon fc049c
            requestfolder=None,
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
        self.session.commit()
Pierre-Yves Chibon fc049c
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon fc049c
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
        self.assertEqual(
Pierre-Yves Chibon fc049c
            pagure.lib.get_watch_list(self.session, req),
Pierre-Yves Chibon fc049c
            set(['foo', 'bar', 'pingou'])
Pierre-Yves Chibon fc049c
        )
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
Pierre-Yves Chibon fc049c
if __name__ == '__main__':
Pierre-Yves Chibon fc049c
    unittest.main()