toDus-API 1.3.3__tar.gz → 1.3.4__tar.gz

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.
Files changed (36) hide show
  1. {todus_api-1.3.3/toDus_API.egg-info → todus_api-1.3.4}/PKG-INFO +1 -1
  2. todus_api-1.3.4/tests/test_proxy.py +134 -0
  3. {todus_api-1.3.3 → todus_api-1.3.4/toDus_API.egg-info}/PKG-INFO +1 -1
  4. {todus_api-1.3.3 → todus_api-1.3.4}/todus/__init__.py +1 -1
  5. {todus_api-1.3.3 → todus_api-1.3.4}/todus/client/file.py +1 -1
  6. {todus_api-1.3.3 → todus_api-1.3.4}/todus/client/profile.py +2 -2
  7. todus_api-1.3.3/tests/test_proxy.py +0 -65
  8. {todus_api-1.3.3 → todus_api-1.3.4}/CHANGELOG.md +0 -0
  9. {todus_api-1.3.3 → todus_api-1.3.4}/LICENSE +0 -0
  10. {todus_api-1.3.3 → todus_api-1.3.4}/MANIFEST.in +0 -0
  11. {todus_api-1.3.3 → todus_api-1.3.4}/README.md +0 -0
  12. {todus_api-1.3.3 → todus_api-1.3.4}/pyproject.toml +0 -0
  13. {todus_api-1.3.3 → todus_api-1.3.4}/setup.cfg +0 -0
  14. {todus_api-1.3.3 → todus_api-1.3.4}/tests/test_stanzas.py +0 -0
  15. {todus_api-1.3.3 → todus_api-1.3.4}/tests/test_types.py +0 -0
  16. {todus_api-1.3.3 → todus_api-1.3.4}/tests/test_util.py +0 -0
  17. {todus_api-1.3.3 → todus_api-1.3.4}/toDus_API.egg-info/SOURCES.txt +0 -0
  18. {todus_api-1.3.3 → todus_api-1.3.4}/toDus_API.egg-info/dependency_links.txt +0 -0
  19. {todus_api-1.3.3 → todus_api-1.3.4}/toDus_API.egg-info/requires.txt +0 -0
  20. {todus_api-1.3.3 → todus_api-1.3.4}/toDus_API.egg-info/top_level.txt +0 -0
  21. {todus_api-1.3.3 → todus_api-1.3.4}/todus/client/__init__.py +0 -0
  22. {todus_api-1.3.3 → todus_api-1.3.4}/todus/client/auth.py +0 -0
  23. {todus_api-1.3.3 → todus_api-1.3.4}/todus/client/base.py +0 -0
  24. {todus_api-1.3.3 → todus_api-1.3.4}/todus/client/message.py +0 -0
  25. {todus_api-1.3.3 → todus_api-1.3.4}/todus/constants.py +0 -0
  26. {todus_api-1.3.3 → todus_api-1.3.4}/todus/errors.py +0 -0
  27. {todus_api-1.3.3 → todus_api-1.3.4}/todus/group.py +0 -0
  28. {todus_api-1.3.3 → todus_api-1.3.4}/todus/parser.py +0 -0
  29. {todus_api-1.3.3 → todus_api-1.3.4}/todus/stanza.py +0 -0
  30. {todus_api-1.3.3 → todus_api-1.3.4}/todus/stanzas/__init__.py +0 -0
  31. {todus_api-1.3.3 → todus_api-1.3.4}/todus/stanzas/group.py +0 -0
  32. {todus_api-1.3.3 → todus_api-1.3.4}/todus/stanzas/presence.py +0 -0
  33. {todus_api-1.3.3 → todus_api-1.3.4}/todus/stanzas/private.py +0 -0
  34. {todus_api-1.3.3 → todus_api-1.3.4}/todus/stanzas/utils.py +0 -0
  35. {todus_api-1.3.3 → todus_api-1.3.4}/todus/types.py +0 -0
  36. {todus_api-1.3.3 → todus_api-1.3.4}/todus/util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toDus-API
3
- Version: 1.3.3
3
+ Version: 1.3.4
4
4
  Summary: Cliente Python para ToDus (mensajería cubana) — chat, grupos, archivos, stickers y más
5
5
  Author: ElJoker63
6
6
  License-Expression: MIT
