mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-22 02:11:26 -07:00
Added module for creating protected branches (#2781)
* Added module for creating protected branches * Applied some changes due to comments and added a test that currently fails * Changing no_access to nobody due to comment on PR * Changing the description to clarify it a bit more * Added working tests for module 'gitlab_protected_branch' * Fixing lint issues * Added doc that minimum of v2.3.0 is needed to work correctly * Fixed the requirements notation * Check the version of the module * Hopefully fixed the tests by skipping it when lower version of 2.3.0 is installed * Fix lint issues * Applying changes due to comments in PR * Remove commented code * Removing the trailing dot ... Co-authored-by: jenkins-x-bot <jenkins-x@googlegroups.com> Co-authored-by: Werner Dijkerman <iam@werner-dijkerman.nl>
This commit is contained in:
parent
27ba98a68e
commit
7734430f23
4 changed files with 319 additions and 2 deletions
|
@ -13,7 +13,7 @@ from httmock import urlmatch # noqa
|
|||
|
||||
from ansible_collections.community.general.tests.unit.compat import unittest
|
||||
|
||||
from gitlab import Gitlab
|
||||
import gitlab
|
||||
|
||||
|
||||
class FakeAnsibleModule(object):
|
||||
|
@ -33,7 +33,7 @@ class GitlabModuleTestCase(unittest.TestCase):
|
|||
|
||||
self.mock_module = FakeAnsibleModule()
|
||||
|
||||
self.gitlab_instance = Gitlab("http://localhost", private_token="private_token", api_version=4)
|
||||
self.gitlab_instance = gitlab.Gitlab("http://localhost", private_token="private_token", api_version=4)
|
||||
|
||||
|
||||
# Python 2.7+ is needed for python-gitlab
|
||||
|
@ -45,6 +45,14 @@ def python_version_match_requirement():
|
|||
return sys.version_info >= GITLAB_MINIMUM_PYTHON_VERSION
|
||||
|
||||
|
||||
def python_gitlab_module_version():
|
||||
return gitlab.__version__
|
||||
|
||||
|
||||
def python_gitlab_version_match_requirement():
|
||||
return "2.3.0"
|
||||
|
||||
|
||||
# Skip unittest test case if python version don't match requirement
|
||||
def unitest_python_version_check_requirement(unittest_testcase):
|
||||
if not python_version_match_requirement():
|
||||
|
@ -467,6 +475,32 @@ def resp_delete_project(url, request):
|
|||
return response(204, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/protected_branches/master", method="get")
|
||||
def resp_get_protected_branch(url, request):
|
||||
headers = {'content-type': 'application/json'}
|
||||
content = ('{"id": 1, "name": "master", "push_access_levels": [{"access_level": 40, "access_level_description": "Maintainers"}],'
|
||||
'"merge_access_levels": [{"access_level": 40, "access_level_description": "Maintainers"}],'
|
||||
'"allow_force_push":false, "code_owner_approval_required": false}')
|
||||
content = content.encode("utf-8")
|
||||
return response(200, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/protected_branches/master", method="get")
|
||||
def resp_get_protected_branch_not_exist(url, request):
|
||||
headers = {'content-type': 'application/json'}
|
||||
content = ('')
|
||||
content = content.encode("utf-8")
|
||||
return response(404, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1/protected_branches/master", method="delete")
|
||||
def resp_delete_protected_branch(url, request):
|
||||
headers = {'content-type': 'application/json'}
|
||||
content = ('')
|
||||
content = content.encode("utf-8")
|
||||
return response(204, content, headers, None, 5, request)
|
||||
|
||||
|
||||
'''
|
||||
HOOK API
|
||||
'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue