FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add appearance API by max-wittig · Pull Request #996 · python-gitlab/python-gitlab · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions docs/api-objects.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ API examples
:maxdepth: 1

gl_objects/access_requests
gl_objects/appearance
gl_objects/emojis
gl_objects/badges
gl_objects/branches
Expand Down
26 changes: 26 additions & 0 deletions docs/gl_objects/appearance.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
##########
Appearance
##########

Reference
---------

* v4 API:

+ :class:`gitlab.v4.objects.ApplicationAppearance`
+ :class:`gitlab.v4.objects.ApplicationAppearanceManager`
+ :attr:`gitlab.Gitlab.appearance`

* GitLab API: https://docs.gitlab.com/ce/api/appearance.html

Examples
--------

Get the appearance::

appearance = gl.appearance.get()

Update the appearance::

appearance.title = "Test"
appearance.save()
1 change: 1 addition & 0 deletions gitlab/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def __init__(
self.projects = objects.ProjectManager(self)
self.runners = objects.RunnerManager(self)
self.settings = objects.ApplicationSettingsManager(self)
self.appearance = objects.ApplicationAppearanceManager(self)
self.sidekiq = objects.SidekiqManager(self)
self.snippets = objects.SnippetManager(self)
self.users = objects.UserManager(self)
Expand Down
120 changes: 120 additions & 0 deletions gitlab/tests/objects/test_application.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import unittest
import gitlab
import os
import pickle
import tempfile
import json
import unittest
import requests
from gitlab import * # noqa
from gitlab.v4.objects import * # noqa
from httmock import HTTMock, urlmatch, response # noqa


headers = {"content-type": "application/json"}


class TestApplicationAppearance(unittest.TestCase):
def setUp(self):
self.gl = Gitlab(
"http://localhost",
private_token="private_token",
ssl_verify=True,
api_version="4",
)
self.title = "GitLab Test Instance"
self.new_title = "new-title"
self.description = "gitlab-test.example.com"
self.new_description = "new-description"

def test_get_update_appearance(self):
@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/application/appearance",
method="get",
)
def resp_get_appearance(url, request):
content = """{
"title": "%s",
"description": "%s",
"logo": "/uploads/-/system/appearance/logo/1/logo.png",
"header_logo": "/uploads/-/system/appearance/header_logo/1/header.png",
"favicon": "/uploads/-/system/appearance/favicon/1/favicon.png",
"new_project_guidelines": "Please read the FAQs for help.",
"header_message": "",
"footer_message": "",
"message_background_color": "#e75e40",
"message_font_color": "#ffffff",
"email_header_and_footer_enabled": false}""" % (
self.title,
self.description,
)
content = content.encode("utf-8")
return response(200, content, headers, None, 25, request)

@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/application/appearance",
method="put",
)
def resp_update_appearance(url, request):
content = """{
"title": "%s",
"description": "%s",
"logo": "/uploads/-/system/appearance/logo/1/logo.png",
"header_logo": "/uploads/-/system/appearance/header_logo/1/header.png",
"favicon": "/uploads/-/system/appearance/favicon/1/favicon.png",
"new_project_guidelines": "Please read the FAQs for help.",
"header_message": "",
"footer_message": "",
"message_background_color": "#e75e40",
"message_font_color": "#ffffff",
"email_header_and_footer_enabled": false}""" % (
self.new_title,
self.new_description,
)
content = content.encode("utf-8")
return response(200, content, headers, None, 25, request)

with HTTMock(resp_get_appearance), HTTMock(resp_update_appearance):
appearance = self.gl.appearance.get()
self.assertEqual(appearance.title, self.title)
self.assertEqual(appearance.description, self.description)
appearance.title = self.new_title
appearance.description = self.new_description
appearance.save()
self.assertEqual(appearance.title, self.new_title)
self.assertEqual(appearance.description, self.new_description)

def test_update_appearance(self):
@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/application/appearance",
method="put",
)
def resp_update_appearance(url, request):
content = """{
"title": "%s",
"description": "%s",
"logo": "/uploads/-/system/appearance/logo/1/logo.png",
"header_logo": "/uploads/-/system/appearance/header_logo/1/header.png",
"favicon": "/uploads/-/system/appearance/favicon/1/favicon.png",
"new_project_guidelines": "Please read the FAQs for help.",
"header_message": "",
"footer_message": "",
"message_background_color": "#e75e40",
"message_font_color": "#ffffff",
"email_header_and_footer_enabled": false}""" % (
self.new_title,
self.new_description,
)
content = content.encode("utf-8")
return response(200, content, headers, None, 25, request)

with HTTMock(resp_update_appearance):
resp = self.gl.appearance.update(
title=self.new_title, description=self.new_description
)
45 changes: 45 additions & 0 deletions gitlab/v4/objects.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,51 @@ class CurrentUserManager(GetWithoutIdMixin, RESTManager):
_obj_cls = CurrentUser


class ApplicationAppearance(SaveMixin, RESTObject):
_id_attr = None


class ApplicationAppearanceManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
_path = "/application/appearance"
_obj_cls = ApplicationAppearance
_update_attrs = (
tuple(),
(
"title",
"description",
"logo",
"header_logo",
"favicon",
"new_project_guidelines",
"header_message",
"footer_message",
"message_background_color",
"message_font_color",
"email_header_and_footer_enabled",
),
)

@exc.on_http_error(exc.GitlabUpdateError)
def update(self, id=None, new_data=None, **kwargs):
"""Update an object on the server.

Args:
id: ID of the object to update (can be None if not required)
new_data: the update data for the object
**kwargs: Extra options to send to the server (e.g. sudo)

Returns:
dict: The new object data (*not* a RESTObject)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server cannot perform the request
"""
new_data = new_data or {}
data = new_data.copy()
super(ApplicationAppearanceManager, self).update(id, data, **kwargs)


class ApplicationSettings(SaveMixin, RESTObject):
_id_attr = None

Expand Down

Back | FazBrowse Home | New Git URL