@@ -0,0 +1,134 @@
1
+ """Tests para el soporte de proxy en ToDus."""
2
+
3
+ import pytest
4
+ import socks
5
+ from todus.client.base import ToDusClientBase
6
+ from todus.client import ToDusClient2
7
+
8
+
9
+ class TestProxySupport:
10
+ def test_parse_socks5_proxy_basic(self):
11
+ client = ToDusClientBase()
12
+ proxy_type, host, port, username, password = client._parse_proxy("socks5://127.0.0.1:1080")
13
+ assert proxy_type == socks.SOCKS5
14
+ assert host == "127.0.0.1"
15
+ assert port == 1080
16
+ assert username is None
17
+ assert password is None
18
+
19
+ def test_parse_socks5_proxy_auth(self):
20
+ client = ToDusClientBase()
21
+ proxy_type, host, port, username, password = client._parse_proxy("socks5://user:pass@127.0.0.1:1080")
22
+ assert proxy_type == socks.SOCKS5
23
+ assert host == "127.0.0.1"
24
+ assert port == 1080
25
+ assert username == "user"
26
+ assert password == "pass"
27
+
28
+ def test_parse_http_proxy_default_port(self):
29
+ client = ToDusClientBase()
30
+ proxy_type, host, port, username, password = client._parse_proxy("http://proxy.example.com")
31
+ assert proxy_type == socks.HTTP
32
+ assert host == "proxy.example.com"
33
+ assert port == 8080
34
+ assert username is None
35
+ assert password is None
36
+
37
+ def test_parse_socks5h_proxy(self):
38
+ client = ToDusClientBase()
39
+ proxy_type, host, port, username, password = client._parse_proxy("socks5h://127.0.0.1")
40
+ assert proxy_type == socks.SOCKS5
41
+ assert host == "127.0.0.1"
42
+ assert port == 1080
43
+
44
+ def test_parse_unsupported_scheme(self):
45
+ client = ToDusClientBase()
46
+ with pytest.raises(ValueError):
47
+ client._parse_proxy("ftp://127.0.0.1")
48
+
49
+ def test_client_init_with_proxy(self):
50
+ proxy_url = "socks5://127.0.0.1:1080"
51
+ client = ToDusClientBase(proxy=proxy_url)
52
+ assert client.proxy == proxy_url
53
+ assert client.session.proxies == {
54
+ "http": proxy_url,
55
+ "https": proxy_url,
56
+ }
57
+
58
+ def test_client2_init_with_proxy(self):
59
+ proxy_url = "http://127.0.0.1:8080"
60
+ client = ToDusClient2(phone_number="5312345678", password="pass", proxy=proxy_url)
61
+ assert client.proxy == proxy_url
62
+ assert client.session.proxies == {
63
+ "http": proxy_url,
64
+ "https": proxy_url,
65
+ }
66
+
67
+ def test_upload_file_uses_session(self, monkeypatch):
68
+ client = ToDusClient2(phone_number="5312345678", password="pass", proxy="http://127.0.0.1:8080")
69
+ client._token = "mock_token"
70
+
71
+ def mock_reserve(*args, **kwargs):
72
+ return "https://upload.todus.cu/put", "https://download.todus.cu/get"
73
+ monkeypatch.setattr(client, "reserve_upload_url", mock_reserve)
74
+
75
+ called_args = []
76
+ class MockResponse:
77
+ def raise_for_status(self):
78
+ pass
79
+
80
+ def mock_put(url, *args, **kwargs):
81
+ called_args.append(url)
82
+ return MockResponse()
83
+
84
+ monkeypatch.setattr(client.session, "put", mock_put)
85
+
86
+ down_url = client.upload_file(b"test data", file_name="test.txt")
87
+
88
+ assert down_url == "https://download.todus.cu/get"
89
+ assert len(called_args) == 1
90
+ assert called_args[0] == "https://upload.todus.cu/put"
91
+ assert client.session.proxies == {
92
+ "http": "http://127.0.0.1:8080",
93
+ "https": "http://127.0.0.1:8080",
94
+ }
95
+
96
+ def test_upload_avatar_uses_session(self, monkeypatch):
97
+ client = ToDusClient2(phone_number="5312345678", password="pass", proxy="http://127.0.0.1:8080")
98
+ client._token = "mock_token"
99
+
100
+ urls = [
101
+ ("https://upload.todus.cu/put_main", "https://download.todus.cu/get_main"),
102
+ ("https://upload.todus.cu/put_thumb", "https://download.todus.cu/get_thumb")
103
+ ]
104
+ url_idx = 0
105
+ def mock_reserve(*args, **kwargs):
106
+ nonlocal url_idx
107
+ val = urls[url_idx]
108
+ url_idx += 1
109
+ return val
110
+ monkeypatch.setattr(client, "reserve_upload_url", mock_reserve)
111
+
112
+ called_urls = []
113
+ class MockResponse:
114
+ def raise_for_status(self):
115
+ pass
116
+
117
+ def mock_put(url, *args, **kwargs):
118
+ called_urls.append(url)
119
+ return MockResponse()
120
+
121
+ monkeypatch.setattr(client.session, "put", mock_put)
122
+
123
+ profile_url, thumb_url = client.upload_avatar(b"main_image", b"thumb_image")
124
+
125
+ assert profile_url == "https://download.todus.cu/get_main"
126
+ assert thumb_url == "https://download.todus.cu/get_thumb"
127
+ assert len(called_urls) == 2
128
+ assert called_urls[0] == "https://upload.todus.cu/put_main"
129
+ assert called_urls[1] == "https://upload.todus.cu/put_thumb"
130
+ assert client.session.proxies == {
131
+ "http": "http://127.0.0.1:8080",
132
+ "https": "http://127.0.0.1:8080",
133
+ }
134
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toDus-API
3
- Version: 1.3.3
3
+ Version: 1.3.4
4
4
  Summary: Cliente Python para ToDus (mensajería cubana) — chat, grupos, archivos, stickers y más
