diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2021-11-28 00:50:49 +0100 |
---|---|---|
committer | John Villalovos <john@sodarock.com> | 2022-05-29 16:56:36 -0700 |
commit | df072e130aa145a368bbdd10be98208a25100f89 (patch) | |
tree | d52fc1a500bc510a76bea8dba4d7b304a66b83df /tests/unit/test_gitlab.py | |
parent | c51b538caae0a94d936d94d6da60c362492f9403 (diff) | |
download | gitlab-df072e130aa145a368bbdd10be98208a25100f89.tar.gz |
test(gitlab): increase unit test coverage
Diffstat (limited to 'tests/unit/test_gitlab.py')
-rw-r--r-- | tests/unit/test_gitlab.py | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/tests/unit/test_gitlab.py b/tests/unit/test_gitlab.py index 44abfc1..070f215 100644 --- a/tests/unit/test_gitlab.py +++ b/tests/unit/test_gitlab.py @@ -24,6 +24,7 @@ import pytest import responses import gitlab +from tests.unit import helpers localhost = "http://localhost" token = "abc123" @@ -58,7 +59,7 @@ def resp_page_1(): "headers": headers, "content_type": "application/json", "status": 200, - "match": [responses.matchers.query_param_matcher({})], + "match": helpers.MATCH_EMPTY_QUERY_PARAMS, } @@ -84,6 +85,64 @@ def resp_page_2(): } +def test_gitlab_init_with_valid_api_version(): + gl = gitlab.Gitlab(api_version="4") + assert gl.api_version == "4" + + +def test_gitlab_init_with_invalid_api_version(): + with pytest.raises(ModuleNotFoundError): + gitlab.Gitlab(api_version="1") + + +def test_gitlab_as_context_manager(): + with gitlab.Gitlab() as gl: + assert isinstance(gl, gitlab.Gitlab) + + +@responses.activate +@pytest.mark.parametrize( + "status_code,response_json,expected", + [ + (200, {"version": "0.0.0-pre", "revision": "abcdef"}, ("0.0.0-pre", "abcdef")), + (200, None, ("unknown", "unknown")), + (401, None, ("unknown", "unknown")), + ], +) +def test_gitlab_get_version(gl, status_code, response_json, expected): + responses.add( + method=responses.GET, + url="http://localhost/api/v4/version", + json=response_json, + status=status_code, + match=helpers.MATCH_EMPTY_QUERY_PARAMS, + ) + + version = gl.version() + assert version == expected + + +@responses.activate +@pytest.mark.parametrize( + "response_json,expected", + [ + ({"id": "1", "plan": "premium"}, {"id": "1", "plan": "premium"}), + (None, {}), + ], +) +def test_gitlab_get_license(gl, response_json, expected): + responses.add( + method=responses.GET, + url="http://localhost/api/v4/license", + json=response_json, + status=200, + match=helpers.MATCH_EMPTY_QUERY_PARAMS, + ) + + gitlab_license = gl.get_license() + assert gitlab_license == expected + + @responses.activate def test_gitlab_build_list(gl, resp_page_1, resp_page_2): responses.add(**resp_page_1) |