|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | 3 | # |
4 | | -# Copyright (c) 2020-2021 Kiwi TCMS project. All rights reserved. |
| 4 | +# Copyright (c) 2020-2024 Kiwi TCMS project. All rights reserved. |
5 | 5 | # Author: Alexander Todorov <info@kiwitcms.org> |
6 | 6 | # |
7 | 7 |
|
8 | | -import ssl |
9 | 8 | import unittest |
10 | | -from unittest.mock import patch |
11 | 9 |
|
12 | 10 | from datetime import datetime |
13 | | - |
14 | | -import requests |
15 | 11 | from tcms_api import TCMS |
16 | 12 |
|
17 | 13 |
|
18 | | -try: |
19 | | - _create_unverified_https_context = ssl._create_unverified_context |
20 | | -except AttributeError: |
21 | | - # Legacy Python that doesn't verify HTTPS certificates by default |
22 | | - pass |
23 | | -else: |
24 | | - # Handle target environment that doesn't support HTTPS verification |
25 | | - ssl._create_default_https_context = _create_unverified_https_context |
26 | | - |
27 | | - |
28 | | -class DoNotVerifySSLSession(requests.sessions.Session): |
29 | | - def __init__(self): |
30 | | - super().__init__() |
31 | | - self.verify = False |
32 | | - |
33 | | - def get(self, url, **kwargs): |
34 | | - kwargs.setdefault("verify", False) |
35 | | - return super().get(url, **kwargs) |
36 | | - |
37 | | - |
38 | 14 | class IntegrationTestCase(unittest.TestCase): |
39 | 15 | @classmethod |
40 | 16 | def setUpClass(cls): |
41 | 17 | cls.rpc = TCMS().exec |
42 | 18 |
|
43 | 19 | def test_readonly_filtering_works(self): |
44 | | - with patch("requests.sessions.Session") as session: |
45 | | - session.return_value = DoNotVerifySSLSession() |
46 | | - |
47 | | - results = self.rpc.Product.filter({}) |
48 | | - self.assertGreater(len(results), 0) |
| 20 | + results = self.rpc.Product.filter({}) |
| 21 | + self.assertGreater(len(results), 0) |
49 | 22 |
|
50 | 23 | def test_create_objects_works(self): |
51 | | - with patch("requests.sessions.Session") as session: |
52 | | - session.return_value = DoNotVerifySSLSession() |
53 | | - |
54 | | - now = datetime.now().isoformat() |
55 | | - |
56 | | - result = self.rpc.Classification.filter( |
57 | | - { |
58 | | - "name": "test-products", |
59 | | - } |
60 | | - )[0] |
61 | | - self.assertEqual(result["name"], "test-products") |
62 | | - classification_id = result["id"] |
63 | | - |
64 | | - product_name = "tcms-api-%s" % now |
65 | | - result = self.rpc.Product.create( |
66 | | - {"name": product_name, "classification": classification_id} |
67 | | - ) |
68 | | - self.assertEqual(result["name"], product_name) |
| 24 | + now = datetime.now().isoformat() |
| 25 | + |
| 26 | + result = self.rpc.Classification.filter( |
| 27 | + { |
| 28 | + "name": "test-products", |
| 29 | + } |
| 30 | + )[0] |
| 31 | + self.assertEqual(result["name"], "test-products") |
| 32 | + classification_id = result["id"] |
| 33 | + |
| 34 | + product_name = "tcms-api-%s" % now |
| 35 | + result = self.rpc.Product.create( |
| 36 | + {"name": product_name, "classification": classification_id} |
| 37 | + ) |
| 38 | + self.assertEqual(result["name"], product_name) |
69 | 39 |
|
70 | 40 |
|
71 | 41 | if __name__ == "__main__": |
|
0 commit comments