| |
@@ -29,889 +29,57 @@
|
| |
import tests
|
| |
|
| |
|
| |
- class PagureLibtests_search_user(tests.Modeltests):
|
| |
- """
|
| |
- Test the pagure.lib search_user() method
|
| |
- """
|
| |
-
|
| |
- def test_search_user_all(self):
|
| |
- """
|
| |
- Test the method returns all the users for the given session
|
| |
- """
|
| |
-
|
| |
- # Retrieve all users
|
| |
- items = pagure.lib.search_user(self.session)
|
| |
- self.assertEqual(2, len(items))
|
| |
- self.assertEqual(2, items[0].id)
|
| |
- self.assertEqual('foo', items[0].user)
|
| |
- self.assertEqual('foo', items[0].username)
|
| |
- self.assertEqual([], items[1].groups)
|
| |
- self.assertEqual(1, items[1].id)
|
| |
- self.assertEqual('pingou', items[1].user)
|
| |
- self.assertEqual('pingou', items[1].username)
|
| |
- self.assertEqual([], items[1].groups)
|
| |
-
|
| |
- def test_search_user_username(self):
|
| |
- """
|
| |
- Test the method returns the user for a given username
|
| |
- """
|
| |
-
|
| |
- # Retrieve user by username
|
| |
- item = pagure.lib.search_user(self.session, username='foo')
|
| |
- self.assertEqual('foo', item.user)
|
| |
- self.assertEqual('foo', item.username)
|
| |
- self.assertEqual([], item.groups)
|
| |
-
|
| |
- item = pagure.lib.search_user(self.session, username='bar')
|
| |
- self.assertEqual(None, item)
|
| |
-
|
| |
- def test_search_user_email(self):
|
| |
- """
|
| |
- Test the method returns a user for a given email address
|
| |
- """
|
| |
-
|
| |
- # Retrieve user by email
|
| |
- item = pagure.lib.search_user(self.session, email='foo@foo.com')
|
| |
- self.assertEqual(None, item)
|
| |
-
|
| |
- item = pagure.lib.search_user(self.session, email='foo@bar.com')
|
| |
- self.assertEqual('foo', item.user)
|
| |
- self.assertEqual('foo', item.username)
|
| |
- self.assertEqual([], item.groups)
|
| |
- self.assertEqual(
|
| |
- ['foo@bar.com'], [email.email for email in item.emails])
|
| |
-
|
| |
- item = pagure.lib.search_user(self.session, email='foo@pingou.com')
|
| |
- self.assertEqual('pingou', item.user)
|
| |
- self.assertEqual(
|
| |
- sorted(['bar@pingou.com', 'foo@pingou.com']),
|
| |
- sorted([email.email for email in item.emails]))
|
| |
-
|
| |
- def test_search_user_token(self):
|
| |
- """
|
| |
- Test the method returns a user for a given token
|
| |
- """
|
| |
-
|
| |
- # Retrieve user by token
|
| |
- item = pagure.lib.search_user(self.session, token='aaa')
|
| |
- self.assertEqual(None, item)
|
| |
-
|
| |
- item = pagure.lib.model.User(
|
| |
- user='pingou2',
|
| |
- fullname='PY C',
|
| |
- token='aaabbb',
|
| |
- default_email='bar@pingou.com',
|
| |
- )
|
| |
- self.session.add(item)
|
| |
- self.session.commit()
|
| |
-
|
| |
- item = pagure.lib.search_user(self.session, token='aaabbb')
|
| |
- self.assertEqual('pingou2', item.user)
|
| |
- self.assertEqual('PY C', item.fullname)
|
| |
-
|
| |
- def test_search_user_pattern(self):
|
| |
- """
|
| |
- Test the method returns a user for a given pattern
|
| |
- """
|
| |
-
|
| |
- # Retrieve user by pattern
|
| |
- item = pagure.lib.search_user(self.session, pattern='a*')
|
| |
- self.assertEqual([], item)
|
| |
-
|
| |
- item = pagure.lib.model.User(
|
| |
- user='pingou2',
|
| |
- fullname='PY C',
|
| |
- token='aaabbb',
|
| |
- default_email='bar@pingou.com',
|
| |
- )
|
| |
- self.session.add(item)
|
| |
- self.session.commit()
|
| |
-
|
| |
- items = pagure.lib.search_user(self.session, pattern='p*')
|
| |
- self.assertEqual(2, len(items))
|
| |
- self.assertEqual(1, items[0].id)
|
| |
- self.assertEqual('pingou', items[0].user)
|
| |
- self.assertEqual('pingou', items[0].username)
|
| |
- self.assertEqual([], items[0].groups)
|
| |
- self.assertEqual(
|
| |
- sorted(['bar@pingou.com', 'foo@pingou.com']),
|
| |
- sorted([email.email for email in items[0].emails]))
|
| |
- self.assertEqual(3, items[1].id)
|
| |
- self.assertEqual('pingou2', items[1].user)
|
| |
- self.assertEqual('pingou2', items[1].username)
|
| |
- self.assertEqual([], items[1].groups)
|
| |
- self.assertEqual(
|
| |
- [], [email.email for email in items[1].emails])
|
| |
-
|
| |
-
|
| |
- class PagureLibtests_search_projects(tests.Modeltests):
|
| |
- """
|
| |
- Test the pagure.lib search_projects() method
|
| |
- """
|
| |
-
|
| |
- def setUp(self):
|
| |
- super(PagureLibtests_search_projects, self).setUp()
|
| |
- tests.create_projects(self.session)
|
| |
-
|
| |
- def test_search_projects_all(self):
|
| |
- """
|
| |
- Test the method returns all the projects for the given session
|
| |
- """
|
| |
-
|
| |
- projects = pagure.lib.search_projects(self.session)
|
| |
- self.assertEqual(len(projects), 3)
|
| |
- self.assertEqual(projects[0].id, 1)
|
| |
- self.assertEqual(projects[1].id, 2)
|
| |
-
|
| |
- def test_search_projects_username(self):
|
| |
- """
|
| |
- Test the method returns all the projects for the given username
|
| |
- """
|
| |
- projects = pagure.lib.search_projects(self.session, username='foo')
|
| |
- self.assertEqual(len(projects), 0)
|
| |
-
|
| |
- projects = pagure.lib.search_projects(self.session, username='pingou')
|
| |
- self.assertEqual(len(projects), 3)
|
| |
- self.assertEqual(projects[0].id, 1)
|
| |
- self.assertEqual(projects[1].id, 2)
|
| |
-
|
| |
- def test_search_projects_start(self):
|
| |
- """
|
| |
- Test the method returns all the projects for the given start
|
| |
- """
|
| |
- projects = pagure.lib.search_projects(self.session, start=1)
|
| |
- self.assertEqual(len(projects), 2)
|
| |
- self.assertEqual(projects[0].id, 2)
|
| |
-
|
| |
- def test_search_projects_limit(self):
|
| |
- """
|
| |
- Test the method returns all the projects for the given limit
|
| |
- """
|
| |
- projects = pagure.lib.search_projects(self.session, limit=1)
|
| |
- self.assertEqual(len(projects), 1)
|
| |
- self.assertEqual(projects[0].id, 1)
|
| |
-
|
| |
- def test_search_projects_count(self):
|
| |
- """
|
| |
- Test the method returns the count of the projects
|
| |
- """
|
| |
- projects = pagure.lib.search_projects(self.session, count=True)
|
| |
- self.assertEqual(projects, 3)
|
| |
-
|
| |
- def test_search_projects_commit_access(self):
|
| |
- """
|
| |
- Test the method returns the project of user with only commit access
|
| |
- """
|
| |
- # Also check if the project shows up if a user doesn't
|
| |
- # have admin access in the project
|
| |
- # Check with commit access first
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou',
|
| |
- access='commit'
|
| |
- )
|
| |
-
|
| |
- self.assertEqual(msg, 'User added')
|
| |
- self.session.commit()
|
| |
- projects = pagure.lib.search_projects(self.session, username='foo')
|
| |
- self.assertEqual(len(projects), 1)
|
| |
-
|
| |
- def test_search_projects_ticket_access(self):
|
| |
- """
|
| |
- Test the method does not returns the project of user with only ticket access
|
| |
- """
|
| |
- # Now check with only ticket access
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou',
|
| |
- access='ticket'
|
| |
- )
|
| |
- self.assertEqual(msg, 'User added')
|
| |
- self.session.commit()
|
| |
- projects = pagure.lib.search_projects(self.session, username='foo')
|
| |
- self.assertEqual(len(projects), 0)
|
| |
-
|
| |
- def test_search_project_forked(self):
|
| |
- """
|
| |
- Test the search_project for forked projects in pagure.lib.
|
| |
- """
|
| |
-
|
| |
- # Create two forked repo
|
| |
- item = pagure.lib.model.Project(
|
| |
- user_id=2, # foo
|
| |
- name='test',
|
| |
- description='test project #1',
|
| |
- is_fork=True,
|
| |
- parent_id=1,
|
| |
- hook_token='aaabbbttt',
|
| |
- )
|
| |
- self.session.add(item)
|
| |
-
|
| |
- item = pagure.lib.model.Project(
|
| |
- user_id=2, # foo
|
| |
- name='test2',
|
| |
- description='test project #2',
|
| |
- is_fork=True,
|
| |
- parent_id=2,
|
| |
- hook_token='aaabbbuuu',
|
| |
- )
|
| |
- self.session.add(item)
|
| |
-
|
| |
- # Since we have two forks, let's search them
|
| |
- projects = pagure.lib.search_projects(self.session, fork=True)
|
| |
- self.assertEqual(len(projects), 2)
|
| |
- projects = pagure.lib.search_projects(self.session, fork=False)
|
| |
- self.assertEqual(len(projects), 3)
|
| |
-
|
| |
- def test_search_projects_private(self):
|
| |
- """
|
| |
- Test the method for private projects
|
| |
- """
|
| |
-
|
| |
- item = pagure.lib.model.Project(
|
| |
- user_id=1, # pingou
|
| |
- name='private_test',
|
| |
- description='Private test project #1',
|
| |
- hook_token='aaabbbcccpp',
|
| |
- )
|
| |
- self.session.add(item)
|
| |
- self.session.commit()
|
| |
-
|
| |
- projects = pagure.lib.search_projects(self.session)
|
| |
- self.assertEqual(len(projects), 4)
|
| |
- self.assertEqual(
|
| |
- [p.path for p in projects],
|
| |
- ['private_test.git', 'test.git', 'test2.git',
|
| |
- 'somenamespace/test3.git']
|
| |
- )
|
| |
-
|
| |
- projects = pagure.lib.search_projects(
|
| |
- self.session, username='pingou')
|
| |
- self.assertEqual(len(projects), 4)
|
| |
- self.assertEqual(
|
| |
- [p.path for p in projects],
|
| |
- ['private_test.git', 'test.git', 'test2.git',
|
| |
- 'somenamespace/test3.git']
|
| |
- )
|
| |
-
|
| |
- projects = pagure.lib.search_projects(
|
| |
- self.session, username='pingou', private='pingou')
|
| |
- self.assertEqual(len(projects), 4)
|
| |
- self.assertEqual(
|
| |
- [p.path for p in projects],
|
| |
- ['private_test.git', 'test.git', 'test2.git',
|
| |
- 'somenamespace/test3.git']
|
| |
- )
|
| |
-
|
| |
- projects = pagure.lib.search_projects(
|
| |
- self.session, username='pingou', private='foo')
|
| |
- self.assertEqual(len(projects), 0)
|
| |
-
|
| |
- def test_search_projects_tags(self):
|
| |
- """
|
| |
- Test the method returns all the projects for the given tags
|
| |
- """
|
| |
-
|
| |
- # Add tags to the project
|
| |
- project = pagure.lib._get_project(self.session, 'test')
|
| |
- tag = pagure.lib.model.Tag(
|
| |
- tag='fedora'
|
| |
- )
|
| |
- self.session.add(tag)
|
| |
- self.session.commit()
|
| |
- tp = pagure.lib.model.TagProject(
|
| |
- project_id=project.id,
|
| |
- tag='fedora'
|
| |
- )
|
| |
- self.session.add(tp)
|
| |
- self.session.commit()
|
| |
-
|
| |
- projects = pagure.lib.search_projects(
|
| |
- self.session, tags='fedora')
|
| |
- self.assertEqual(len(projects), 1)
|
| |
- self.assertEqual(projects[0].path, 'test.git')
|
| |
-
|
| |
- def test_search_projects_pattern(self):
|
| |
- """
|
| |
- Test the method returns all the projects for the given pattern
|
| |
- """
|
| |
-
|
| |
- projects = pagure.lib.search_projects(
|
| |
- self.session, pattern='test*')
|
| |
- self.assertEqual(len(projects), 3)
|
| |
- self.assertEqual(
|
| |
- [p.path for p in projects],
|
| |
- ['test.git', 'test2.git', 'somenamespace/test3.git']
|
| |
- )
|
| |
-
|
| |
- def test_search_projects_sort(self):
|
| |
- """
|
| |
- Test the method returns all the projects sorted by lastest and oldest
|
| |
- """
|
| |
-
|
| |
- projects = pagure.lib.search_projects(
|
| |
- self.session, pattern='*', sort='latest')
|
| |
- self.assertEqual(len(projects), 3)
|
| |
- self.assertEqual(
|
| |
- [p.path for p in projects],
|
| |
- ['somenamespace/test3.git', 'test2.git', 'test.git']
|
| |
- )
|
| |
-
|
| |
- projects = pagure.lib.search_projects(
|
| |
- self.session, pattern='*', sort='oldest')
|
| |
- self.assertEqual(len(projects), 3)
|
| |
- self.assertEqual(
|
| |
- [p.path for p in projects],
|
| |
- ['test.git', 'test2.git', 'somenamespace/test3.git']
|
| |
- )
|
| |
-
|
| |
-
|
| |
- class PagureLibtests(tests.Modeltests):
|
| |
- """ Tests for pagure.lib """
|
| |
-
|
| |
- def test_get_next_id(self):
|
| |
- """ Test the get_next_id function of pagure.lib. """
|
| |
- tests.create_projects(self.session)
|
| |
- self.assertEqual(1, pagure.lib.get_next_id(self.session, 1))
|
| |
-
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_new_issue(self, p_send_email, p_ugt):
|
| |
- """ Test the new_issue of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- tests.create_projects(self.session)
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- # Set some priorities to the project
|
| |
- repo.priorities = {'1': 'High', '2': 'Normal'}
|
| |
- self.session.add(repo)
|
| |
- self.session.commit()
|
| |
-
|
| |
- # Before
|
| |
- issues = pagure.lib.search_issues(self.session, repo)
|
| |
- self.assertEqual(len(issues), 0)
|
| |
- self.assertEqual(repo.open_tickets, 0)
|
| |
- self.assertEqual(repo.open_tickets_public, 0)
|
| |
-
|
| |
- # See where it fails
|
| |
- self.assertRaises(
|
| |
- pagure.exceptions.PagureException,
|
| |
- pagure.lib.new_issue,
|
| |
- session=self.session,
|
| |
- repo=repo,
|
| |
- title='Test issue',
|
| |
- content='We should work on this',
|
| |
- user='blah',
|
| |
- ticketfolder=None
|
| |
- )
|
| |
-
|
| |
- # Fails since we're trying to give a non-existant priority
|
| |
- self.assertRaises(
|
| |
- pagure.exceptions.PagureException,
|
| |
- pagure.lib.new_issue,
|
| |
- session=self.session,
|
| |
- repo=repo,
|
| |
- title='Test issue',
|
| |
- content='We should work on this',
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- priority=0,
|
| |
- )
|
| |
-
|
| |
- # Add an extra user to project `foo`
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- session=self.session,
|
| |
- project=repo,
|
| |
- new_user='foo',
|
| |
- user='pingou'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'User added')
|
| |
-
|
| |
- # Try adding again this extra user to project `foo`
|
| |
- self.assertRaises(
|
| |
- pagure.exceptions.PagureException,
|
| |
- pagure.lib.add_user_to_project,
|
| |
- session=self.session,
|
| |
- project=repo,
|
| |
- new_user='foo',
|
| |
- user='pingou'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'User added')
|
| |
-
|
| |
- # Create issues to play with
|
| |
- msg = pagure.lib.new_issue(
|
| |
- session=self.session,
|
| |
- repo=repo,
|
| |
- title='Test issue',
|
| |
- content='We should work on this',
|
| |
- user='pingou',
|
| |
- ticketfolder=None
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue')
|
| |
- self.assertEqual(repo.open_tickets, 1)
|
| |
- self.assertEqual(repo.open_tickets_public, 1)
|
| |
-
|
| |
- msg = pagure.lib.new_issue(
|
| |
- session=self.session,
|
| |
- repo=repo,
|
| |
- title='Test issue #2',
|
| |
- content='We should work on this for the second time',
|
| |
- user='foo',
|
| |
- status='Open',
|
| |
- ticketfolder=None
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue #2')
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
- # After
|
| |
- issues = pagure.lib.search_issues(self.session, repo)
|
| |
- self.assertEqual(len(issues), 2)
|
| |
-
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_edit_issue(self, p_send_email, p_ugt):
|
| |
- """ Test the edit_issue of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- self.test_new_issue()
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
-
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
- # Edit the issue
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, None)
|
| |
-
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- title='Test issue #2',
|
| |
- content='We should work on this for the second time',
|
| |
- status='Open',
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, None)
|
| |
-
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- title='Foo issue #2',
|
| |
- content='We should work on this period',
|
| |
- status='Closed',
|
| |
- close_status='Invalid',
|
| |
- private=True,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg,
|
| |
- [
|
| |
- 'Issue status updated to: Closed (was: Open)',
|
| |
- 'Issue close_status updated to: Invalid',
|
| |
- 'Issue private status set to: True'
|
| |
- ]
|
| |
- )
|
| |
-
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- title='Foo issue #2',
|
| |
- content='Fixed!',
|
| |
- status='Closed',
|
| |
- close_status='Fixed',
|
| |
- private=False,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg,
|
| |
- [
|
| |
- 'Issue close_status updated to: Fixed (was: Invalid)',
|
| |
- 'Issue private status set to: False (was: True)'
|
| |
- ]
|
| |
- )
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(repo.open_tickets, 1)
|
| |
- self.assertEqual(repo.open_tickets_public, 1)
|
| |
- self.assertEqual(repo.issues[1].status, 'Closed')
|
| |
- self.assertEqual(repo.issues[1].close_status, 'Fixed')
|
| |
-
|
| |
- # Edit the status: re-open the ticket
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- status='Open',
|
| |
- ticketfolder=None,
|
| |
- private=True,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg,
|
| |
- [
|
| |
- 'Issue status updated to: Open (was: Closed)',
|
| |
- 'Issue private status set to: True'
|
| |
- ]
|
| |
- )
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- for issue in repo.issues:
|
| |
- self.assertEqual(issue.status, 'Open')
|
| |
- self.assertEqual(issue.close_status, None)
|
| |
- # 2 open but one of them is private
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 1)
|
| |
-
|
| |
- # Edit the status: re-close the ticket
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- status='Closed',
|
| |
- close_status='Invalid',
|
| |
- ticketfolder=None,
|
| |
- private=True,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg,
|
| |
- [
|
| |
- 'Issue status updated to: Closed (was: Open)',
|
| |
- 'Issue close_status updated to: Invalid'
|
| |
- ]
|
| |
- )
|
| |
+ class PagureLibtests(tests.Modeltests):
|
| |
+ """ Tests for pagure.lib """
|
| |
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(repo.open_tickets, 1)
|
| |
- self.assertEqual(repo.open_tickets_public, 1)
|
| |
- self.assertEqual(repo.issues[1].status, 'Closed')
|
| |
- self.assertEqual(repo.issues[1].close_status, 'Invalid')
|
| |
+ def test_get_next_id(self):
|
| |
+ """ Test the get_next_id function of pagure.lib. """
|
| |
+ tests.create_projects(self.session)
|
| |
+ self.assertEqual(1, pagure.lib.get_next_id(self.session, 1))
|
| |
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_edit_issue_close_status(self, p_send_email, p_ugt):
|
| |
+ @patch('pagure.lib.REDIS')
|
| |
+ @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
|
| |
+ @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
| |
+ def test_edit_comment(self, mock_redis):
|
| |
""" Test the edit_issue of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- self.test_new_issue()
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
- self.assertEqual(issue.status, 'Open')
|
| |
- self.assertEqual(issue.close_status, None)
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
- # Edit the issue, providing just a close_status should also close
|
| |
- # the ticket
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- close_status='Fixed',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, ['Issue close_status updated to: Fixed'])
|
| |
-
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
- self.assertEqual(issue.status, 'Closed')
|
| |
- self.assertEqual(issue.close_status, 'Fixed')
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(repo.open_tickets, 1)
|
| |
- self.assertEqual(repo.open_tickets_public, 1)
|
| |
-
|
| |
- # Edit the issue, editing the status to open, should reset the
|
| |
- # close_status
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- status='Open',
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg, ['Issue status updated to: Open (was: Closed)'])
|
| |
+ mock_redis.return_value = True
|
| |
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
- self.assertEqual(issue.status, 'Open')
|
| |
- self.assertEqual(issue.close_status, None)
|
| |
+ tests.create_projects(self.session)
|
| |
|
| |
repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_edit_issue_priority(self, p_send_email, p_ugt):
|
| |
- """ Test the edit_issue of pagure.lib when changing the priority.
|
| |
- """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- self.test_new_issue()
|
| |
-
|
| |
- repo = pagure.get_authorized_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
-
|
| |
- # Set some priorities to the repo
|
| |
- repo = pagure.get_authorized_project(self.session, 'test')
|
| |
- repo.priorities = {'1': 'High', '2': 'Normal'}
|
| |
- self.session.add(repo)
|
| |
- self.session.commit()
|
| |
-
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
- # Edit the issue -- Wrong priority value: No changes
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- priority=3,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, None)
|
| |
-
|
| |
- # Edit the issue -- Good priority
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- priority=2,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg,
|
| |
- [
|
| |
- 'Issue priority set to: Normal'
|
| |
- ]
|
| |
- )
|
| |
-
|
| |
- # Edit the issue -- Update priority
|
| |
- msg = pagure.lib.edit_issue(
|
| |
+ pagure.lib.add_user_to_project(
|
| |
session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- priority=1,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg,
|
| |
- [
|
| |
- 'Issue priority set to: High (was: Normal)'
|
| |
- ]
|
| |
+ project=repo,
|
| |
+ new_user='foo',
|
| |
+ user='pingou'
|
| |
)
|
| |
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_edit_issue_depending(self, p_send_email, p_ugt):
|
| |
- """ Test the edit_issue of pagure.lib when the issue depends on
|
| |
- another.
|
| |
- """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- tests.create_projects(self.session)
|
| |
- repo = pagure.get_authorized_project(self.session, 'test')
|
| |
-
|
| |
- # Create 3 issues
|
| |
- msg = pagure.lib.new_issue(
|
| |
+ # Create issues to play with
|
| |
+ pagure.lib.new_issue(
|
| |
session=self.session,
|
| |
repo=repo,
|
| |
- title='Test issue #1',
|
| |
- content='We should work on this for the second time',
|
| |
- user='foo',
|
| |
- status='Open',
|
| |
+ title='Test issue',
|
| |
+ content='We should work on this',
|
| |
+ user='pingou',
|
| |
ticketfolder=None
|
| |
)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue #1')
|
| |
|
| |
- msg = pagure.lib.new_issue(
|
| |
- session=self.session,
|
| |
- repo=repo,
|
| |
- title='Test issue #2',
|
| |
- content='We should work on this for the second time',
|
| |
- user='foo',
|
| |
- status='Open',
|
| |
- ticketfolder=None
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue #2')
|
| |
+ issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
|
| |
- msg = pagure.lib.new_issue(
|
| |
+ pagure.lib.add_issue_comment(
|
| |
session=self.session,
|
| |
- repo=repo,
|
| |
- title='Test issue #3',
|
| |
- content='We should work on this for the second time',
|
| |
+ issue=issue,
|
| |
+ comment='Hey look a comment!',
|
| |
user='foo',
|
| |
- status='Open',
|
| |
ticketfolder=None
|
| |
)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue #3')
|
| |
-
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
-
|
| |
- self.assertEqual(repo.open_tickets, 3)
|
| |
- self.assertEqual(repo.open_tickets_public, 3)
|
| |
-
|
| |
- # Make issue #2 blocking on issue #1
|
| |
- msgs = pagure.lib.update_blocked_issue(
|
| |
- self.session,
|
| |
- repo,
|
| |
- issue,
|
| |
- blocks=['1'],
|
| |
- username='pingou',
|
| |
- ticketfolder=None,
|
| |
- )
|
| |
- self.assertEqual(msgs, ['Issue marked as blocking: #1'])
|
| |
-
|
| |
- # Make issue #2 depend on issue #3
|
| |
- msgs = pagure.lib.update_dependency_issue(
|
| |
- self.session,
|
| |
- repo,
|
| |
- issue,
|
| |
- depends=['3'],
|
| |
- username='pingou',
|
| |
- ticketfolder=None,
|
| |
- )
|
| |
- self.assertEqual(msgs, ['Issue marked as depending on: #3'])
|
| |
-
|
| |
- # Edit the issue #3
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=3)
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, None)
|
| |
-
|
| |
- msg = pagure.lib.edit_issue(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- title='Foo issue #2',
|
| |
- content='We should work on this period',
|
| |
- status='Closed',
|
| |
- close_status='Invalid',
|
| |
- private=True,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(
|
| |
- msg,
|
| |
- [
|
| |
- 'Issue status updated to: Closed (was: Open)',
|
| |
- 'Issue close_status updated to: Invalid',
|
| |
- 'Issue private status set to: True'
|
| |
- ]
|
| |
- )
|
| |
-
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
- @patch('pagure.lib.REDIS', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
| |
- def test_add_issue_dependency(self):
|
| |
- """ Test the add_issue_dependency of pagure.lib. """
|
| |
-
|
| |
- self.test_new_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
- issue_blocked = pagure.lib.search_issues(
|
| |
- self.session, repo, issueid=2)
|
| |
|
| |
- # Before
|
| |
- self.assertEqual(issue.parents, [])
|
| |
- self.assertEqual(issue.children, [])
|
| |
- self.assertEqual(issue_blocked.parents, [])
|
| |
- self.assertEqual(issue_blocked.children, [])
|
| |
-
|
| |
- self.assertRaises(
|
| |
- pagure.exceptions.PagureException,
|
| |
- pagure.lib.add_issue_dependency,
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- issue_blocked=issue,
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
-
|
| |
- msg = pagure.lib.add_issue_dependency(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- issue_blocked=issue_blocked,
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
self.session.commit()
|
| |
- self.assertEqual(msg, 'Issue marked as depending on: #2')
|
| |
-
|
| |
- # After
|
| |
- self.assertEqual(len(issue.parents), 0)
|
| |
- self.assertEqual(issue.parents, [])
|
| |
- self.assertEqual(len(issue.children), 1)
|
| |
- self.assertEqual(issue.children[0].id, 2)
|
| |
- self.assertEqual(issue.depending_text, [])
|
| |
- self.assertEqual(issue.blocking_text, [2])
|
| |
-
|
| |
- self.assertEqual(len(issue_blocked.children), 0)
|
| |
- self.assertEqual(issue_blocked.children, [])
|
| |
- self.assertEqual(len(issue_blocked.parents), 1)
|
| |
- self.assertEqual(issue_blocked.parents[0].id, 1)
|
| |
- self.assertEqual(issue_blocked.depending_text, [1])
|
| |
- self.assertEqual(issue_blocked.blocking_text, [])
|
| |
-
|
| |
- @patch('pagure.lib.REDIS')
|
| |
- @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
| |
- def test_edit_comment(self, mock_redis):
|
| |
- """ Test the edit_issue of pagure.lib. """
|
| |
- mock_redis.return_value = True
|
| |
-
|
| |
- self.test_add_issue_comment()
|
| |
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
+ self.assertEqual(repo.open_tickets, 1)
|
| |
+ self.assertEqual(repo.open_tickets_public, 1)
|
| |
|
| |
- self.assertEqual(mock_redis.publish.call_count, 0)
|
| |
+ self.assertEqual(mock_redis.publish.call_count, 4)
|
| |
|
| |
# Before
|
| |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
@@ -928,7 +96,7 @@
|
| |
folder=None)
|
| |
self.session.commit()
|
| |
self.assertEqual(msg, 'Comment updated')
|
| |
- self.assertEqual(mock_redis.publish.call_count, 2)
|
| |
+ self.assertEqual(mock_redis.publish.call_count, 6)
|
| |
|
| |
# After
|
| |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
@@ -940,14 +108,44 @@
|
| |
@patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
| |
def test_edit_comment_private(self, mock_redis):
|
| |
""" Test the edit_issue of pagure.lib. """
|
| |
+ mock_redis.return_value = True
|
| |
+ tests.create_projects(self.session)
|
| |
+
|
| |
+ repo = pagure.lib._get_project(self.session, 'test')
|
| |
+ pagure.lib.add_user_to_project(
|
| |
+ session=self.session,
|
| |
+ project=repo,
|
| |
+ new_user='foo',
|
| |
+ user='pingou'
|
| |
+ )
|
| |
+
|
| |
+ pagure.lib.new_issue(
|
| |
+ session=self.session,
|
| |
+ repo=repo,
|
| |
+ title='Test issue #1',
|
| |
+ content='We should work on this for the second time',
|
| |
+ user='foo',
|
| |
+ status='Open',
|
| |
+ ticketfolder=None,
|
| |
+ private=True,
|
| |
+ )
|
| |
+
|
| |
+ issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
|
| |
- self.test_add_issue_comment_private()
|
| |
+ pagure.lib.add_issue_comment(
|
| |
+ session=self.session,
|
| |
+ issue=issue,
|
| |
+ comment='Hey look a comment!',
|
| |
+ user='foo',
|
| |
+ ticketfolder=None
|
| |
+ )
|
| |
+
|
| |
+ self.session.commit()
|
| |
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
self.assertEqual(repo.open_tickets, 1)
|
| |
self.assertEqual(repo.open_tickets_public, 0)
|
| |
|
| |
- self.assertEqual(mock_redis.publish.call_count, 0)
|
| |
+ self.assertEqual(mock_redis.publish.call_count, 2)
|
| |
|
| |
# Before
|
| |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
@@ -964,7 +162,7 @@
|
| |
folder=None)
|
| |
self.session.commit()
|
| |
self.assertEqual(msg, 'Comment updated')
|
| |
- self.assertEqual(mock_redis.publish.call_count, 1)
|
| |
+ self.assertEqual(mock_redis.publish.call_count, 3)
|
| |
|
| |
# After
|
| |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
@@ -978,7 +176,38 @@
|
| |
""" Test the add_tag_obj of pagure.lib. """
|
| |
mock_redis.return_value=True
|
| |
|
| |
- self.test_edit_issue()
|
| |
+ tests.create_projects(self.session)
|
| |
+
|
| |
+ repo = pagure.lib._get_project(self.session, 'test')
|
| |
+ pagure.lib.add_user_to_project(
|
| |
+ session=self.session,
|
| |
+ project=repo,
|
| |
+ new_user='foo',
|
| |
+ user='pingou'
|
| |
+ )
|
| |
+
|
| |
+ # Create issues to play with
|
| |
+ pagure.lib.new_issue(
|
| |
+ session=self.session,
|
| |
+ repo=repo,
|
| |
+ title='Test issue',
|
| |
+ content='We should work on this',
|
| |
+ user='pingou',
|
| |
+ ticketfolder=None
|
| |
+ )
|
| |
+
|
| |
+ pagure.lib.new_issue(
|
| |
+ session=self.session,
|
| |
+ repo=repo,
|
| |
+ title='Test issue #2',
|
| |
+ content='We should work on this for the second time',
|
| |
+ user='foo',
|
| |
+ status='Open',
|
| |
+ ticketfolder=None
|
| |
+ )
|
| |
+
|
| |
+ self.session.commit()
|
| |
+
|
| |
repo = pagure.lib._get_project(self.session, 'test')
|
| |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
self.assertFalse(issue.private)
|
| |
@@ -1212,265 +441,7 @@
|
| |
self.session.commit()
|
| |
self.assertEqual(msgs, ['Edited tag: tag2(lorem ipsum)[black] to tag4(ipsum lorem)[purple]'])
|
| |
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_search_issues(self, p_send_email, p_ugt):
|
| |
- """ Test the search_issues of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- self.test_edit_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
-
|
| |
- # All issues
|
| |
- issues = pagure.lib.search_issues(self.session, repo)
|
| |
- self.assertEqual(len(issues), 2)
|
| |
- self.assertEqual(issues[1].id, 1)
|
| |
- self.assertEqual(issues[1].project_id, 1)
|
| |
- self.assertEqual(issues[1].status, 'Open')
|
| |
- self.assertEqual(issues[1].tags, [])
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(issues[0].status, 'Closed')
|
| |
- self.assertEqual(issues[0].close_status, 'Invalid')
|
| |
- self.assertEqual(issues[0].tags, [])
|
| |
-
|
| |
- # Issues by status
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, status='Closed')
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(issues[0].status, 'Closed')
|
| |
- self.assertEqual(issues[0].close_status, 'Invalid')
|
| |
- self.assertEqual(issues[0].tags, [])
|
| |
-
|
| |
- # Issues closed
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, closed=True)
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(issues[0].status, 'Closed')
|
| |
- self.assertEqual(issues[0].close_status, 'Invalid')
|
| |
- self.assertEqual(issues[0].tags, [])
|
| |
-
|
| |
- # Issues by tag
|
| |
- issues = pagure.lib.search_issues(self.session, repo, tags='foo')
|
| |
- self.assertEqual(len(issues), 0)
|
| |
- issues = pagure.lib.search_issues(self.session, repo, tags='!foo')
|
| |
- self.assertEqual(len(issues), 2)
|
| |
-
|
| |
- # Issue by id
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
- self.assertEqual(issue.title, 'Test issue')
|
| |
- self.assertEqual(issue.user.user, 'pingou')
|
| |
- self.assertEqual(issue.tags, [])
|
| |
-
|
| |
- # Issues by authors
|
| |
- issues = pagure.lib.search_issues(self.session, repo, author='foo')
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(issues[0].status, 'Closed')
|
| |
- self.assertEqual(issues[0].close_status, 'Invalid')
|
| |
- self.assertEqual(issues[0].tags, [])
|
| |
-
|
| |
- # Issues by assignee
|
| |
- issues = pagure.lib.search_issues(self.session, repo, assignee='foo')
|
| |
- self.assertEqual(len(issues), 0)
|
| |
- issues = pagure.lib.search_issues(self.session, repo, assignee='!foo')
|
| |
- self.assertEqual(len(issues), 2)
|
| |
-
|
| |
- issues = pagure.lib.search_issues(self.session, repo, private='foo')
|
| |
- self.assertEqual(len(issues), 2)
|
| |
-
|
| |
- @patch('pagure.lib.REDIS', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
| |
- def test_add_issue_assignee(self):
|
| |
- """ Test the add_issue_assignee of pagure.lib. """
|
| |
-
|
| |
- self.test_new_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
-
|
| |
- # Before
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, assignee='pingou')
|
| |
- self.assertEqual(len(issues), 0)
|
| |
-
|
| |
- # Test when it fails
|
| |
- self.assertRaises(
|
| |
- pagure.exceptions.PagureException,
|
| |
- pagure.lib.add_issue_assignee,
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- assignee='foo@foobar.com',
|
| |
- user='foo@pingou.com',
|
| |
- ticketfolder=None,
|
| |
- )
|
| |
-
|
| |
- self.assertRaises(
|
| |
- pagure.exceptions.PagureException,
|
| |
- pagure.lib.add_issue_assignee,
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- assignee='foo@bar.com',
|
| |
- user='foo@foopingou.com',
|
| |
- ticketfolder=None,
|
| |
- )
|
| |
-
|
| |
- # Set the assignee by its email
|
| |
- msg = pagure.lib.add_issue_assignee(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- assignee='foo@bar.com',
|
| |
- user='foo@pingou.com',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Issue assigned to foo@bar.com')
|
| |
-
|
| |
- # Change the assignee to someone else by its username
|
| |
- msg = pagure.lib.add_issue_assignee(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- assignee='pingou',
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Issue assigned to pingou (was: foo)')
|
| |
-
|
| |
- # After -- Searches by assignee
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, assignee='pingou')
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(issues[0].status, 'Open')
|
| |
- self.assertEqual(issues[0].tags, [])
|
| |
-
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, assignee=True)
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].title, 'Test issue #2')
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(issues[0].status, 'Open')
|
| |
- self.assertEqual(issues[0].tags, [])
|
| |
-
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, assignee=False)
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 1)
|
| |
- self.assertEqual(issues[0].title, 'Test issue')
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(issues[0].status, 'Open')
|
| |
- self.assertEqual(issues[0].tags, [])
|
| |
-
|
| |
- # Reset the assignee to no-one
|
| |
- msg = pagure.lib.add_issue_assignee(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- assignee=None,
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Assignee reset')
|
| |
-
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, assignee=False)
|
| |
- self.assertEqual(len(issues), 2)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[1].id, 1)
|
| |
-
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, assignee=True)
|
| |
- self.assertEqual(len(issues), 0)
|
| |
-
|
| |
- @patch('pagure.lib.REDIS', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
| |
- def test_add_issue_comment(self):
|
| |
- """ Test the add_issue_comment of pagure.lib. """
|
| |
-
|
| |
- self.test_new_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
-
|
| |
- # Before
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
- self.assertEqual(len(issue.comments), 0)
|
| |
-
|
| |
- # Set the assignee by its email
|
| |
- msg = pagure.lib.add_issue_assignee(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- assignee='foo@bar.com',
|
| |
- user='foo@pingou.com',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Issue assigned to foo@bar.com')
|
| |
-
|
| |
- # Add a comment to that issue
|
| |
- msg = pagure.lib.add_issue_comment(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- comment='Hey look a comment!',
|
| |
- user='foo',
|
| |
- ticketfolder=None
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Comment added')
|
| |
-
|
| |
- # After
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
- self.assertEqual(len(issue.comments), 1)
|
| |
- self.assertEqual(issue.comments[0].comment, 'Hey look a comment!')
|
| |
- self.assertEqual(issue.comments[0].user.user, 'foo')
|
| |
-
|
| |
- @patch('pagure.lib.REDIS', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
|
| |
- @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
| |
- def test_add_issue_comment_private(self):
|
| |
- """ Test the add_issue_comment of pagure.lib. """
|
| |
- tests.create_projects(self.session)
|
| |
- project = pagure.lib._get_project(self.session, 'test')
|
| |
-
|
| |
- msg = pagure.lib.new_issue(
|
| |
- session=self.session,
|
| |
- repo=project,
|
| |
- title='Test issue #1',
|
| |
- content='We should work on this for the second time',
|
| |
- user='foo',
|
| |
- status='Open',
|
| |
- ticketfolder=None,
|
| |
- private=True,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue #1')
|
| |
- self.assertEqual(project.open_tickets, 1)
|
| |
- self.assertEqual(project.open_tickets_public, 0)
|
| |
-
|
| |
- # Before
|
| |
- issue = pagure.lib.search_issues(self.session, project, issueid=1)
|
| |
- self.assertEqual(len(issue.comments), 0)
|
| |
-
|
| |
- # Add a comment to that issue
|
| |
- msg = pagure.lib.add_issue_comment(
|
| |
- session=self.session,
|
| |
- issue=issue,
|
| |
- comment='Hey look a comment!',
|
| |
- user='foo',
|
| |
- ticketfolder=None
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Comment added')
|
| |
|
| |
- # After
|
| |
- issue = pagure.lib.search_issues(self.session, project, issueid=1)
|
| |
- self.assertEqual(len(issue.comments), 1)
|
| |
- self.assertEqual(issue.comments[0].comment, 'Hey look a comment!')
|
| |
- self.assertEqual(issue.comments[0].user.user, 'foo')
|
| |
|
| |
@patch('pagure.lib.notify.send_email')
|
| |
def test_add_user_to_project(self, p_send_email):
|
| |
@@ -1972,98 +943,6 @@
|
| |
self.assertTrue(repo.settings['project_documentation'])
|
| |
self.assertFalse(repo.settings['pull_requests'])
|
| |
|
| |
- def test_search_issues_milestones_invalid(self):
|
| |
- """ Test the search_issues of pagure.lib. """
|
| |
-
|
| |
- self.test_edit_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(len(repo.issues), 2)
|
| |
-
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, milestones='foo')
|
| |
- self.assertEqual(len(issues), 0)
|
| |
-
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, milestones='foo', no_milestones=True)
|
| |
- self.assertEqual(len(issues), 2)
|
| |
-
|
| |
- def test_search_issues_custom_search(self):
|
| |
- """ Test the search_issues of pagure.lib. """
|
| |
-
|
| |
- self.test_edit_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(len(repo.issues), 2)
|
| |
-
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, custom_search={'foo': '*'})
|
| |
- self.assertEqual(len(issues), 0)
|
| |
-
|
| |
- def test_search_issues_offset(self):
|
| |
- """ Test the search_issues of pagure.lib. """
|
| |
-
|
| |
- self.test_edit_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
-
|
| |
- issues = pagure.lib.search_issues(self.session, repo)
|
| |
- self.assertEqual(len(issues), 2)
|
| |
- self.assertEqual([i.id for i in issues], [2, 1])
|
| |
-
|
| |
- issues = pagure.lib.search_issues(self.session, repo, offset=1)
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual([i.id for i in issues], [1])
|
| |
-
|
| |
- def test_search_issues_tags(self):
|
| |
- """ Test the search_issues of pagure.lib. """
|
| |
-
|
| |
- self.test_edit_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- self.assertEqual(len(repo.issues), 2)
|
| |
-
|
| |
- # Add `tag1` to one issues and `tag2` only to the other one
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
- msg = pagure.lib.add_tag_obj(
|
| |
- session=self.session,
|
| |
- obj=issue,
|
| |
- tags='tag1',
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Issue tagged with: tag1')
|
| |
-
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=2)
|
| |
- msg = pagure.lib.add_tag_obj(
|
| |
- session=self.session,
|
| |
- obj=issue,
|
| |
- tags='tag2',
|
| |
- user='pingou',
|
| |
- ticketfolder=None)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'Issue tagged with: tag2')
|
| |
-
|
| |
- # Search all issues tagged with `tag1`
|
| |
- issues = pagure.lib.search_issues(self.session, repo, tags='tag1')
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 1)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual([tag.tag for tag in issues[0].tags], ['tag1'])
|
| |
-
|
| |
- # Search all issues *not* tagged with `tag1`
|
| |
- issues = pagure.lib.search_issues(self.session, repo, tags='!tag1')
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(
|
| |
- [tag.tag for tag in issues[0].tags], ['tag2'])
|
| |
-
|
| |
- # Search all issues *not* tagged with `tag1` but tagged with `tag2`
|
| |
- issues = pagure.lib.search_issues(
|
| |
- self.session, repo, tags=['!tag1', 'tag2'])
|
| |
- self.assertEqual(len(issues), 1)
|
| |
- self.assertEqual(issues[0].id, 2)
|
| |
- self.assertEqual(issues[0].project_id, 1)
|
| |
- self.assertEqual(
|
| |
- [tag.tag for tag in issues[0].tags], ['tag2'])
|
| |
-
|
| |
def test_get_tags_of_project(self):
|
| |
""" Test the get_tags_of_project of pagure.lib. """
|
| |
|
| |
@@ -2786,12 +1665,51 @@
|
| |
def test_remove_issue_dependency(self):
|
| |
""" Test remove_issue_dependency of pagure.lib. """
|
| |
|
| |
- self.test_add_issue_dependency()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
+ tests.create_projects(self.session)
|
| |
+
|
| |
+ repo = pagure.lib._get_project(self.session, 'test')
|
| |
+ pagure.lib.add_user_to_project(
|
| |
+ session=self.session,
|
| |
+ project=repo,
|
| |
+ new_user='foo',
|
| |
+ user='pingou'
|
| |
+ )
|
| |
+
|
| |
+ # Create issues to play with
|
| |
+ pagure.lib.new_issue(
|
| |
+ session=self.session,
|
| |
+ repo=repo,
|
| |
+ title='Test issue',
|
| |
+ content='We should work on this',
|
| |
+ user='pingou',
|
| |
+ ticketfolder=None
|
| |
+ )
|
| |
+
|
| |
+ pagure.lib.new_issue(
|
| |
+ session=self.session,
|
| |
+ repo=repo,
|
| |
+ title='Test issue #2',
|
| |
+ content='We should work on this for the second time',
|
| |
+ user='foo',
|
| |
+ status='Open',
|
| |
+ ticketfolder=None
|
| |
+ )
|
| |
+
|
| |
+ self.session.commit()
|
| |
+
|
| |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
issue_blocked = pagure.lib.search_issues(
|
| |
self.session, repo, issueid=2)
|
| |
|
| |
+ pagure.lib.add_issue_dependency(
|
| |
+ session=self.session,
|
| |
+ issue=issue,
|
| |
+ issue_blocked=issue_blocked,
|
| |
+ user='pingou',
|
| |
+ ticketfolder=None)
|
| |
+
|
| |
+ self.session.commit()
|
| |
+
|
| |
# Before
|
| |
self.assertEqual(len(issue.children), 1)
|
| |
self.assertEqual(issue.children[0].id, 2)
|
| |
@@ -2845,189 +1763,47 @@
|
| |
p_send_email.return_value = True
|
| |
p_ugt.return_value = True
|
| |
|
| |
- self.test_add_issue_comment()
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
-
|
| |
- self.assertEqual(
|
| |
- pagure.lib.get_issue_comment(self.session, issue.uid, 10),
|
| |
- None
|
| |
- )
|
| |
-
|
| |
- comment = pagure.lib.get_issue_comment(self.session, issue.uid, 1)
|
| |
- self.assertEqual(comment.comment, 'Hey look a comment!')
|
| |
-
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_get_issue_by_uid(self, p_send_email, p_ugt):
|
| |
- """ Test the get_issue_by_uid of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- self.test_new_issue()
|
| |
-
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
-
|
| |
- self.assertEqual(
|
| |
- pagure.lib.get_issue_by_uid(self.session, 'foobar'),
|
| |
- None
|
| |
- )
|
| |
-
|
| |
- new_issue = pagure.lib.get_issue_by_uid(self.session, issue.uid)
|
| |
- self.assertEqual(issue, new_issue)
|
| |
-
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_update_tags(self, p_send_email, p_ugt):
|
| |
- """ Test the update_tags of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
+ tests.create_projects(self.session)
|
| |
|
| |
- self.test_new_issue()
|
| |
repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
-
|
| |
- # before
|
| |
- self.assertEqual(repo.tags_colored, [])
|
| |
- self.assertEqual(issue.tags_text, [])
|
| |
-
|
| |
- messages = pagure.lib.update_tags(
|
| |
- self.session, issue, 'tag', 'pingou', ticketfolder=None)
|
| |
- self.assertEqual(messages, ['Issue tagged with: tag'])
|
| |
-
|
| |
- # after
|
| |
- repo = pagure.get_authorized_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
-
|
| |
- self.assertEqual(
|
| |
- [t.tag for t in repo.tags_colored], ['tag'])
|
| |
- self.assertEqual(issue.tags_text, ['tag'])
|
| |
-
|
| |
- # Replace the tag by two others
|
| |
- messages = pagure.lib.update_tags(
|
| |
- self.session, issue, ['tag2', 'tag3'], 'pingou',
|
| |
- ticketfolder=None)
|
| |
- self.assertEqual(
|
| |
- messages, [
|
| |
- 'Issue tagged with: tag2, tag3',
|
| |
- 'Issue **un**tagged with: tag'
|
| |
- ]
|
| |
+ pagure.lib.add_user_to_project(
|
| |
+ session=self.session,
|
| |
+ project=repo,
|
| |
+ new_user='foo',
|
| |
+ user='pingou'
|
| |
)
|
| |
|
| |
- # after
|
| |
- repo = pagure.get_authorized_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
-
|
| |
- self.assertEqual(
|
| |
- sorted([t.tag for t in repo.tags_colored]),
|
| |
- ['tag', 'tag2', 'tag3'])
|
| |
- self.assertEqual(issue.tags_text, ['tag2', 'tag3'])
|
| |
-
|
| |
-
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_update_dependency_issue(self, p_send_email, p_ugt):
|
| |
- """ Test the update_dependency_issue of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
-
|
| |
- self.test_new_issue()
|
| |
- repo = pagure.lib._get_project(self.session, 'test')
|
| |
- issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
-
|
| |
- self.assertEqual(repo.open_tickets, 2)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
# Create issues to play with
|
| |
- msg = pagure.lib.new_issue(
|
| |
+ pagure.lib.new_issue(
|
| |
session=self.session,
|
| |
repo=repo,
|
| |
- title='Test issue #3',
|
| |
- content='We should work on this (3rd time!)',
|
| |
+ title='Test issue',
|
| |
+ content='We should work on this',
|
| |
user='pingou',
|
| |
- ticketfolder=None,
|
| |
- private=True,
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue #3')
|
| |
-
|
| |
- self.assertEqual(repo.open_tickets, 3)
|
| |
- self.assertEqual(repo.open_tickets_public, 2)
|
| |
-
|
| |
- # before
|
| |
- self.assertEqual(issue.tags_text, [])
|
| |
- self.assertEqual(issue.depending_text, [])
|
| |
- self.assertEqual(issue.blocking_text, [])
|
| |
-
|
| |
- messages = pagure.lib.update_dependency_issue(
|
| |
- self.session, repo, issue, '2', 'pingou', ticketfolder=None)
|
| |
- self.assertEqual(messages, ['Issue marked as depending on: #2'])
|
| |
- messages = pagure.lib.update_dependency_issue(
|
| |
- self.session, repo, issue, ['3', '4', 5], 'pingou',
|
| |
- ticketfolder=None)
|
| |
- self.assertEqual(
|
| |
- messages,
|
| |
- [
|
| |
- 'Issue marked as depending on: #3',
|
| |
- 'Issue marked as depending on: #4',
|
| |
- 'Issue marked as depending on: #5',
|
| |
- 'Issue **un**marked as depending on: #2'
|
| |
- ]
|
| |
+ ticketfolder=None
|
| |
)
|
| |
|
| |
- # after
|
| |
- self.assertEqual(issue.tags_text, [])
|
| |
- self.assertEqual(issue.depending_text, [3])
|
| |
- self.assertEqual(issue.blocking_text, [])
|
| |
-
|
| |
- @patch('pagure.lib.git.update_git')
|
| |
- @patch('pagure.lib.notify.send_email')
|
| |
- def test_update_blocked_issue(self, p_send_email, p_ugt):
|
| |
- """ Test the update_blocked_issue of pagure.lib. """
|
| |
- p_send_email.return_value = True
|
| |
- p_ugt.return_value = True
|
| |
+ self.session.commit()
|
| |
|
| |
- self.test_new_issue()
|
| |
repo = pagure.lib._get_project(self.session, 'test')
|
| |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
| |
|
| |
- # Create issues to play with
|
| |
- msg = pagure.lib.new_issue(
|
| |
+ pagure.lib.add_issue_comment(
|
| |
session=self.session,
|
| |
- repo=repo,
|
| |
- title='Test issue #3',
|
| |
- content='We should work on this (3rd time!)',
|
| |
- user='pingou',
|
| |
- ticketfolder=None,
|
| |
- private=True,
|
| |
+ issue=issue,
|
| |
+ comment='Hey look a comment!',
|
| |
+ user='foo',
|
| |
+ ticketfolder=None
|
| |
)
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg.title, 'Test issue #3')
|
| |
-
|
| |
- # before
|
| |
- self.assertEqual(issue.tags_text, [])
|
| |
- self.assertEqual(issue.depending_text, [])
|
| |
- self.assertEqual(issue.blocking_text, [])
|
| |
-
|
| |
- messages = pagure.lib.update_blocked_issue(
|
| |
- self.session, repo, issue, '2', 'pingou', ticketfolder=None)
|
| |
- self.assertEqual(messages, ['Issue marked as blocking: #2'])
|
| |
- messages = pagure.lib.update_blocked_issue(
|
| |
- self.session, repo, issue, ['3', '4', 5], 'pingou',
|
| |
- ticketfolder=None)
|
| |
+
|
| |
self.assertEqual(
|
| |
- messages, [
|
| |
- 'Issue marked as blocking: #3',
|
| |
- 'Issue marked as blocking: #4',
|
| |
- 'Issue marked as blocking: #5',
|
| |
- 'Issue **un**marked as blocking: #2'])
|
| |
+ pagure.lib.get_issue_comment(self.session, issue.uid, 10),
|
| |
+ None
|
| |
+ )
|
| |
+
|
| |
+ comment = pagure.lib.get_issue_comment(self.session, issue.uid, 1)
|
| |
+ self.assertEqual(comment.comment, 'Hey look a comment!')
|
| |
|
| |
- # after
|
| |
- self.assertEqual(issue.tags_text, [])
|
| |
- self.assertEqual(issue.depending_text, [])
|
| |
- self.assertEqual(issue.blocking_text, [3])
|
| |
|
| |
@patch('pagure.lib.notify.send_email')
|
| |
def test_add_pull_request_assignee(self, mockemail):
|
| |
@@ -4305,202 +3081,6 @@
|
| |
sorted(acls)
|
| |
)
|
| |
|
| |
- def test_get_project_users(self):
|
| |
- ''' Test the get_project_users method when combine is True
|
| |
- '''
|
| |
-
|
| |
- tests.create_projects(self.session)
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
-
|
| |
- # Default value of combine is True
|
| |
- # which means the an admin is a user, committer as well
|
| |
- # and a committer is also a user
|
| |
- # and a user is just a user
|
| |
- users = project.get_project_users(access='admin')
|
| |
-
|
| |
- # Only pingou is the admin as of now
|
| |
- # But, he is the creator and
|
| |
- # the creator of the project is not listed in user_projects
|
| |
- # table. Thus, get_projec_users won't return him as an admin
|
| |
- # He has all the access of an admin though
|
| |
- self.assertEqual(len(users), 0)
|
| |
- self.assertEqual(project.user.username, 'pingou')
|
| |
-
|
| |
- # Wrong access level, should raise Accesslevelnotfound exception
|
| |
- self.assertRaises(
|
| |
- pagure.exceptions.AccessLevelNotFound,
|
| |
- project.get_project_users,
|
| |
- access='owner',
|
| |
- )
|
| |
-
|
| |
- # Let's add a new user to the project, 'foo'
|
| |
- # By default, if no access is specified, he becomes an admin
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- # since, he is an admin, the msg should be 'User added'
|
| |
- self.assertEqual(msg, 'User added')
|
| |
-
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
- users = project.get_project_users(access='admin')
|
| |
-
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- # foo should be a committer as well, since he is an admin
|
| |
- users = project.get_project_users(access='commit')
|
| |
-
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- # the admin also has ticket access
|
| |
- users = project.get_project_users(access='ticket')
|
| |
-
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- # let's update the access of foo to 'committer'
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou',
|
| |
- access='commit'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'User access updated')
|
| |
-
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
- # No admin now, even though pingou the creator is there
|
| |
- users = project.get_project_users(access='admin')
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- users = project.get_project_users(access='commit')
|
| |
- # foo is the committer currently
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- users = project.get_project_users(access='ticket')
|
| |
-
|
| |
- # foo also has ticket rights
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- # let's update the access of foo to 'ticket'
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou',
|
| |
- access='ticket'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'User access updated')
|
| |
-
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
- # No admin now, even though pingou the creator is there
|
| |
- users = project.get_project_users(access='admin')
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- users = project.get_project_users(access='commit')
|
| |
- # foo deosn't have commit rights now
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- users = project.get_project_users(access='ticket')
|
| |
-
|
| |
- # foo does have tickets right though
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- def test_get_project_users_combine_false(self):
|
| |
- ''' Test the get_project_users method when combine is False
|
| |
- '''
|
| |
-
|
| |
- tests.create_projects(self.session)
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
-
|
| |
- # Let's add a new user to the project, 'foo'
|
| |
- # By default, if no access is specified, he becomes an admin
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- # since, he is an admin, the msg should be 'User added'
|
| |
- self.assertEqual(msg, 'User added')
|
| |
-
|
| |
- # only one admin
|
| |
- users = project.get_project_users(access='admin', combine=False)
|
| |
-
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- # No user with only commit access
|
| |
- users = project.get_project_users(access='commit', combine=False)
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- # No user with only ticket access
|
| |
- users = project.get_project_users(access='ticket', combine=False)
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- # Update the access level of foo user to commit
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou',
|
| |
- access='commit'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'User access updated')
|
| |
-
|
| |
- # He is just a committer
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
- users = project.get_project_users(access='admin', combine=False)
|
| |
-
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- # He is just a committer
|
| |
- users = project.get_project_users(access='commit', combine=False)
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
- # He is just a committer
|
| |
- users = project.get_project_users(access='ticket', combine=False)
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- # Update the access level of foo user to ticket
|
| |
- msg = pagure.lib.add_user_to_project(
|
| |
- self.session,
|
| |
- project=project,
|
| |
- new_user='foo',
|
| |
- user='pingou',
|
| |
- access='ticket'
|
| |
- )
|
| |
- self.session.commit()
|
| |
- self.assertEqual(msg, 'User access updated')
|
| |
-
|
| |
- # He is just a ticketer
|
| |
- project = pagure.get_authorized_project(self.session, project_name='test')
|
| |
- users = project.get_project_users(access='admin',combine=False)
|
| |
-
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- # He is just a ticketer
|
| |
- users = project.get_project_users(access='commit', combine=False)
|
| |
- self.assertEqual(len(users), 0)
|
| |
-
|
| |
- # He is just a ticketer
|
| |
- users = project.get_project_users(access='ticket', combine=False)
|
| |
- self.assertEqual(len(users), 1)
|
| |
- self.assertEqual(users[0].username, 'foo')
|
| |
-
|
| |
def test_get_project_groups(self):
|
| |
''' Test the get_project_groups method when combine is True
|
| |
'''
|
| |
@@ -5476,43 +4056,6 @@
|
| |
email='foo@pingou.com'
|
| |
)
|
| |
|
| |
- def test_get_acls(self):
|
| |
- """ Test the get_acls function of pagure.lib. """
|
| |
- acls = pagure.lib.get_acls(self.session)
|
| |
- self.assertEqual(
|
| |
- [a.name for a in acls],
|
| |
- [
|
| |
- 'create_project',
|
| |
- 'fork_project',
|
| |
- 'issue_assign',
|
| |
- 'issue_change_status',
|
| |
- 'issue_comment',
|
| |
- 'issue_create',
|
| |
- 'issue_subscribe',
|
| |
- 'issue_update',
|
| |
- 'issue_update_custom_fields',
|
| |
- 'issue_update_milestone',
|
| |
- 'modify_project',
|
| |
- 'pull_request_close',
|
| |
- 'pull_request_comment',
|
| |
- 'pull_request_flag',
|
| |
- 'pull_request_merge'
|
| |
- ]
|
| |
- )
|
| |
-
|
| |
- def test_get_acls_restrict_one(self):
|
| |
- """ Test the get_acls function of pagure.lib. """
|
| |
- acls = pagure.lib.get_acls(self.session, restrict='create_project')
|
| |
- self.assertEqual([a.name for a in acls], ['create_project'])
|
| |
-
|
| |
- def test_get_acls_restrict_two(self):
|
| |
- """ Test the get_acls function of pagure.lib. """
|
| |
- acls = pagure.lib.get_acls(
|
| |
- self.session, restrict=['create_project', 'issue_create'])
|
| |
- self.assertEqual(
|
| |
- [a.name for a in acls],
|
| |
- ['create_project', 'issue_create'])
|
| |
-
|
| |
def test_filter_img_src(self):
|
| |
""" Test the filter_img_src function of pagure.lib. """
|
| |
for name in ('alt', 'height', 'width', 'class'):
|
| |
@@ -5796,73 +4339,6 @@
|
| |
user_obj=None,
|
| |
)
|
| |
|
| |
- def test_search_token_no_acls(self):
|
| |
- """ Test the search_token function of pagure.lib. """
|
| |
- tests.create_projects(self.session)
|
| |
- tests.create_tokens(self.session)
|
| |
- tests.create_tokens_acl(self.session)
|
| |
-
|
| |
- out = pagure.lib.search_token(
|
| |
- self.session,
|
| |
- []
|
| |
- )
|
| |
- self.assertEqual(len(out), 1)
|
| |
- self.assertEqual(out[0].id, 'aaabbbcccddd')
|
| |
-
|
| |
- def test_search_token_single_acls(self):
|
| |
- """ Test the search_token function of pagure.lib. """
|
| |
- tests.create_projects(self.session)
|
| |
- tests.create_tokens(self.session)
|
| |
- tests.create_tokens_acl(self.session)
|
| |
-
|
| |
- out = pagure.lib.search_token(
|
| |
- self.session,
|
| |
- 'issue_create',
|
| |
- )
|
| |
- self.assertEqual(len(out), 1)
|
| |
- self.assertEqual(out[0].id, 'aaabbbcccddd')
|
| |
-
|
| |
- def test_search_token_single_acls_user(self):
|
| |
- """ Test the search_token function of pagure.lib. """
|
| |
- tests.create_projects(self.session)
|
| |
- tests.create_tokens(self.session)
|
| |
- tests.create_tokens_acl(self.session)
|
| |
-
|
| |
- out = pagure.lib.search_token(
|
| |
- self.session,
|
| |
- 'issue_create',
|
| |
- user='pingou',
|
| |
- )
|
| |
- self.assertEqual(len(out), 1)
|
| |
- self.assertEqual(out[0].id, 'aaabbbcccddd')
|
| |
-
|
| |
- out = pagure.lib.search_token(
|
| |
- self.session,
|
| |
- 'issue_create',
|
| |
- user='foo',
|
| |
- )
|
| |
- self.assertEqual(len(out), 0)
|
| |
-
|
| |
- def test_search_token_single_acls_active(self):
|
| |
- """ Test the search_token function of pagure.lib. """
|
| |
- tests.create_projects(self.session)
|
| |
- tests.create_tokens(self.session)
|
| |
- tests.create_tokens_acl(self.session)
|
| |
-
|
| |
- out = pagure.lib.search_token(
|
| |
- self.session,
|
| |
- 'issue_create',
|
| |
- active=True
|
| |
- )
|
| |
- self.assertEqual(len(out), 1)
|
| |
- self.assertEqual(out[0].id, 'aaabbbcccddd')
|
| |
-
|
| |
- out = pagure.lib.search_token(
|
| |
- self.session,
|
| |
- 'issue_create',
|
| |
- expired=True
|
| |
- )
|
| |
- self.assertEqual(len(out), 0)
|
| |
|
| |
if __name__ == '__main__':
|
| |
unittest.main(verbosity=2)
|
| |
This is quite a big change, I have continued refactoring the unit test for pagure.lib methods. I have moved the related tests under the tests/lib folder.
I did not managed to run the full unit test suite in environment, so it would be good to test this change locally. I am also interested to see if it speed up a little the unit test runtime.