|
| 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