diff options
author | Max Wittig <max.wittig@siemens.com> | 2020-01-21 18:46:27 +0100 |
---|---|---|
committer | Max Wittig <max.wittig95@gmail.com> | 2020-01-22 21:19:21 +0100 |
commit | 4c4ac5ca1e5cabc4ea4b12734a7b091bc4c224b5 (patch) | |
tree | 76f64ea79d1349b904c3eb1e16ff92b770c7ae74 | |
parent | afdc43f401e20550ed181d4b87829739791d2ee3 (diff) | |
download | gitlab-feat/appearance.tar.gz |
feat: add appearance APIfeat/appearance
-rw-r--r-- | docs/api-objects.rst | 1 | ||||
-rw-r--r-- | docs/gl_objects/appearance.rst | 26 | ||||
-rw-r--r-- | gitlab/__init__.py | 1 | ||||
-rw-r--r-- | gitlab/tests/objects/test_application.py | 120 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 45 |
5 files changed, 193 insertions, 0 deletions
diff --git a/docs/api-objects.rst b/docs/api-objects.rst index 4767c48..569435c 100644 --- a/docs/api-objects.rst +++ b/docs/api-objects.rst @@ -6,6 +6,7 @@ API examples :maxdepth: 1 gl_objects/access_requests + gl_objects/appearance gl_objects/emojis gl_objects/badges gl_objects/branches diff --git a/docs/gl_objects/appearance.rst b/docs/gl_objects/appearance.rst new file mode 100644 index 0000000..0c05268 --- /dev/null +++ b/docs/gl_objects/appearance.rst @@ -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() diff --git a/gitlab/__init__.py b/gitlab/__init__.py index b377023..9cb027b 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -129,6 +129,7 @@ class Gitlab(object): 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) diff --git a/gitlab/tests/objects/test_application.py b/gitlab/tests/objects/test_application.py new file mode 100644 index 0000000..50ca1ad --- /dev/null +++ b/gitlab/tests/objects/test_application.py @@ -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 + ) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 88ede56..c38a4bf 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -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 |