5
5
  Author: ElJoker63
6
6
  License-Expression: MIT
@@ -18,7 +18,7 @@ from .errors import (
18
18
  from .util import normalize_phone, build_jid, generate_token, jwt_decode_payload, timestamp_ms, format_size
19
19
  from .parser import IncrementalParser, parse_tdack
20
20
 
21
- __version__ = "1.3.3"
21
+ __version__ = "1.3.4"
22
22
  __all__ = [
23
23
  "ToDusClient",
24
24
  "ToDusClient2",
@@ -94,7 +94,7 @@ class ToDusFileMixin:
94
94
  def upload_file(self, token: str, data: bytes, file_type: FileType = FileType.FILE, progress_callback: Callable[[int, int], None] = None, file_name: str = "") -> str:
95
95
  up_url, down_url = self.reserve_upload_url(token, len(data), file_type, file_name=file_name)
96
96
  upload_data = _ProgressReader(data, progress_callback) if progress_callback else data
97
- resp = requests.put(
97
+ resp = self.session.put(
98
98
  up_url,
99
99
  data=upload_data,
100
100
  headers={"Content-Length": str(len(data))},
@@ -34,7 +34,7 @@ class ToDusProfileMixin:
34
34
  thumbnail_data = image_data
35
35
 
36
36
  up_url, down_url = self.reserve_upload_url(token, len(image_data), FileType.PROFILE)
37
- resp = requests.put(
37
+ resp = self.session.put(
38
38
  up_url,
39
39
  data=image_data,
40
40
  headers={"Content-Length": str(len(image_data)), "Content-Type": "application/octet-stream"},
@@ -44,7 +44,7 @@ class ToDusProfileMixin:
44
44
  profile_url = down_url
45
45
 
46
46
  up_url, down_url = self.reserve_upload_url(token, len(thumbnail_data), FileType.PROFILE_THUMBNAIL)
47
- resp = requests.put(
47
+ resp = self.session.put(
48
48
  up_url,
49
49
  data=thumbnail_data,
50
50
  headers={"Content-Length": str(len(thumbnail_data)), "Content-Type": "application/octet-stream"},
@@ -1,65 +0,0 @@
1
- """Tests para el soporte de proxy en ToDus."""
2
-
3
- import pytest
4
- import socks
5
- from todus.client.base import ToDusClientBase
6
- from todus.client import ToDusClient2
7
-
8
-
9
- class TestProxySupport:
10
- def test_parse_socks5_proxy_basic(self):
11
- client = ToDusClientBase()
12
- proxy_type, host, port, username, password = client._parse_proxy("socks5://127.0.0.1:1080")
13
- assert proxy_type == socks.SOCKS5
14
- assert host == "127.0.0.1"
15
- assert port == 1080
16
- assert username is None
17
- assert password is None
18
-
19
- def test_parse_socks5_proxy_auth(self):
20
- client = ToDusClientBase()
21
- proxy_type, host, port, username, password = client._parse_proxy("socks5://user:pass@127.0.0.1:1080")
22
- assert proxy_type == socks.SOCKS5
23
- assert host == "127.0.0.1"
24
- assert port == 1080
25
- assert username == "user"
26
- assert password == "pass"
27
-
28
- def test_parse_http_proxy_default_port(self):
29
- client = ToDusClientBase()
30
- proxy_type, host, port, username, password = client._parse_proxy("http://proxy.example.com")
31
- assert proxy_type == socks.HTTP
32
- assert host == "proxy.example.com"
33
- assert port == 8080
34
- assert username is None
35
- assert password is None
36
-
37
- def test_parse_socks5h_proxy(self):
38
- client = ToDusClientBase()
39
- proxy_type, host, port, username, password = client._parse_proxy("socks5h://127.0.0.1")
40
- assert proxy_type == socks.SOCKS5
41
- assert host == "127.0.0.1"
42
- assert port == 1080
43
-
44
- def test_parse_unsupported_scheme(self):
45
- client = ToDusClientBase()
46
- with pytest.raises(ValueError):
47
- client._parse_proxy("ftp://127.0.0.1")
48
-
49
- def test_client_init_with_proxy(self):
50
- proxy_url = "socks5://127.0.0.1:1080"
51
- client = ToDusClientBase(proxy=proxy_url)
52
- assert client.proxy == proxy_url
53
- assert client.session.proxies == {
54
- "http": proxy_url,
55
- "https": proxy_url,
56
- }
57
-
58
- def test_client2_init_with_proxy(self):
59
- proxy_url = "http://127.0.0.1:8080"
60
- client = ToDusClient2(phone_number="5312345678", password="pass", proxy=proxy_url)
61
- assert client.proxy == proxy_url
62
- assert client.session.proxies == {
63
- "http": proxy_url,
64
- "https": proxy_url,
65
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes