|
Pierre-Yves Chibon |
0f5019 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
"""
|
|
Pierre-Yves Chibon |
0f5019 |
(c) 2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
Authors:
|
|
Pierre-Yves Chibon |
0f5019 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
"""
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
0f5019 |
import pkg_resources
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
import unittest
|
|
Pierre-Yves Chibon |
0f5019 |
import shutil
|
|
Pierre-Yves Chibon |
0f5019 |
import sys
|
|
Pierre-Yves Chibon |
0f5019 |
import os
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
import mock
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
0f5019 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
import pagure.lib
|
|
Pierre-Yves Chibon |
0f5019 |
import pagure.lib.model
|
|
Pierre-Yves Chibon |
0f5019 |
import tests
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
class PagureExcludeGroupIndex(tests.Modeltests):
|
|
Pierre-Yves Chibon |
0f5019 |
""" Tests the EXCLUDE_GROUP_INDEX configuration key in pagure """
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
def setUp(self):
|
|
Pierre-Yves Chibon |
0f5019 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
0f5019 |
super(PagureExcludeGroupIndex, self).setUp()
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
pagure.APP.config['GIT_FOLDER'] = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
0f5019 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
0f5019 |
tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# Create a ``provenpackger`` group:
|
|
Pierre-Yves Chibon |
0f5019 |
msg = pagure.lib.add_group(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
group_name='provenpackager',
|
|
Pierre-Yves Chibon |
0f5019 |
display_name='Proven Packagers',
|
|
Pierre-Yves Chibon |
0f5019 |
description='Packagers having access to all the repo',
|
|
Pierre-Yves Chibon |
0f5019 |
group_type='user',
|
|
Pierre-Yves Chibon |
0f5019 |
user='pingou',
|
|
Pierre-Yves Chibon |
0f5019 |
is_admin=False,
|
|
Pierre-Yves Chibon |
0f5019 |
blacklist=[],
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
self.session.commit()
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
0f5019 |
msg, 'User `pingou` added to the group `provenpackager`.')
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# Add the `provenpackager` group to the test2 project
|
|
Pierre-Yves Chibon |
0f5019 |
project = pagure.lib.get_project(self.session, 'test2')
|
|
Pierre-Yves Chibon |
0f5019 |
msg = pagure.lib.add_group_to_project(
|
|
Pierre-Yves Chibon |
0f5019 |
session=self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
project=project,
|
|
Pierre-Yves Chibon |
0f5019 |
new_group='provenpackager',
|
|
Pierre-Yves Chibon |
0f5019 |
user='pingou',
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
self.session.commit()
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(msg, 'Group added')
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
def test_defaults_pingou(self):
|
|
Pierre-Yves Chibon |
0f5019 |
""" Test which repo pingou has by default. """
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
repos = pagure.lib.search_projects(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='pingou',
|
|
Pierre-Yves Chibon |
0f5019 |
fork=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(len(repos), 3)
|
|
Pierre-Yves Chibon |
0f5019 |
for idx, name in enumerate(['test', 'test2', 'test3']):
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(repos[idx].name, name)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
def test_defaults_foo(self):
|
|
Pierre-Yves Chibon |
0f5019 |
""" Test which repo foo has by default. """
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
repos = pagure.lib.search_projects(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='foo',
|
|
Pierre-Yves Chibon |
0f5019 |
fork=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(len(repos), 0)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
def test_add_foo_test(self):
|
|
Pierre-Yves Chibon |
0f5019 |
""" Test adding foo to the test project. """
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
group = pagure.lib.search_groups(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session, group_name='provenpackager')
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(group.group_name, 'provenpackager')
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# List all foo's project before (ie: there should be none)
|
|
Pierre-Yves Chibon |
0f5019 |
repos = pagure.lib.search_projects(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='foo',
|
|
Pierre-Yves Chibon |
0f5019 |
fork=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(len(repos), 0)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# Adding `foo` to the `provenpackager` group
|
|
Pierre-Yves Chibon |
0f5019 |
msg = pagure.lib.add_user_to_group(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='foo',
|
|
Pierre-Yves Chibon |
0f5019 |
group=group,
|
|
Pierre-Yves Chibon |
0f5019 |
user='pingou',
|
|
Pierre-Yves Chibon |
0f5019 |
is_admin=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
0f5019 |
msg, 'User `foo` added to the group `provenpackager`.')
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# Test that foo has now one project, via the provenpackager group
|
|
Pierre-Yves Chibon |
0f5019 |
repos = pagure.lib.search_projects(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='foo',
|
|
Pierre-Yves Chibon |
0f5019 |
fork=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(len(repos), 1)
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(repos[0].name, 'test2')
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
def test_excluding_provenpackager(self):
|
|
Pierre-Yves Chibon |
0f5019 |
""" Test retrieving user's repo with a group excluded. """
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# Add `foo` to `provenpackager`
|
|
Pierre-Yves Chibon |
0f5019 |
group = pagure.lib.search_groups(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session, group_name='provenpackager')
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(group.group_name, 'provenpackager')
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
msg = pagure.lib.add_user_to_group(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='foo',
|
|
Pierre-Yves Chibon |
0f5019 |
group=group,
|
|
Pierre-Yves Chibon |
0f5019 |
user='pingou',
|
|
Pierre-Yves Chibon |
0f5019 |
is_admin=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
0f5019 |
msg, 'User `foo` added to the group `provenpackager`.')
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# Get foo's project outside of proven packager
|
|
Pierre-Yves Chibon |
0f5019 |
repos = pagure.lib.search_projects(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='foo',
|
|
Pierre-Yves Chibon |
0f5019 |
exclude_groups=['provenpackager'],
|
|
Pierre-Yves Chibon |
0f5019 |
fork=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(len(repos), 0)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
# Get pingou's project outside of proven packager (nothing changes)
|
|
Pierre-Yves Chibon |
0f5019 |
repos = pagure.lib.search_projects(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='pingou',
|
|
Pierre-Yves Chibon |
0f5019 |
exclude_groups=['provenpackager'],
|
|
Pierre-Yves Chibon |
0f5019 |
fork=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
repos2 = pagure.lib.search_projects(
|
|
Pierre-Yves Chibon |
0f5019 |
self.session,
|
|
Pierre-Yves Chibon |
0f5019 |
username='pingou',
|
|
Pierre-Yves Chibon |
0f5019 |
fork=False,
|
|
Pierre-Yves Chibon |
0f5019 |
)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(repos, repos2)
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(len(repos), 3)
|
|
Pierre-Yves Chibon |
0f5019 |
for idx, name in enumerate(['test', 'test2', 'test3']):
|
|
Pierre-Yves Chibon |
0f5019 |
self.assertEqual(repos[idx].name, name)
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
|
|
Pierre-Yves Chibon |
0f5019 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
0f5019 |
unittest.main(verbosity=2)
|