|
Pierre-Yves Chibon |
8b45f6 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
"""
|
|
Pierre-Yves Chibon |
b63f28 |
(c) 2015-2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
Authors:
|
|
Pierre-Yves Chibon |
8b45f6 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
"""
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
8b45f6 |
import pkg_resources
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
import unittest
|
|
Pierre-Yves Chibon |
8b45f6 |
import sys
|
|
Pierre-Yves Chibon |
8b45f6 |
import os
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
from mock import patch
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
8b45f6 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
fe5017 |
import pagure.lib
|
|
Pierre-Yves Chibon |
8b45f6 |
import tests
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
fe5017 |
class PagureLibModeltests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Tests for pagure.lib.model """
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
def test_user__repr__(self):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the User.__repr__ function of pagure.lib.model. """
|
|
Pierre-Yves Chibon |
fe5017 |
item = pagure.lib.search_user(self.session, email='foo@bar.com')
|
|
Pierre-Yves Chibon |
8b45f6 |
self.assertEqual(str(item), 'User: 2 - name foo')
|
|
Pierre-Yves Chibon |
8b45f6 |
self.assertEqual('foo', item.user)
|
|
Pierre-Yves Chibon |
8b45f6 |
self.assertEqual('foo', item.username)
|
|
Pierre-Yves Chibon |
8b45f6 |
self.assertEqual([], item.groups)
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
fe5017 |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
fe5017 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
c6bb48 |
def test_issue__repr__(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the Issue.__repr__ function of pagure.lib.model. """
|
|
Pierre-Yves Chibon |
c6bb48 |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
c6bb48 |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
c6bb48 |
|
|
Pierre-Yves Chibon |
c6bb48 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
fe5017 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c6bb48 |
|
|
Pierre-Yves Chibon |
c6bb48 |
# Create an issue
|
|
Pierre-Yves Chibon |
fe5017 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
c6bb48 |
session=self.session,
|
|
Pierre-Yves Chibon |
c6bb48 |
repo=repo,
|
|
Pierre-Yves Chibon |
c6bb48 |
title='Test issue',
|
|
Pierre-Yves Chibon |
c6bb48 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
c6bb48 |
user='pingou',
|
|
Pierre-Yves Chibon |
c6bb48 |
ticketfolder=None
|
|
Pierre-Yves Chibon |
c6bb48 |
)
|
|
Pierre-Yves Chibon |
11d78c |
self.assertEqual(msg.title, 'Test issue')
|
|
Pierre-Yves Chibon |
c6bb48 |
|
|
Pierre-Yves Chibon |
fe5017 |
issues = pagure.lib.search_issues(self.session, repo)
|
|
Pierre-Yves Chibon |
c6bb48 |
self.assertEqual(len(issues), 1)
|
|
Pierre-Yves Chibon |
c6bb48 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
c6bb48 |
str(issues[0]),
|
|
Pierre-Yves Chibon |
c6bb48 |
'Issue(1, project:test, user:pingou, title:Test issue)')
|
|
Pierre-Yves Chibon |
c6bb48 |
|
|
Pierre-Yves Chibon |
fe5017 |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
fe5017 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
17d33a |
def test_pullrequest__repr__(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the PullRequest.__repr__ function of pagure.lib.model. """
|
|
Pierre-Yves Chibon |
17d33a |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
17d33a |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
17d33a |
|
|
Pierre-Yves Chibon |
17d33a |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
17d33a |
# Create a forked repo
|
|
Pierre-Yves Chibon |
fe5017 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
17d33a |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
17d33a |
name='test',
|
|
Pierre-Yves Chibon |
17d33a |
description='test project #1',
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
Pierre-Yves Chibon |
17d33a |
parent_id=1,
|
|
Pierre-Yves Chibon |
e2259d |
hook_token='aaabbbyyy',
|
|
Pierre-Yves Chibon |
17d33a |
)
|
|
Pierre-Yves Chibon |
17d33a |
self.session.commit()
|
|
Pierre-Yves Chibon |
17d33a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
17d33a |
|
|
Pierre-Yves Chibon |
fe5017 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fe5017 |
forked_repo = pagure.lib.get_project(
|
|
Pierre-Yves Chibon |
17d33a |
self.session, 'test', user='pingou')
|
|
Pierre-Yves Chibon |
17d33a |
|
|
Pierre-Yves Chibon |
17d33a |
# Create an pull-request
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
17d33a |
session=self.session,
|
|
Pierre-Yves Chibon |
17d33a |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
17d33a |
branch_from='master',
|
|
Pierre-Yves Chibon |
17d33a |
repo_to=repo,
|
|
Pierre-Yves Chibon |
17d33a |
branch_to='master',
|
|
Pierre-Yves Chibon |
17d33a |
title='test pull-request',
|
|
Pierre-Yves Chibon |
8582b5 |
user='pingou',
|
|
Pierre-Yves Chibon |
8582b5 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
17d33a |
)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
f9c5f9 |
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
f9c5f9 |
str(req),
|
|
Pierre-Yves Chibon |
f9c5f9 |
'PullRequest(1, project:test, user:pingou, '
|
|
Pierre-Yves Chibon |
f9c5f9 |
'title:test pull-request)')
|
|
Pierre-Yves Chibon |
17d33a |
|
|
Pierre-Yves Chibon |
fe5017 |
request = pagure.lib.search_pull_requests(self.session, requestid=1)
|
|
Pierre-Yves Chibon |
17d33a |
self.assertEqual(
|
|
Pierre-Yves Chibon |
17d33a |
str(request),
|
|
Pierre-Yves Chibon |
17d33a |
'PullRequest(1, project:test, user:pingou, '
|
|
Pierre-Yves Chibon |
17d33a |
'title:test pull-request)')
|
|
Pierre-Yves Chibon |
17d33a |
|
|
Pierre-Yves Chibon |
fe5017 |
def test_paguregroup__repr__(self):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the PagureGroup.__repr__ function of pagure.lib.model. """
|
|
Pierre-Yves Chibon |
fe5017 |
item = pagure.lib.model.PagureGroup(
|
|
Pierre-Yves Chibon |
e1c99a |
group_name='admin',
|
|
Pierre-Yves Chibon |
ce6666 |
display_name='admin group',
|
|
Pierre-Yves Chibon |
ce6666 |
description='the local admin group',
|
|
Pierre-Yves Chibon |
d5efb0 |
user_id=1,
|
|
Pierre-Yves Chibon |
e1c99a |
)
|
|
Pierre-Yves Chibon |
e1c99a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
e1c99a |
self.session.commit()
|
|
Pierre-Yves Chibon |
e1c99a |
|
|
Pierre-Yves Chibon |
e1c99a |
self.assertEqual(str(item), 'Group: 1 - name admin')
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
302953 |
def test_tagissue__repr__(self):
|
|
Pierre-Yves Chibon |
302953 |
""" Test the TagIssue.__repr__ function of pagure.lib.model. """
|
|
Pierre-Yves Chibon |
302953 |
self.test_issue__repr__()
|
|
Pierre-Yves Chibon |
302953 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
302953 |
issues = pagure.lib.search_issues(self.session, repo)
|
|
Pierre-Yves Chibon |
302953 |
self.assertEqual(len(issues), 1)
|
|
Pierre-Yves Chibon |
302953 |
|
|
Pierre-Yves Chibon |
a8f682 |
item = pagure.lib.model.Tag(tag='foo')
|
|
Pierre-Yves Chibon |
302953 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
302953 |
self.session.commit()
|
|
Pierre-Yves Chibon |
302953 |
|
|
Pierre-Yves Chibon |
302953 |
item = pagure.lib.model.TagIssue(
|
|
Pierre-Yves Chibon |
302953 |
issue_uid=issues[0].uid,
|
|
Pierre-Yves Chibon |
a8f682 |
tag='foo'
|
|
Pierre-Yves Chibon |
302953 |
)
|
|
Pierre-Yves Chibon |
302953 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
302953 |
self.session.commit()
|
|
Pierre-Yves Chibon |
302953 |
self.assertEqual(str(item), 'TagIssue(issue:1, tag:foo)')
|
|
Pierre-Yves Chibon |
302953 |
|
|
Pierre-Yves Chibon |
a8f682 |
def test_tagissuecolor__repr__(self):
|
|
Pierre-Yves Chibon |
a8f682 |
""" Test the TagIssue.__repr__ function of pagure.lib.model. """
|
|
Pierre-Yves Chibon |
a8f682 |
self.test_issue__repr__()
|
|
Pierre-Yves Chibon |
a8f682 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a8f682 |
issues = pagure.lib.search_issues(self.session, repo)
|
|
Pierre-Yves Chibon |
a8f682 |
self.assertEqual(len(issues), 1)
|
|
Pierre-Yves Chibon |
a8f682 |
|
|
Pierre-Yves Chibon |
a8f682 |
item = pagure.lib.model.TagColored(
|
|
Pierre-Yves Chibon |
a8f682 |
tag='foo',
|
|
Pradeep CE (cep) |
dc15c9 |
tag_description='bar',
|
|
Pierre-Yves Chibon |
a8f682 |
tag_color='DeepSkyBlue',
|
|
Pierre-Yves Chibon |
a8f682 |
project_id=repo.id)
|
|
Pierre-Yves Chibon |
a8f682 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
a8f682 |
self.session.commit()
|
|
Pierre-Yves Chibon |
a8f682 |
|
|
Pierre-Yves Chibon |
a8f682 |
item = pagure.lib.model.TagIssueColored(
|
|
Pierre-Yves Chibon |
a8f682 |
issue_uid=issues[0].uid,
|
|
Pierre-Yves Chibon |
a8f682 |
tag_id=item.id
|
|
Pierre-Yves Chibon |
a8f682 |
)
|
|
Pierre-Yves Chibon |
a8f682 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
a8f682 |
self.session.commit()
|
|
Pierre-Yves Chibon |
a8f682 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
a8f682 |
str(item),
|
|
Pierre-Yves Chibon |
a8f682 |
'TagIssueColored(issue:1, tag:foo, project:test)'
|
|
Pierre-Yves Chibon |
a8f682 |
)
|
|
Pierre-Yves Chibon |
a8f682 |
|
|
Pierre-Yves Chibon |
830728 |
def test_group_project_ordering(self):
|
|
Pierre-Yves Chibon |
830728 |
""" Test the ordering of project.groups. """
|
|
Pierre-Yves Chibon |
830728 |
# Create three projects
|
|
Pierre-Yves Chibon |
830728 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
830728 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
830728 |
name='aaa',
|
|
Pierre-Yves Chibon |
830728 |
description='Project aaa',
|
|
Pierre-Yves Chibon |
830728 |
hook_token='aaabbbccc',
|
|
Pierre-Yves Chibon |
830728 |
)
|
|
Pierre-Yves Chibon |
830728 |
item.close_status = ['Invalid', 'Fixed', 'Duplicate']
|
|
Pierre-Yves Chibon |
830728 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
830728 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
830728 |
name='KKK',
|
|
Pierre-Yves Chibon |
830728 |
description='project KKK',
|
|
Pierre-Yves Chibon |
830728 |
hook_token='aaabbbddd',
|
|
Pierre-Yves Chibon |
830728 |
)
|
|
Pierre-Yves Chibon |
830728 |
item.close_status = ['Invalid', 'Fixed', 'Duplicate']
|
|
Pierre-Yves Chibon |
830728 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
830728 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
830728 |
name='zzz',
|
|
Pierre-Yves Chibon |
830728 |
description='Namespaced project zzz',
|
|
Pierre-Yves Chibon |
830728 |
hook_token='aaabbbeee',
|
|
Pierre-Yves Chibon |
830728 |
namespace='somenamespace',
|
|
Pierre-Yves Chibon |
830728 |
)
|
|
Pierre-Yves Chibon |
830728 |
item.close_status = ['Invalid', 'Fixed', 'Duplicate']
|
|
Pierre-Yves Chibon |
830728 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
# Create a group
|
|
Pierre-Yves Chibon |
830728 |
group = pagure.lib.model.PagureGroup(
|
|
Pierre-Yves Chibon |
830728 |
group_name='testgrp',
|
|
Pierre-Yves Chibon |
830728 |
display_name='Test group',
|
|
Pierre-Yves Chibon |
830728 |
description=None,
|
|
Pierre-Yves Chibon |
b63f28 |
group_type='user',
|
|
Pierre-Yves Chibon |
830728 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
830728 |
)
|
|
Pierre-Yves Chibon |
830728 |
item.close_status = ['Invalid', 'Fixed', 'Duplicate']
|
|
Pierre-Yves Chibon |
830728 |
self.session.add(group)
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
self.session.commit()
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
# Add projects to group
|
|
Pierre-Yves Chibon |
830728 |
for ns, reponame in [
|
|
Pierre-Yves Chibon |
830728 |
(None, 'aaa'), (None, 'KKK'), ('somenamespace', 'zzz')]:
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
repo = pagure.lib.get_project(
|
|
Pierre-Yves Chibon |
830728 |
self.session, reponame, namespace=ns)
|
|
Pierre-Yves Chibon |
830728 |
msg = pagure.lib.add_group_to_project(
|
|
Pierre-Yves Chibon |
830728 |
self.session,
|
|
Pierre-Yves Chibon |
830728 |
project=repo,
|
|
Pierre-Yves Chibon |
830728 |
new_group='testgrp',
|
|
Pierre-Yves Chibon |
830728 |
user='pingou',
|
|
Pierre-Yves Chibon |
830728 |
create=False,
|
|
Pierre-Yves Chibon |
830728 |
is_admin=False
|
|
Pierre-Yves Chibon |
830728 |
)
|
|
Pierre-Yves Chibon |
830728 |
self.session.commit()
|
|
Pierre-Yves Chibon |
830728 |
self.assertEqual(msg, 'Group added')
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
# Check the ordering
|
|
Pierre-Yves Chibon |
830728 |
group = pagure.lib.search_groups(self.session, group_name='testgrp')
|
|
Pierre-Yves Chibon |
022a29 |
# Default PostgreSQL order
|
|
Pierre-Yves Chibon |
022a29 |
order = ['aaa', 'KKK', 'somenamespace/zzz']
|
|
Pierre-Yves Chibon |
022a29 |
# Odd, SQLite order
|
|
Pierre-Yves Chibon |
022a29 |
if str(self.session.bind.engine.url).startswith('sqlite:'):
|
|
Pierre-Yves Chibon |
022a29 |
order = ['somenamespace/zzz', 'aaa', 'KKK']
|
|
Pierre-Yves Chibon |
022a29 |
|
|
Pierre-Yves Chibon |
830728 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
830728 |
[p.fullname for p in group.projects],
|
|
Pierre-Yves Chibon |
022a29 |
order
|
|
Pierre-Yves Chibon |
830728 |
)
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
830728 |
|
|
Pierre-Yves Chibon |
302953 |
|
|
Pierre-Yves Chibon |
8b45f6 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
fe5017 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibModeltests)
|
|
Pierre-Yves Chibon |
8b45f6 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|