hardpy 0.5.0__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,96 @@
1
1
  # Copyright (c) 2024 Everypin
2
2
  # GNU General Public License v3.0 (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
3
3
 
4
+ import ast
5
+ import requests
6
+ import socket
7
+
4
8
  from dataclasses import dataclass
9
+ from urllib3 import disable_warnings
5
10
 
6
11
 
7
12
  @dataclass
8
13
  class CouchdbConfig: # noqa: WPS306
9
- """CouchDB loader config."""
14
+ """CouchDB loader config.
15
+
16
+ If `connection_str` arg is not set, it will be created from other args.
17
+ """
10
18
 
11
19
  db_name: str = "report"
12
20
  user: str = "dev"
13
21
  password: str = "dev"
14
22
  host: str = "localhost"
15
23
  port: int = 5984
24
+ connection_str: str | None = None
25
+
26
+ def __post_init__(self):
27
+ """Disable urllib3 warnings.
28
+
29
+ More info: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
30
+ """
31
+ disable_warnings()
16
32
 
17
33
  @property
18
34
  def connection_string(self) -> str:
19
- """Get couchdb connection string."""
35
+ """Get couchdb connection string.
36
+
37
+ Raises:
38
+ RuntimeError: CouchDB server is not available
39
+
40
+ Returns:
41
+ str: Database connection string.
42
+ """
43
+ if self.connection_str:
44
+ return self.connection_str
45
+
46
+ # TODO: Modify connection string creating based on protocol.
47
+ # Some problems with http and https, different ports, local
48
+ # and cloud databases.
49
+ protocol = self._get_protocol()
50
+
51
+ if protocol == "http":
52
+ host_url = f"http://{self.host}:{self.port}"
53
+ uri = f"{self.host}:{str(self.port)}" # noqa: WPS237
54
+ elif protocol == "https":
55
+ host_url = f"https://{self.host}"
56
+ uri = f"{self.host}"
57
+
58
+ try:
59
+ response = requests.get(host_url, timeout=5)
60
+ except requests.exceptions.RequestException:
61
+ raise RuntimeError(f"Error CouchDB connecting to {host_url}.")
62
+
63
+ # fmt: off
64
+ try:
65
+ couchdb_dict = ast.literal_eval(response._content.decode("utf-8")) # noqa: WPS437,E501
66
+ couchdb_dict.get("couchdb", False)
67
+ except Exception:
68
+ raise RuntimeError(f"Address {host_url} does not provide CouchDB attributes.")
69
+ # fmt: on
70
+
20
71
  credentials = f"{self.user}:{self.password}"
21
- uri = f"{self.host}:{str(self.port)}"
22
- return f"http://{credentials}@{uri}/"
72
+ return f"{protocol}://{credentials}@{uri}/"
73
+
74
+ def _get_protocol(self) -> str: # noqa: WPS231
75
+ success = 200
76
+ try:
77
+ # HTTPS attempt
78
+ sock = socket.create_connection((self.host, self.port))
79
+ sock.close()
80
+ request = f"https://{self.host}"
81
+ if requests.get(request, timeout=5).status_code == success:
82
+ return "https"
83
+ raise OSError
84
+ except OSError:
85
+ try: # noqa: WPS505
86
+ # HTTP attempt
87
+ sock = socket.create_connection((self.host, self.port))
88
+ sock.close()
89
+ request = f"http://{self.host}:{self.port}"
90
+ if requests.get(request, timeout=5).status_code == success:
91
+ return "http"
92
+ raise OSError
93
+ except OSError:
94
+ raise RuntimeError(
95
+ f"Error connecting to couchdb server {self.host}:{self.port}."
96
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hardpy
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: HardPy library for device testing
5
5
  Project-URL: Homepage, https://github.com/everypinio/hardpy/
6
6
  Project-URL: Documentation, https://everypinio.github.io/hardpy/
@@ -52,7 +52,7 @@ hardpy/pytest_hardpy/reporter/base.py,sha256=M-lwli64ty9FW8HlGEpUyoFsZv48tyNgzPj
52
52
  hardpy/pytest_hardpy/reporter/hook_reporter.py,sha256=kZ3jx--ne9l3a27TmVdZCPBoqy53EuHYg2fHDGuJNes,10068
53
53
  hardpy/pytest_hardpy/reporter/runner_reporter.py,sha256=NXkBIoERqmLI-GYtHavmOWC5t6NIpcAE-NECrUKIAJs,827
54
54
  hardpy/pytest_hardpy/result/__init__.py,sha256=NMeCGx3yh8ds9VpaUpuNFDxbwgYFq3e-o7W6rYIv8uI,346
55
- hardpy/pytest_hardpy/result/couchdb_config.py,sha256=QZryfA2QoHIjzbVT3OAD76DCNppCghtRWdZMZ5v7KhY,611
55
+ hardpy/pytest_hardpy/result/couchdb_config.py,sha256=kttsrWzv9D99R3ms-hFbzVbrZ78B2me6rrJgncfs5jk,3129
56
56
  hardpy/pytest_hardpy/result/report_loader/__init__.py,sha256=FuHuD6IFZyaKj0yu5urhf6nkxGbiPONJ-WHnJ2jHwyc,251
57
57
  hardpy/pytest_hardpy/result/report_loader/couchdb_loader.py,sha256=1BGncK1NnwYJanm5TYETjMkqR7tmrUfGK8Sgnp2JZC8,2203
58
58
  hardpy/pytest_hardpy/result/report_reader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -65,8 +65,8 @@ hardpy/pytest_hardpy/utils/exception.py,sha256=khifykRuFS7GyIyQcJeMg6VOgwhPPvzNq
65
65
  hardpy/pytest_hardpy/utils/node_info.py,sha256=VnEbhKBNAL5xpuFtJTCg90TmkjkFCQA59F5W2RcOlx4,3157
66
66
  hardpy/pytest_hardpy/utils/progress_calculator.py,sha256=r0qb3p6_yDIyLeCshF3Ceo5pCzd3BoTahL4rCD2oMNw,1041
67
67
  hardpy/pytest_hardpy/utils/singleton.py,sha256=C8cgRDydnG2b5dcN1LCLw4aM-AUMAvJc1W39mTkNWlQ,614
68
- hardpy-0.5.0.dist-info/METADATA,sha256=uzKt39irvwMS6Y73kXPR1JRW-VEEfg1tEszfUTvPtiM,4305
69
- hardpy-0.5.0.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
70
- hardpy-0.5.0.dist-info/entry_points.txt,sha256=q73g5GfznSUpjkayi0SV4uaAtrf7D-7rmDoWoEZmZe0,120
71
- hardpy-0.5.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
72
- hardpy-0.5.0.dist-info/RECORD,,
68
+ hardpy-0.5.1.dist-info/METADATA,sha256=rqydaDWQCSC8_UiPYkz6uF0_C475CleUaREiDWbX1DY,4305
69
+ hardpy-0.5.1.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
70
+ hardpy-0.5.1.dist-info/entry_points.txt,sha256=q73g5GfznSUpjkayi0SV4uaAtrf7D-7rmDoWoEZmZe0,120
71
+ hardpy-0.5.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
72
+ hardpy-0.5.1.dist-info/RECORD,,
File without changes