diff options
| author | Nejc Habjan <hab.nejc@gmail.com> | 2020-04-17 02:26:28 +0200 |
|---|---|---|
| committer | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-22 20:09:52 +0200 |
| commit | 76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7 (patch) | |
| tree | 4dbe6ae57c4f03e1351f7a49e590cbbc6d31121a /gitlab/tests/objects/test_application.py | |
| parent | 11383e70f74c70e6fe8a56f18b5b170db982f402 (diff) | |
| download | gitlab-76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7.tar.gz | |
refactor: split unit tests by GitLab API resources
Diffstat (limited to 'gitlab/tests/objects/test_application.py')
| -rw-r--r-- | gitlab/tests/objects/test_application.py | 226 |
1 files changed, 107 insertions, 119 deletions
diff --git a/gitlab/tests/objects/test_application.py b/gitlab/tests/objects/test_application.py index a10691b..356f0d3 100644 --- a/gitlab/tests/objects/test_application.py +++ b/gitlab/tests/objects/test_application.py @@ -1,120 +1,108 @@ -import unittest -import gitlab -import os -import pickle -import tempfile +""" +GitLab API: https://docs.gitlab.com/ce/api/applications.html +""" + 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() - assert appearance.title == self.title - assert appearance.description == self.description - appearance.title = self.new_title - appearance.description = self.new_description - appearance.save() - assert appearance.title == self.new_title - assert 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 - ) + +from httmock import urlmatch, response, with_httmock # noqa + +from .mocks import headers + + +title = "GitLab Test Instance" +description = "gitlab-test.example.com" +new_title = "new-title" +new_description = "new-description" + + +@urlmatch( + scheme="http", netloc="localhost", path="/api/v4/applications", method="post", +) +def resp_application_create(url, request): + content = '{"name": "test_app", "redirect_uri": "http://localhost:8080", "scopes": ["api", "email"]}' + json_content = json.loads(content) + return response(200, json_content, headers, None, 5, request) + + +@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}""" % ( + title, + 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}""" % ( + new_title, + new_description, + ) + content = content.encode("utf-8") + return response(200, content, headers, None, 25, request) + + +@with_httmock(resp_application_create) +def test_create_application(gl): + application = gl.applications.create( + { + "name": "test_app", + "redirect_uri": "http://localhost:8080", + "scopes": ["api", "email"], + "confidential": False, + } + ) + assert application.name == "test_app" + assert application.redirect_uri == "http://localhost:8080" + assert application.scopes == ["api", "email"] + + +@with_httmock(resp_get_appearance, resp_update_appearance) +def test_get_update_appearance(gl): + appearance = gl.appearance.get() + assert appearance.title == title + assert appearance.description == description + appearance.title = new_title + appearance.description = new_description + appearance.save() + assert appearance.title == new_title + assert appearance.description == new_description + + +@with_httmock(resp_update_appearance) +def test_update_application_appearance(gl): + resp = gl.appearance.update(title=new_title, description=new_description) |
