amochka 0.4.4__tar.gz → 0.4.5__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 (27) hide show
  1. {amochka-0.4.4 → amochka-0.4.5}/PKG-INFO +1 -1
  2. {amochka-0.4.4 → amochka-0.4.5}/amochka/__init__.py +1 -1
  3. {amochka-0.4.4 → amochka-0.4.5}/amochka/client.py +11 -1
  4. {amochka-0.4.4 → amochka-0.4.5}/amochka.egg-info/PKG-INFO +1 -1
  5. {amochka-0.4.4 → amochka-0.4.5}/pyproject.toml +1 -1
  6. {amochka-0.4.4 → amochka-0.4.5}/tests/test_client.py +37 -0
  7. {amochka-0.4.4 → amochka-0.4.5}/README.md +0 -0
  8. {amochka-0.4.4 → amochka-0.4.5}/amochka/errors.py +0 -0
  9. {amochka-0.4.4 → amochka-0.4.5}/amochka/etl.py +0 -0
  10. {amochka-0.4.4 → amochka-0.4.5}/amochka.egg-info/SOURCES.txt +0 -0
  11. {amochka-0.4.4 → amochka-0.4.5}/amochka.egg-info/dependency_links.txt +0 -0
  12. {amochka-0.4.4 → amochka-0.4.5}/amochka.egg-info/requires.txt +0 -0
  13. {amochka-0.4.4 → amochka-0.4.5}/amochka.egg-info/top_level.txt +0 -0
  14. {amochka-0.4.4 → amochka-0.4.5}/etl/__init__.py +0 -0
  15. {amochka-0.4.4 → amochka-0.4.5}/etl/config.py +0 -0
  16. {amochka-0.4.4 → amochka-0.4.5}/etl/extractors.py +0 -0
  17. {amochka-0.4.4 → amochka-0.4.5}/etl/loaders.py +0 -0
  18. {amochka-0.4.4 → amochka-0.4.5}/etl/migrations/001_create_tables.sql +0 -0
  19. {amochka-0.4.4 → amochka-0.4.5}/etl/run_etl.py +0 -0
  20. {amochka-0.4.4 → amochka-0.4.5}/etl/transformers.py +0 -0
  21. {amochka-0.4.4 → amochka-0.4.5}/setup.cfg +0 -0
  22. {amochka-0.4.4 → amochka-0.4.5}/tests/test_cache.py +0 -0
  23. {amochka-0.4.4 → amochka-0.4.5}/tests/test_etl.py +0 -0
  24. {amochka-0.4.4 → amochka-0.4.5}/tests/test_http.py +0 -0
  25. {amochka-0.4.4 → amochka-0.4.5}/tests/test_notes_events.py +0 -0
  26. {amochka-0.4.4 → amochka-0.4.5}/tests/test_security.py +0 -0
  27. {amochka-0.4.4 → amochka-0.4.5}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amochka
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Python library for working with amoCRM API with ETL capabilities
5
5
  Author-email: Timur <timurdt@gmail.com>
6
6
  License: MIT
@@ -2,7 +2,7 @@
2
2
  amochka: Библиотека для работы с API amoCRM.
3
3
  """
4
4
 
5
- __version__ = "0.4.4"
5
+ __version__ = "0.4.5"
6
6
 
7
7
  from .client import AmoCRMClient, CacheConfig
8
8
  from .errors import (
@@ -1093,12 +1093,17 @@ class AmoCRMClient:
1093
1093
  updated_from: Optional[Union[int, float, str, datetime]] = None,
1094
1094
  updated_to: Optional[Union[int, float, str, datetime]] = None,
1095
1095
  contact_ids: Optional[Union[int, Sequence[Union[int, str]]]] = None,
1096
+ query: Optional[str] = None,
1097
+ min_query_length: Optional[int] = None,
1096
1098
  limit: int = 250,
1097
1099
  extra_params: Optional[dict] = None,
1098
1100
  max_pages: Optional[int] = None,
1099
1101
  ) -> Iterator[dict]:
1100
1102
  """
1101
- Итератор контактов с фильтрацией по диапазону обновления или списку ID.
1103
+ Итератор контактов с фильтрацией по диапазону обновления, списку ID или query.
1104
+
1105
+ :param query: Строка поиска (например, телефон). Перед отправкой очищается до цифр.
1106
+ :param min_query_length: Минимальная длина query (по числу цифр). Если не достигнута, query не отправляется.
1102
1107
 
1103
1108
  :param max_pages: Максимальное количество страниц для итерации (None = без ограничений)
1104
1109
  :raises ValidationError: Если параметры имеют некорректный тип или значение.
@@ -1135,6 +1140,11 @@ class AmoCRMClient:
1135
1140
  contact_param = self._format_filter_values(contact_ids)
1136
1141
  if contact_param:
1137
1142
  params["filter[id][]"] = contact_param
1143
+ if query is not None:
1144
+ query_digits = "".join(ch for ch in query.strip() if ch.isdigit())
1145
+ if query_digits:
1146
+ if min_query_length is None or len(query_digits) >= min_query_length:
1147
+ params["query"] = query_digits
1138
1148
  if extra_params:
1139
1149
  params.update(extra_params)
1140
1150
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amochka
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Python library for working with amoCRM API with ETL capabilities
5
5
  Author-email: Timur <timurdt@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "amochka"
7
- version = "0.4.4"
7
+ version = "0.4.5"
8
8
  description = "Python library for working with amoCRM API with ETL capabilities"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -20,6 +20,17 @@ from amochka import (
20
20
  )
21
21
 
22
22
 
23
+ def make_client():
24
+ import time
25
+ token_data = {"access_token": "token", "expires_at": str(time.time() + 3600)}
26
+ return AmoCRMClient(
27
+ base_url="https://example.amocrm.ru",
28
+ token_file=json.dumps(token_data),
29
+ cache_config=CacheConfig.disabled(),
30
+ disable_logging=True,
31
+ )
32
+
33
+
23
34
  class DummyClient(AmoCRMClient):
24
35
  def __init__(self):
25
36
  import time
@@ -260,3 +271,29 @@ def test_export_helpers_write_expected_files(tmp_path):
260
271
 
261
272
  notes_call = next(item for item in client.calls if item[1] == "/api/v4/leads/notes")
262
273
  assert notes_call[2]["filter[updated_at][from]"] is None or notes_call[2]["filter[updated_at][from]"] >= 0
274
+
275
+
276
+ def test_iter_contacts_query_param(monkeypatch):
277
+ client = make_client()
278
+ captured = {}
279
+
280
+ def fake_request(method, endpoint, params=None, **kwargs):
281
+ captured["params"] = params
282
+ return {"_embedded": {"contacts": []}, "_page_count": 1}
283
+
284
+ monkeypatch.setattr(client, "_make_request", fake_request)
285
+ list(client.iter_contacts(query="7925", max_pages=1))
286
+ assert captured["params"]["query"] == "7925"
287
+
288
+
289
+ def test_iter_contacts_query_min_length(monkeypatch):
290
+ client = make_client()
291
+ captured = {}
292
+
293
+ def fake_request(method, endpoint, params=None, **kwargs):
294
+ captured["params"] = params
295
+ return {"_embedded": {"contacts": []}, "_page_count": 1}
296
+
297
+ monkeypatch.setattr(client, "_make_request", fake_request)
298
+ list(client.iter_contacts(query="7925", min_query_length=8, max_pages=1))
299
+ assert "query" not in captured["params"]
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