|
Pierre-Yves Chibon |
227f4c |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
"""
|
|
Pierre-Yves Chibon |
227f4c |
(c) 2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
Authors:
|
|
Pierre-Yves Chibon |
227f4c |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
"""
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
import datetime
|
|
Pierre-Yves Chibon |
227f4c |
import os
|
|
Pierre-Yves Chibon |
227f4c |
import shutil
|
|
Pierre-Yves Chibon |
227f4c |
import sys
|
|
Pierre-Yves Chibon |
227f4c |
import tempfile
|
|
Pierre-Yves Chibon |
227f4c |
import time
|
|
Pierre-Yves Chibon |
227f4c |
import unittest
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
import pygit2
|
|
Pierre-Yves Chibon |
227f4c |
import six
|
|
Pierre-Yves Chibon |
227f4c |
from mock import patch, MagicMock, ANY, call
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
227f4c |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
import pagure.lib.git
|
|
Pierre-Yves Chibon |
227f4c |
import tests
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
from pagure.lib.repo import PagureRepo
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
class PagureLibGitMirrorProjecttests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
227f4c |
""" Tests for pagure.lib.git.mirror_pull_project """
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
maxDiff = None
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
def setUp(self):
|
|
Pierre-Yves Chibon |
227f4c |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
227f4c |
super(PagureLibGitMirrorProjecttests, self).setUp()
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
227f4c |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
227f4c |
os.path.join(self.path, "repos"),
|
|
Pierre-Yves Chibon |
227f4c |
bare=True
|
|
Pierre-Yves Chibon |
227f4c |
)
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
# Make the test project mirrored from elsewhere
|
|
Pierre-Yves Chibon |
227f4c |
self.project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
227f4c |
self.session, 'test')
|
|
Pierre-Yves Chibon |
227f4c |
self.project.mirrored_from = "https://example.com/foo/bar.git"
|
|
Pierre-Yves Chibon |
227f4c |
self.session.add(self.project)
|
|
Pierre-Yves Chibon |
227f4c |
self.session.commit()
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
@patch('subprocess.Popen')
|
|
Pierre-Yves Chibon |
227f4c |
@patch('subprocess.check_output')
|
|
Pierre-Yves Chibon |
227f4c |
def test_mirror_pull_project(self, ck_out_mock, popen_mock):
|
|
Pierre-Yves Chibon |
227f4c |
""" Test the mirror_pull_project method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
tmp = MagicMock()
|
|
Pierre-Yves Chibon |
227f4c |
tmp.communicate.return_value = ('', '')
|
|
Pierre-Yves Chibon |
227f4c |
popen_mock.return_value = tmp
|
|
Pierre-Yves Chibon |
227f4c |
ck_out_mock.return_value = "all good"
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
output = pagure.lib.git.mirror_pull_project(
|
|
Pierre-Yves Chibon |
227f4c |
self.session,
|
|
Pierre-Yves Chibon |
227f4c |
self.project
|
|
Pierre-Yves Chibon |
227f4c |
)
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
227f4c |
popen_mock.call_count,
|
|
Pierre-Yves Chibon |
227f4c |
2
|
|
Pierre-Yves Chibon |
227f4c |
)
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
calls = [
|
|
Pierre-Yves Chibon |
227f4c |
call(
|
|
Pierre-Yves Chibon |
227f4c |
[
|
|
Pierre-Yves Chibon |
227f4c |
u'git', u'clone', u'--mirror',
|
|
Pierre-Yves Chibon |
227f4c |
u'https://example.com/foo/bar.git', u'.'
|
|
Pierre-Yves Chibon |
227f4c |
],
|
|
Pierre-Yves Chibon |
227f4c |
cwd=ANY,
|
|
Pierre-Yves Chibon |
227f4c |
stderr=-1,
|
|
Pierre-Yves Chibon |
227f4c |
stdin=None,
|
|
Pierre-Yves Chibon |
227f4c |
stdout=-1
|
|
Pierre-Yves Chibon |
227f4c |
),
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
call(
|
|
Pierre-Yves Chibon |
227f4c |
[u'git', u'remote', u'add', u'local', ANY],
|
|
Pierre-Yves Chibon |
227f4c |
cwd=ANY,
|
|
Pierre-Yves Chibon |
227f4c |
stderr=-1,
|
|
Pierre-Yves Chibon |
227f4c |
stdin=None,
|
|
Pierre-Yves Chibon |
227f4c |
stdout=-1
|
|
Pierre-Yves Chibon |
227f4c |
),
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
ANY,
|
|
Pierre-Yves Chibon |
227f4c |
]
|
|
Pierre-Yves Chibon |
227f4c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
227f4c |
popen_mock.mock_calls,
|
|
Pierre-Yves Chibon |
227f4c |
calls
|
|
Pierre-Yves Chibon |
227f4c |
)
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
ck_out_mock.assert_called_once_with(
|
|
Pierre-Yves Chibon |
227f4c |
[u'git', u'push', u'local', u'--mirror'],
|
|
Pierre-Yves Chibon |
227f4c |
cwd=ANY,
|
|
Pierre-Yves Chibon |
227f4c |
env=ANY,
|
|
Pierre-Yves Chibon |
227f4c |
stderr=-2
|
|
Pierre-Yves Chibon |
227f4c |
)
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
|
|
Pierre-Yves Chibon |
227f4c |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
227f4c |
unittest.main(verbosity=2)
|