Skip to content

Commit 7604fc6

Browse files
authored
Merge pull request #3 from sw360/feat/get-clearing-request
Feat/get clearing request
2 parents 0eb71af + 639031b commit 7604fc6

5 files changed

Lines changed: 107 additions & 2 deletions

File tree

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SW360 Base Library for Python
22

3+
## V0.9.1
4+
* **New Features**:
5+
* support to retrieve information about clearing requests (`get_clearing_request`, `get_clearing_request_for_project`).
6+
37
## V0.9
48
* relicensed to MIT.
59
* **Breaking API changes**:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sw360"
3-
version = "0.9"
3+
version = "0.9.1"
44
description = "Python interface to the SW360 software component catalogue"
55
authors = ["Thomas Graf <thomas.graf@siemens.com>",
66
"Gernot Hillier <gernot.hillier@siemens.com>"]

sw360/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
# SPDX-License-Identifier: MIT
88
# -------------------------------------------------------------------------------
99

10-
__version__ = (0, 9, 0)
10+
__version__ = (0, 9, 1)
1111

1212
from .sw360_api import SW360, SW360Error # noqa: F401

sw360/sw360_api.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,38 @@ def get_health_status(self):
14241424
resp = self.api_get(self.url + "resource/health/")
14251425
return resp
14261426

1427+
# ----- Clearing Requests ------------------------------------------------
1428+
1429+
def get_clearing_request(self, request_id):
1430+
"""Get information of about a clearing request
1431+
1432+
API endpoint: GET /clearingrequest/{id}
1433+
1434+
:param request_id: the id of the clearing request to be requested
1435+
:type request_id: string
1436+
:return: a clearing request
1437+
:rtype: JSON clearing request object
1438+
:raises SW360Error: if there is a negative HTTP response
1439+
"""
1440+
1441+
resp = self.api_get(self.url + "resource/api/clearingrequest/" + request_id)
1442+
return resp
1443+
1444+
def get_clearing_request_for_project(self, project_id):
1445+
"""Get information of about a clearing request for a specific project
1446+
1447+
API endpoint: GET /clearingrequest/project/{id}
1448+
1449+
:param request_id: the id of the clearing request to be requested
1450+
:type request_id: string
1451+
:return: a clearing request
1452+
:rtype: JSON clearing request object
1453+
:raises SW360Error: if there is a negative HTTP response
1454+
"""
1455+
1456+
resp = self.api_get(self.url + "resource/api/clearingrequest/project/" + project_id)
1457+
return resp
1458+
14271459
# ----- Support ----------------------------------------------------------
14281460

14291461
@classmethod
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -------------------------------------------------------------------------------
2+
# (c) 2021 Siemens AG
3+
# All Rights Reserved.
4+
# Author: thomas.graf@siemens.com
5+
#
6+
# Licensed under the MIT license.
7+
# SPDX-License-Identifier: MIT
8+
# -------------------------------------------------------------------------------
9+
10+
import sys
11+
import warnings
12+
import unittest
13+
14+
import responses
15+
16+
sys.path.insert(1, "..")
17+
18+
from sw360 import SW360 # noqa: E402
19+
20+
21+
class Sw360TestClearingRequests(unittest.TestCase):
22+
MYTOKEN = "MYTOKEN"
23+
MYURL = "https://my.server.com/"
24+
ERROR_MSG_NO_LOGIN = "Unable to login"
25+
26+
def setUp(self):
27+
warnings.filterwarnings(
28+
"ignore", category=ResourceWarning,
29+
message="unclosed.*<ssl.SSLSocket.*>")
30+
31+
def _add_login_response(self):
32+
"""
33+
Add the response for a successfull login.
34+
"""
35+
responses.add(
36+
method=responses.GET,
37+
url=self.MYURL + "resource/api/",
38+
body="{'status': 'ok'}",
39+
status=200,
40+
content_type="application/json",
41+
adding_headers={"Authorization": "Token " + self.MYTOKEN},
42+
)
43+
44+
@responses.activate
45+
def test_get_clearing_request(self):
46+
lib = SW360(self.MYURL, self.MYTOKEN, False)
47+
self._add_login_response()
48+
actual = lib.login_api()
49+
self.assertTrue(actual)
50+
51+
responses.add(
52+
method=responses.GET,
53+
url=self.MYURL + "resource/api/clearingrequest/12345",
54+
body='{"id": "12345",\
55+
"requestedClearingDate": "2021-09-04",\
56+
"projectId": "007",\
57+
"clearingState": "NEW"}', # noqa
58+
status=200,
59+
content_type="application/json",
60+
adding_headers={"Authorization": "Token " + self.MYTOKEN},
61+
)
62+
63+
vendor = lib.get_clearing_request("12345")
64+
self.assertIsNotNone(vendor)
65+
self.assertEqual("2021-09-04", vendor["requestedClearingDate"])
66+
67+
68+
if __name__ == "__main__":
69+
unittest.main()

0 commit comments

Comments
 (0)