From 11383e70f74c70e6fe8a56f18b5b170db982f402 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Thu, 9 Apr 2020 00:13:36 +0200 Subject: chore: run unittest2pytest on all unit tests --- gitlab/tests/objects/test_application.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gitlab/tests/objects/test_application.py') diff --git a/gitlab/tests/objects/test_application.py b/gitlab/tests/objects/test_application.py index 50ca1ad..a10691b 100644 --- a/gitlab/tests/objects/test_application.py +++ b/gitlab/tests/objects/test_application.py @@ -80,13 +80,13 @@ class TestApplicationAppearance(unittest.TestCase): 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) + assert appearance.title == self.title + assert 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) + assert appearance.title == self.new_title + assert appearance.description == self.new_description def test_update_appearance(self): @urlmatch( -- cgit v1.2.1 From 76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Fri, 17 Apr 2020 02:26:28 +0200 Subject: refactor: split unit tests by GitLab API resources --- gitlab/tests/objects/test_application.py | 226 +++++++++++++++---------------- 1 file changed, 107 insertions(+), 119 deletions(-) (limited to 'gitlab/tests/objects/test_application.py') 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) -- cgit v1.2.1 From 204782a117f77f367dee87aa2c70822587829147 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sun, 23 Aug 2020 21:16:20 +0200 Subject: refactor: rewrite unit tests for objects with responses --- gitlab/tests/objects/test_application.py | 108 ------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 gitlab/tests/objects/test_application.py (limited to 'gitlab/tests/objects/test_application.py') diff --git a/gitlab/tests/objects/test_application.py b/gitlab/tests/objects/test_application.py deleted file mode 100644 index 356f0d3..0000000 --- a/gitlab/tests/objects/test_application.py +++ /dev/null @@ -1,108 +0,0 @@ -""" -GitLab API: https://docs.gitlab.com/ce/api/applications.html -""" - -import json - -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) -- cgit v1.2.1