|
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 |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
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.model
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
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 |
930073 |
""" Tests for pagure.lib.query.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 |
930073 |
pagure.lib.query.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 |
930073 |
iss = pagure.lib.query.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 |
)
|
|
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 |
930073 |
pagure.lib.query.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 |
930073 |
iss = pagure.lib.query.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 |
)
|
|
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 |
930073 |
pagure.lib.query.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 |
930073 |
project = pagure.lib.query._get_project(
|
|
Pierre-Yves Chibon |
fc049c |
self.session, 'test3', namespace='ns')
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.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 |
930073 |
iss = pagure.lib.query.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 |
)
|
|
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 |
930073 |
pagure.lib.query.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 |
930073 |
msg = pagure.lib.query.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 |
930073 |
group = pagure.lib.query.search_groups(self.session, group_name='foo')
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.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 |
930073 |
project = pagure.lib.query._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 |
930073 |
msg = pagure.lib.query.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 |
930073 |
iss = pagure.lib.query.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 |
)
|
|
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 |
930073 |
pagure.lib.query.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 |
930073 |
project = pagure.lib.query._get_project(
|
|
Pierre-Yves Chibon |
fc049c |
self.session, 'test3', namespace='ns')
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.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 |
930073 |
msg = pagure.lib.query.update_watch_status(
|
|
Pierre-Yves Chibon |
fc049c |
session=self.session,
|
|
Pierre-Yves Chibon |
fc049c |
project=project,
|
|
Pierre-Yves Chibon |
fc049c |
user='pingou',
|
|
Matt Prahl |
b49f93 |
watch='0',
|
|
Pierre-Yves Chibon |
fc049c |
)
|
|
Pierre-Yves Chibon |
fc049c |
self.session.commit()
|
|
Matt Prahl |
b49f93 |
self.assertEqual(msg, 'You are no longer watching this project')
|
|
Pierre-Yves Chibon |
fc049c |
|
|
Pierre-Yves Chibon |
fc049c |
# Create the ticket
|
|
Pierre-Yves Chibon |
930073 |
iss = pagure.lib.query.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 |
)
|
|
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 |
930073 |
pagure.lib.query.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 |
930073 |
project = pagure.lib.query._get_project(
|
|
Pierre-Yves Chibon |
fc049c |
self.session, 'test3', namespace='ns')
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.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 |
930073 |
req = pagure.lib.query.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 |
)
|
|
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 |
930073 |
out = pagure.lib.query.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 |
930073 |
pagure.lib.query.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 |
930073 |
project = pagure.lib.query._get_project(
|
|
Pierre-Yves Chibon |
fc049c |
self.session, 'test3', namespace='ns')
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.update_watch_status(
|
|
Pierre-Yves Chibon |
fc049c |
session=self.session,
|
|
Pierre-Yves Chibon |
fc049c |
project=project,
|
|
Pierre-Yves Chibon |
fc049c |
user='bar',
|
|
Matt Prahl |
b49f93 |
watch='1',
|
|
Pierre-Yves Chibon |
fc049c |
)
|
|
Pierre-Yves Chibon |
fc049c |
self.session.commit()
|
|
Matt Prahl |
b49f93 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
d7ac66 |
msg, 'You are now watching issues and PRs on this project')
|
|
Pierre-Yves Chibon |
fc049c |
|
|
Pierre-Yves Chibon |
fc049c |
# Create the pull-request
|
|
Pierre-Yves Chibon |
930073 |
req = pagure.lib.query.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 |
)
|
|
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 |
930073 |
pagure.lib.query.get_watch_list(self.session, req),
|
|
Pierre-Yves Chibon |
fc049c |
set(['foo', 'bar', 'pingou'])
|
|
Pierre-Yves Chibon |
fc049c |
)
|
|
Pierre-Yves Chibon |
fc049c |
|
|
Karsten Hopp |
19b326 |
@mock.patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
|
|
Pierre-Yves Chibon |
53887d |
def test_get_watch_list_project_w_private_issue(self):
|
|
Pierre-Yves Chibon |
53887d |
""" Test get_watch_list when the project has one contributor watching
|
|
Pierre-Yves Chibon |
53887d |
the project and the issue is private """
|
|
Pierre-Yves Chibon |
53887d |
# Create a project ns/test3
|
|
Pierre-Yves Chibon |
53887d |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
53887d |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
53887d |
name='test3',
|
|
Pierre-Yves Chibon |
53887d |
namespace='ns',
|
|
Pierre-Yves Chibon |
53887d |
description='test project #1',
|
|
Pierre-Yves Chibon |
53887d |
hook_token='aaabbbcccdd',
|
|
Pierre-Yves Chibon |
53887d |
)
|
|
Pierre-Yves Chibon |
53887d |
item.close_status = ['Invalid', 'Insufficient data', 'Fixed']
|
|
Pierre-Yves Chibon |
53887d |
self.session.add(item)
|
|
Pierre-Yves Chibon |
53887d |
self.session.commit()
|
|
Pierre-Yves Chibon |
53887d |
|
|
Pierre-Yves Chibon |
53887d |
# Add a new user
|
|
Pierre-Yves Chibon |
53887d |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
53887d |
user='bar',
|
|
Pierre-Yves Chibon |
53887d |
fullname='bar foo',
|
|
Pierre-Yves Chibon |
53887d |
password='foo',
|
|
Pierre-Yves Chibon |
53887d |
default_email='bar@bar.com',
|
|
Pierre-Yves Chibon |
53887d |
)
|
|
Pierre-Yves Chibon |
53887d |
self.session.add(item)
|
|
Pierre-Yves Chibon |
53887d |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
53887d |
user_id=3,
|
|
Pierre-Yves Chibon |
53887d |
email='bar@bar.com')
|
|
Pierre-Yves Chibon |
53887d |
self.session.add(item)
|
|
Pierre-Yves Chibon |
53887d |
|
|
Pierre-Yves Chibon |
53887d |
# Set the user `bar` to watch the project
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
53887d |
self.session, 'test3', namespace='ns')
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.update_watch_status(
|
|
Pierre-Yves Chibon |
53887d |
session=self.session,
|
|
Pierre-Yves Chibon |
53887d |
project=project,
|
|
Pierre-Yves Chibon |
53887d |
user='bar',
|
|
Matt Prahl |
b49f93 |
watch='1',
|
|
Pierre-Yves Chibon |
53887d |
)
|
|
Pierre-Yves Chibon |
53887d |
self.session.commit()
|
|
Matt Prahl |
b49f93 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
d7ac66 |
msg, 'You are now watching issues and PRs on this project')
|
|
Pierre-Yves Chibon |
53887d |
|
|
Pierre-Yves Chibon |
53887d |
# Create the ticket
|
|
Pierre-Yves Chibon |
930073 |
iss = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
53887d |
issue_id=4,
|
|
Pierre-Yves Chibon |
53887d |
session=self.session,
|
|
Pierre-Yves Chibon |
53887d |
repo=project,
|
|
Pierre-Yves Chibon |
53887d |
title='test issue',
|
|
Pierre-Yves Chibon |
53887d |
content='content test issue',
|
|
Pierre-Yves Chibon |
53887d |
user='pingou',
|
|
Pierre-Yves Chibon |
53887d |
private=True,
|
|
Pierre-Yves Chibon |
53887d |
)
|
|
Pierre-Yves Chibon |
53887d |
self.session.commit()
|
|
Pierre-Yves Chibon |
53887d |
self.assertEqual(iss.id, 4)
|
|
Pierre-Yves Chibon |
53887d |
self.assertEqual(iss.title, 'test issue')
|
|
Pierre-Yves Chibon |
53887d |
|
|
Pierre-Yves Chibon |
53887d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.get_watch_list(self.session, iss),
|
|
Pierre-Yves Chibon |
53887d |
set(['pingou'])
|
|
Pierre-Yves Chibon |
53887d |
)
|
|
Pierre-Yves Chibon |
930073 |
out = pagure.lib.query.set_watch_obj(self.session, 'foo', iss, True)
|
|
Karsten Hopp |
19b326 |
self.assertEqual(out, 'You are now watching this issue')
|
|
Karsten Hopp |
19b326 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.get_watch_list(self.session, iss),
|
|
Karsten Hopp |
19b326 |
set(['pingou','foo'])
|
|
Karsten Hopp |
19b326 |
)
|
|
Pierre-Yves Chibon |
930073 |
out = pagure.lib.query.set_watch_obj(self.session, 'foo', iss, False)
|
|
Karsten Hopp |
19b326 |
self.assertEqual(
|
|
Karsten Hopp |
19b326 |
out, 'You are no longer watching this issue')
|
|
Karsten Hopp |
19b326 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.get_watch_list(self.session, iss),
|
|
Karsten Hopp |
19b326 |
set(['pingou'])
|
|
Karsten Hopp |
19b326 |
)
|
|
Pierre-Yves Chibon |
53887d |
|
|
Pierre-Yves Chibon |
fc049c |
|
|
Pierre-Yves Chibon |
fc049c |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|