|
| 1 | +import unittest |
| 2 | +import gitlab |
| 3 | +import os |
| 4 | +import pickle |
| 5 | +import tempfile |
| 6 | +import json |
| 7 | +import unittest |
| 8 | +import requests |
| 9 | +from gitlab import * # noqa |
| 10 | +from gitlab.v4.objects import * # noqa |
| 11 | +from httmock import HTTMock, urlmatch, response # noqa |
| 12 | + |
| 13 | + |
| 14 | +headers = {"content-type": "application/json"} |
| 15 | + |
| 16 | + |
| 17 | +class TestApplicationAppearance(unittest.TestCase): |
| 18 | + def setUp(self): |
| 19 | + self.gl = Gitlab( |
| 20 | + "http://localhost", |
| 21 | + private_token="private_token", |
| 22 | + ssl_verify=True, |
| 23 | + api_version="4", |
| 24 | + ) |
| 25 | + self.title = "GitLab Test Instance" |
| 26 | + self.new_title = "new-title" |
| 27 | + self.description = "gitlab-test.example.com" |
| 28 | + self.new_description = "new-description" |
| 29 | + |
| 30 | + def test_get_update_appearance(self): |
| 31 | + @urlmatch( |
| 32 | + scheme="http", |
| 33 | + netloc="localhost", |
| 34 | + path="/api/v4/application/appearance", |
| 35 | + method="get", |
| 36 | + ) |
| 37 | + def resp_get_appearance(url, request): |
| 38 | + content = """{ |
| 39 | + "title": "%s", |
| 40 | + "description": "%s", |
| 41 | + "logo": "/uploads/-/system/appearance/logo/1/logo.png", |
| 42 | + "header_logo": "/uploads/-/system/appearance/header_logo/1/header.png", |
| 43 | + "favicon": "/uploads/-/system/appearance/favicon/1/favicon.png", |
| 44 | + "new_project_guidelines": "Please read the FAQs for help.", |
| 45 | + "header_message": "", |
| 46 | + "footer_message": "", |
| 47 | + "message_background_color": "#e75e40", |
| 48 | + "message_font_color": "#ffffff", |
| 49 | + "email_header_and_footer_enabled": false}""" % ( |
| 50 | + self.title, |
| 51 | + self.description, |
| 52 | + ) |
| 53 | + content = content.encode("utf-8") |
| 54 | + return response(200, content, headers, None, 25, request) |
| 55 | + |
| 56 | + @urlmatch( |
| 57 | + scheme="http", |
| 58 | + netloc="localhost", |
| 59 | + path="/api/v4/application/appearance", |
| 60 | + method="put", |
| 61 | + ) |
| 62 | + def resp_update_appearance(url, request): |
| 63 | + content = """{ |
| 64 | + "title": "%s", |
| 65 | + "description": "%s", |
| 66 | + "logo": "/uploads/-/system/appearance/logo/1/logo.png", |
| 67 | + "header_logo": "/uploads/-/system/appearance/header_logo/1/header.png", |
| 68 | + "favicon": "/uploads/-/system/appearance/favicon/1/favicon.png", |
| 69 | + "new_project_guidelines": "Please read the FAQs for help.", |
| 70 | + "header_message": "", |
| 71 | + "footer_message": "", |
| 72 | + "message_background_color": "#e75e40", |
| 73 | + "message_font_color": "#ffffff", |
| 74 | + "email_header_and_footer_enabled": false}""" % ( |
| 75 | + self.new_title, |
| 76 | + self.new_description, |
| 77 | + ) |
| 78 | + content = content.encode("utf-8") |
| 79 | + return response(200, content, headers, None, 25, request) |
| 80 | + |
| 81 | + with HTTMock(resp_get_appearance), HTTMock(resp_update_appearance): |
| 82 | + appearance = self.gl.appearance.get() |
| 83 | + self.assertEqual(appearance.title, self.title) |
| 84 | + self.assertEqual(appearance.description, self.description) |
| 85 | + appearance.title = self.new_title |
| 86 | + appearance.description = self.new_description |
| 87 | + appearance.save() |
| 88 | + self.assertEqual(appearance.title, self.new_title) |
| 89 | + self.assertEqual(appearance.description, self.new_description) |
| 90 | + |
| 91 | + def test_update_appearance(self): |
| 92 | + @urlmatch( |
| 93 | + scheme="http", |
| 94 | + netloc="localhost", |
| 95 | + path="/api/v4/application/appearance", |
| 96 | + method="put", |
| 97 | + ) |
| 98 | + def resp_update_appearance(url, request): |
| 99 | + content = """{ |
| 100 | + "title": "%s", |
| 101 | + "description": "%s", |
| 102 | + "logo": "/uploads/-/system/appearance/logo/1/logo.png", |
| 103 | + "header_logo": "/uploads/-/system/appearance/header_logo/1/header.png", |
| 104 | + "favicon": "/uploads/-/system/appearance/favicon/1/favicon.png", |
| 105 | + "new_project_guidelines": "Please read the FAQs for help.", |
| 106 | + "header_message": "", |
| 107 | + "footer_message": "", |
| 108 | + "message_background_color": "#e75e40", |
| 109 | + "message_font_color": "#ffffff", |
| 110 | + "email_header_and_footer_enabled": false}""" % ( |
| 111 | + self.new_title, |
| 112 | + self.new_description, |
| 113 | + ) |
| 114 | + content = content.encode("utf-8") |
| 115 | + return response(200, content, headers, None, 25, request) |
| 116 | + |
| 117 | + with HTTMock(resp_update_appearance): |
| 118 | + resp = self.gl.appearance.update( |
| 119 | + title=self.new_title, description=self.new_description |
| 120 | + ) |
0 commit comments