|
Pierre-Yves Chibon |
8b45f6 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
"""
|
|
Pierre-Yves Chibon |
8b45f6 |
(c) 2015 - 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 shutil
|
|
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 |
8b45f6 |
import progit.lib
|
|
Pierre-Yves Chibon |
8b45f6 |
import tests
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
class ProgitLibModeltests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
8b45f6 |
""" Tests for progit.lib.model """
|
|
Pierre-Yves Chibon |
8b45f6 |
|
|
Pierre-Yves Chibon |
8b45f6 |
def test_user__repr__(self):
|
|
Pierre-Yves Chibon |
8b45f6 |
""" Test the User.__repr__ function of progit.lib.model. """
|
|
Pierre-Yves Chibon |
8b45f6 |
item = progit.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 |
c6bb48 |
@patch('progit.lib.git.update_git_ticket')
|
|
Pierre-Yves Chibon |
c6bb48 |
@patch('progit.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
c6bb48 |
def test_issue__repr__(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
c6bb48 |
""" Test the Issue.__repr__ function of progit.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 |
c6bb48 |
repo = progit.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c6bb48 |
|
|
Pierre-Yves Chibon |
c6bb48 |
# Create an issue
|
|
Pierre-Yves Chibon |
c6bb48 |
msg = progit.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 |
c6bb48 |
self.assertEqual(msg, 'Issue created')
|
|
Pierre-Yves Chibon |
c6bb48 |
|
|
Pierre-Yves Chibon |
c6bb48 |
issues = progit.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 |
17d33a |
@patch('progit.lib.git.update_git_ticket')
|
|
Pierre-Yves Chibon |
17d33a |
@patch('progit.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
17d33a |
def test_pullrequest__repr__(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
17d33a |
""" Test the PullRequest.__repr__ function of progit.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 |
17d33a |
item = progit.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',
|
|
Pierre-Yves Chibon |
17d33a |
parent_id=1,
|
|
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 |
17d33a |
repo = progit.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
17d33a |
forked_repo = progit.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 |
17d33a |
msg = progit.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 |
17d33a |
user='pingou'
|
|
Pierre-Yves Chibon |
17d33a |
)
|
|
Pierre-Yves Chibon |
17d33a |
self.assertEqual(msg, 'Request created')
|
|
Pierre-Yves Chibon |
17d33a |
|
|
Pierre-Yves Chibon |
17d33a |
request = progit.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 |
e1c99a |
def test_progitgroup__repr__(self):
|
|
Pierre-Yves Chibon |
e1c99a |
""" Test the ProgitGroup.__repr__ function of progit.lib.model. """
|
|
Pierre-Yves Chibon |
e1c99a |
item = progit.lib.model.ProgitGroup(
|
|
Pierre-Yves Chibon |
e1c99a |
group_name='admin',
|
|
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 |
8b45f6 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
8b45f6 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitLibModeltests)
|
|
Pierre-Yves Chibon |
8b45f6 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|