|
Pierre-Yves Chibon |
c43375 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
"""
|
|
Pierre-Yves Chibon |
c43375 |
(c) 2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
Authors:
|
|
Pierre-Yves Chibon |
c43375 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
"""
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
import unittest
|
|
Pierre-Yves Chibon |
c43375 |
import sys
|
|
Pierre-Yves Chibon |
c43375 |
import os
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
import pygit2
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
c43375 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
import pagure
|
|
Pierre-Yves Chibon |
c43375 |
import pagure.lib
|
|
Pierre-Yves Chibon |
c43375 |
import tests
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
class ViewCommitFlagtests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
c43375 |
""" Tests for the UI related to commit flags """
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
def setUp(self):
|
|
Pierre-Yves Chibon |
c43375 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
c43375 |
super(ViewCommitFlagtests, self).setUp()
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
c43375 |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
c43375 |
pagure.ui.SESSION = self.session
|
|
Pierre-Yves Chibon |
c43375 |
pagure.ui.app.SESSION = self.session
|
|
Pierre-Yves Chibon |
c43375 |
pagure.ui.filters.SESSION = self.session
|
|
Pierre-Yves Chibon |
c43375 |
pagure.ui.repo.SESSION = self.session
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
c43375 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
# Add a README to the git repo - First commit
|
|
Pierre-Yves Chibon |
c43375 |
tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
|
|
Pierre-Yves Chibon |
c43375 |
repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
|
|
Pierre-Yves Chibon |
c43375 |
self.commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
def test_view_commit_no_flag(self):
|
|
Pierre-Yves Chibon |
c43375 |
""" Test the view_commit endpoint. """
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
# View first commit
|
|
Pierre-Yves Chibon |
c43375 |
output = self.app.get('/test/c/%s' % self.commit.oid.hex)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'',
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Merged by Alice Author\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Committed by Cecil Committer\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn('''<section class="list-group" id="flag_list"></section>
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
''', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
def test_view_commit_pending_flag(self):
|
|
Pierre-Yves Chibon |
c43375 |
""" Test the view_commit endpoint with a pending flag. """
|
|
Pierre-Yves Chibon |
c43375 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
msg = pagure.lib.add_commit_flag(
|
|
Pierre-Yves Chibon |
c43375 |
session=self.session,
|
|
Pierre-Yves Chibon |
c43375 |
repo=repo,
|
|
Pierre-Yves Chibon |
c43375 |
commit_hash=self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
username='simple-koji-ci',
|
|
Pierre-Yves Chibon |
c43375 |
status='pending',
|
|
Pierre-Yves Chibon |
c43375 |
percent=None,
|
|
Pierre-Yves Chibon |
c43375 |
comment='Build is running',
|
|
Pierre-Yves Chibon |
c43375 |
url='https://koji.fp.o/koji...',
|
|
Pierre-Yves Chibon |
c43375 |
uid='uid',
|
|
Pierre-Yves Chibon |
c43375 |
user='foo',
|
|
Pierre-Yves Chibon |
c43375 |
token='aaabbbcccddd'
|
|
Pierre-Yves Chibon |
c43375 |
)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(msg, ('Flag added', 'uid'))
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
# View first commit
|
|
Pierre-Yves Chibon |
c43375 |
output = self.app.get('/test/c/%s' % self.commit.oid.hex)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'',
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Merged by Alice Author\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Committed by Cecil Committer\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'simple-koji-ci\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'pending'
|
|
Pierre-Yves Chibon |
c43375 |
'\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'Build is running', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
def test_view_commit_success_flag(self):
|
|
Pierre-Yves Chibon |
c43375 |
""" Test the view_commit endpoint with a successful flag. """
|
|
Pierre-Yves Chibon |
c43375 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
msg = pagure.lib.add_commit_flag(
|
|
Pierre-Yves Chibon |
c43375 |
session=self.session,
|
|
Pierre-Yves Chibon |
c43375 |
repo=repo,
|
|
Pierre-Yves Chibon |
c43375 |
commit_hash=self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
username='simple-koji-ci',
|
|
Pierre-Yves Chibon |
c43375 |
status='success',
|
|
Pierre-Yves Chibon |
c43375 |
percent=100,
|
|
Pierre-Yves Chibon |
c43375 |
comment='Build passed',
|
|
Pierre-Yves Chibon |
c43375 |
url='https://koji.fp.o/koji...',
|
|
Pierre-Yves Chibon |
c43375 |
uid='uid',
|
|
Pierre-Yves Chibon |
c43375 |
user='foo',
|
|
Pierre-Yves Chibon |
c43375 |
token='aaabbbcccddd'
|
|
Pierre-Yves Chibon |
c43375 |
)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(msg, ('Flag added', 'uid'))
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
# View first commit
|
|
Pierre-Yves Chibon |
c43375 |
output = self.app.get('/test/c/%s' % self.commit.oid.hex)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'',
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Merged by Alice Author\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Committed by Cecil Committer\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'simple-koji-ci\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'success (100%)'
|
|
Pierre-Yves Chibon |
c43375 |
'\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'Build passed', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
def test_view_commit_error_flag(self):
|
|
Pierre-Yves Chibon |
c43375 |
""" Test the view_commit endpoint with a error flag. """
|
|
Pierre-Yves Chibon |
c43375 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
msg = pagure.lib.add_commit_flag(
|
|
Pierre-Yves Chibon |
c43375 |
session=self.session,
|
|
Pierre-Yves Chibon |
c43375 |
repo=repo,
|
|
Pierre-Yves Chibon |
c43375 |
commit_hash=self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
username='simple-koji-ci',
|
|
Pierre-Yves Chibon |
c43375 |
status='error',
|
|
Pierre-Yves Chibon |
c43375 |
percent=None,
|
|
Pierre-Yves Chibon |
c43375 |
comment='Build errored',
|
|
Pierre-Yves Chibon |
c43375 |
url='https://koji.fp.o/koji...',
|
|
Pierre-Yves Chibon |
c43375 |
uid='uid',
|
|
Pierre-Yves Chibon |
c43375 |
user='foo',
|
|
Pierre-Yves Chibon |
c43375 |
token='aaabbbcccddd'
|
|
Pierre-Yves Chibon |
c43375 |
)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(msg, ('Flag added', 'uid'))
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
# View first commit
|
|
Pierre-Yves Chibon |
c43375 |
output = self.app.get('/test/c/%s' % self.commit.oid.hex)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'',
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Merged by Alice Author\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Committed by Cecil Committer\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'simple-koji-ci\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'error'
|
|
Pierre-Yves Chibon |
c43375 |
'\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'Build errored', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
def test_view_commit_failure_flag(self):
|
|
Pierre-Yves Chibon |
c43375 |
""" Test the view_commit endpoint with a failure flag. """
|
|
Pierre-Yves Chibon |
c43375 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
msg = pagure.lib.add_commit_flag(
|
|
Pierre-Yves Chibon |
c43375 |
session=self.session,
|
|
Pierre-Yves Chibon |
c43375 |
repo=repo,
|
|
Pierre-Yves Chibon |
c43375 |
commit_hash=self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
username='simple-koji-ci',
|
|
Pierre-Yves Chibon |
c43375 |
status='failure',
|
|
Pierre-Yves Chibon |
c43375 |
percent=None,
|
|
Pierre-Yves Chibon |
c43375 |
comment='Build failed',
|
|
Pierre-Yves Chibon |
c43375 |
url='https://koji.fp.o/koji...',
|
|
Pierre-Yves Chibon |
c43375 |
uid='uid',
|
|
Pierre-Yves Chibon |
c43375 |
user='foo',
|
|
Pierre-Yves Chibon |
c43375 |
token='aaabbbcccddd'
|
|
Pierre-Yves Chibon |
c43375 |
)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(msg, ('Flag added', 'uid'))
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
# View first commit
|
|
Pierre-Yves Chibon |
c43375 |
output = self.app.get('/test/c/%s' % self.commit.oid.hex)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'',
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Merged by Alice Author\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Committed by Cecil Committer\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'simple-koji-ci\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'failure'
|
|
Pierre-Yves Chibon |
c43375 |
'\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'Build failed', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
def test_view_commit_canceled_flag(self):
|
|
Pierre-Yves Chibon |
c43375 |
""" Test the view_commit endpoint with a canceled flag. """
|
|
Pierre-Yves Chibon |
c43375 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
msg = pagure.lib.add_commit_flag(
|
|
Pierre-Yves Chibon |
c43375 |
session=self.session,
|
|
Pierre-Yves Chibon |
c43375 |
repo=repo,
|
|
Pierre-Yves Chibon |
c43375 |
commit_hash=self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
username='simple-koji-ci',
|
|
Pierre-Yves Chibon |
c43375 |
status='canceled',
|
|
Pierre-Yves Chibon |
c43375 |
percent=None,
|
|
Pierre-Yves Chibon |
c43375 |
comment='Build canceled',
|
|
Pierre-Yves Chibon |
c43375 |
url='https://koji.fp.o/koji...',
|
|
Pierre-Yves Chibon |
c43375 |
uid='uid',
|
|
Pierre-Yves Chibon |
c43375 |
user='foo',
|
|
Pierre-Yves Chibon |
c43375 |
token='aaabbbcccddd'
|
|
Pierre-Yves Chibon |
c43375 |
)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(msg, ('Flag added', 'uid'))
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
# View first commit
|
|
Pierre-Yves Chibon |
c43375 |
output = self.app.get('/test/c/%s' % self.commit.oid.hex)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'',
|
|
Pierre-Yves Chibon |
c43375 |
output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Merged by Alice Author\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(' Committed by Cecil Committer\n', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'simple-koji-ci\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'\n '
|
|
Pierre-Yves Chibon |
c43375 |
'canceled'
|
|
Pierre-Yves Chibon |
c43375 |
'\n ', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c43375 |
'Build canceled', output.data)
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
|
|
Pierre-Yves Chibon |
c43375 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
c43375 |
unittest.main(verbosity=2)
|