1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
)
|