Verified Commit a866d4e9 authored by Peter Stanko's avatar Peter Stanko
Browse files

Added test for enable to project

parent f805650e
Pipeline #31277 passed with stage
in 6 minutes and 44 seconds
from typing import Union, List
from typing import List
from flask import request, jsonify
from flask import jsonify, request
from flask_jwt_extended import jwt_required
from flask_restplus import Namespace
from gitlab.v4 import objects
......@@ -77,7 +77,7 @@ class GitlabProjects(CustomResource):
args['membership'] = args.get('membership') or True
args['all'] = args.get('all') or True
projects: List[objects.Project] = self.facades.gitlab.list_projects(**args)
return jsonify([proj.attributes for proj in projects])
return jsonify(_extract(projects))
def _get_project_name() -> str:
......@@ -87,6 +87,12 @@ def _get_project_name() -> str:
return pname
def _extract(obj):
if isinstance(obj, list):
return [_extract(item) for item in obj]
return obj.attributes
@gitlab_namespace.route('/project')
class GitlabProjects(CustomResource):
@jwt_required
......@@ -95,7 +101,7 @@ class GitlabProjects(CustomResource):
self.facades.gitlab.check_gl_enabled()
pname = _get_project_name()
project: objects.Project = self.facades.gitlab.get_project(project_name=pname)
return project.attributes
return _extract(project)
@gitlab_namespace.route('/project/members')
......@@ -105,13 +111,15 @@ class GitlabProjectMembers(CustomResource):
def get(self):
self.facades.gitlab.check_gl_enabled()
pname = _get_project_name()
return self.facades.gitlab.list_members(project_name=pname)
members = self.facades.gitlab.list_members(project_name=pname)
return jsonify(_extract(members))
@jwt_required
def post(self, pname: str):
def post(self):
self.facades.gitlab.check_gl_enabled()
pname = _get_project_name()
result = self.facades.gitlab.add_member_to_project(project_name=pname)
return result
return jsonify(_extract(result))
@gitlab_namespace.route('/service_token')
......
import logging
from urllib.parse import urlencode
import gitlab
import pytest
......@@ -196,8 +195,7 @@ def test_get_gitlab_project(client, gl_api_url, data_gl_projects, gl_cookies, gl
pname: str = project['path_with_namespace']
namespace = pname.replace('/', '%2F')
responses.add(responses.GET, f"{gl_api_url}/user", json=gl_user, status=200)
responses.add(responses.GET, f"{gl_api_url}/projects/{namespace}",
json=project, status=200)
responses.add(responses.GET, f"{gl_api_url}/projects/{namespace}", json=project, status=200)
# 'https://gitlab.local/api/v4/user'
response = rest_tools.make_request(client, f'/gitlab/project?project={pname}',
cookies=gl_cookies)
......@@ -208,6 +206,22 @@ def test_get_gitlab_project(client, gl_api_url, data_gl_projects, gl_cookies, gl
assert res_proj == project
@pytest.mark.gitlab
@responses.activate
def test_enable_member_for_gl_project(client, gl_api_url, data_gl_projects, gl_cookies, gl_user):
project = data_gl_projects[0]
pname: str = project['path_with_namespace']
namespace = pname.replace('/', '%2F')
responses.add(responses.GET, f"{gl_api_url}/user", json=gl_user, status=200)
responses.add(responses.GET, f"{gl_api_url}/projects/{namespace}", json=project, status=200)
responses.add(responses.POST, f"{gl_api_url}/projects/{project['id']}/members",
json=project, status=200)
# 'https://gitlab.local/api/v4/user'
response = rest_tools.make_request(client, f'/gitlab/project/members?project={pname}',
method='post', cookies=gl_cookies)
assert_response(response)
@pytest.mark.gitlab
@responses.activate
def test_set_gitlab_service_cookies(client, gl_api_url, gl_user, gl_cookies):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment