|
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 |
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',
|
|
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 |
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 |
fe5017 |
msg = 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 |
17d33a |
self.assertEqual(msg, 'Request created')
|
|
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 |
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 |
fe5017 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibModeltests)
|
|
Pierre-Yves Chibon |
8b45f6 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|