diff options
| author | Ben Brown <ben.brown@codethink.co.uk> | 2021-05-25 14:14:18 +0100 |
|---|---|---|
| committer | Ben Brown <ben.brown@codethink.co.uk> | 2021-06-03 09:22:10 +0100 |
| commit | a81525a2377aaed797af0706b00be7f5d8616d22 (patch) | |
| tree | df32c795081135a1f7abde8500b72c382f68c9b9 /tests/unit | |
| parent | 74f5e62ef5bfffc7ba21494d05dbead60b59ecf0 (diff) | |
| download | gitlab-a81525a2377aaed797af0706b00be7f5d8616d22.tar.gz | |
feat: add keys endpoint
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/objects/test_keys.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/objects/test_keys.py b/tests/unit/objects/test_keys.py new file mode 100644 index 0000000..187a309 --- /dev/null +++ b/tests/unit/objects/test_keys.py @@ -0,0 +1,54 @@ +""" +GitLab API: https://docs.gitlab.com/ce/api/keys.html +""" +import pytest +import responses + +from gitlab.v4.objects import Key + +key_content = {"id": 1, "title": "title", "key": "ssh-keytype AAAAC3Nza/key comment"} + + +@pytest.fixture +def resp_get_key_by_id(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/keys/1", + json=key_content, + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_get_key_by_fingerprint(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/keys?fingerprint=foo", + json=key_content, + content_type="application/json", + status=200, + ) + yield rsps + + +def test_get_key_by_id(gl, resp_get_key_by_id): + key = gl.keys.get(1) + assert isinstance(key, Key) + assert key.id == 1 + assert key.title == "title" + + +def test_get_key_by_fingerprint(gl, resp_get_key_by_fingerprint): + key = gl.keys.get(fingerprint="foo") + assert isinstance(key, Key) + assert key.id == 1 + assert key.title == "title" + + +def test_get_key_missing_attrs(gl): + with pytest.raises(AttributeError): + gl.keys.get() |
