pytest-databases 0.2.4__tar.gz → 0.2.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 (49) hide show
  1. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/.pre-commit-config.yaml +1 -1
  2. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/CONTRIBUTING.rst +7 -11
  3. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/PKG-INFO +7 -2
  4. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/README.md +1 -0
  5. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/pyproject.toml +9 -5
  6. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/requirements/requirements-dev.txt +42 -12
  7. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/requirements/requirements-docs.txt +39 -9
  8. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/__init__.py +2 -4
  9. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/docker-compose.yml +26 -0
  10. pytest_databases-0.2.5/src/pytest_databases/docker/elastic_search.py +127 -0
  11. pytest_databases-0.2.5/tests/docker/test_elasticsearch.py +161 -0
  12. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/.gitignore +0 -0
  13. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/.sourcery.yaml +0 -0
  14. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/.vscode/settings.json +0 -0
  15. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/CODEOWNERS +0 -0
  16. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/LICENSE +0 -0
  17. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/Makefile +0 -0
  18. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/requirements/requirements.txt +0 -0
  19. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/scripts/__init__.py +0 -0
  20. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/scripts/build_docs.py +0 -0
  21. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/scripts/convert_docs.sh +0 -0
  22. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/sonar-project.properties +0 -0
  23. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/__init__.py +0 -0
  24. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/__metadata__.py +0 -0
  25. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/cockroachdb.py +0 -0
  26. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/dragonfly.py +0 -0
  27. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/keydb.py +0 -0
  28. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/mariadb.py +0 -0
  29. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/mssql.py +0 -0
  30. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/mysql.py +0 -0
  31. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/oracle.py +0 -0
  32. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/postgres.py +0 -0
  33. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/redis.py +0 -0
  34. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/docker/spanner.py +0 -0
  35. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/helpers.py +0 -0
  36. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/src/pytest_databases/py.typed +0 -0
  37. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/__init__.py +0 -0
  38. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/conftest.py +0 -0
  39. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/__init__.py +0 -0
  40. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_cockroachdb.py +0 -0
  41. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_dragonfly.py +0 -0
  42. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_keydb.py +0 -0
  43. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_mariadb.py +0 -0
  44. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_mssql.py +0 -0
  45. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_mysql.py +0 -0
  46. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_oracle.py +0 -0
  47. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_postgres.py +0 -0
  48. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_redis.py +0 -0
  49. {pytest_databases-0.2.4 → pytest_databases-0.2.5}/tests/docker/test_spanner.py +0 -0
@@ -2,7 +2,7 @@ exclude: "^docs/conf.py"
2
2
 
3
3
  repos:
4
4
  - repo: https://github.com/pre-commit/pre-commit-hooks
5
- rev: v4.5.0
5
+ rev: v4.6.0
6
6
  hooks:
7
7
  - id: trailing-whitespace
8
8
  - id: check-added-large-files
@@ -4,12 +4,12 @@ Contribution guide
4
4
  Setting up the environment
5
5
  --------------------------
6
6
 
7
- 1. Install `PDM <https://pdm.fming.dev/latest/>`_
8
- 2. Run ``pdm install -G:all`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install
9
- the dependencies
10
- 3. If you're working on the documentation and need to build it locally, install the extra dependencies with ``pdm install -G:docs``
11
- 4. Install `pre-commit <https://pre-commit.com/>`_
12
- 5. Run ``pre-commit install`` to install pre-commit hooks
7
+ 1. ``make install-pipx``
8
+ 2. ``make install-hatch``
9
+ 3. ``make configure-hatch``
10
+ 4. ``make install``
11
+ 5. Install `pre-commit <https://pre-commit.com/>`_
12
+ 6. ``pre-commit install``
13
13
 
14
14
  Code contributions
15
15
  ------------------
@@ -59,11 +59,7 @@ The documentation is located in the ``/docs`` directory and is `ReST <https://do
59
59
  Running the docs locally
60
60
  ++++++++++++++++++++++++
61
61
 
62
- To run or build the docs locally, you need to first install the required dependencies:
63
-
64
- ``pdm install -G:docs``
65
-
66
- Then you can serve the documentation with ``make docs-serve``, or build them with ``make docs``.
62
+ You can serve the documentation with ``make serve-docs``, or build them with ``make docs``.
67
63
 
68
64
  Creating a new release
69
65
  ----------------------
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-databases
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Reusable database fixtures for any and all databases.
5
5
  Project-URL: Documentation, https://github.com/litestar-org/pytest-databases#readme
6
6
  Project-URL: Issues, https://github.com/litestar-org/pytest-databases/issues
@@ -8,7 +8,7 @@ Project-URL: Source, https://github.com/litestar-org/pytest-databases
8
8
  Author-email: Cody Fincher <cody.fincher@gmail.com>
9
9
  License-Expression: MIT
10
10
  License-File: LICENSE
11
- Keywords: bigquery,cockroachdb,database,duckdb,migration,mssql,mysql,oracle,postgres,redis,spanner
11
+ Keywords: bigquery,cockroachdb,database,duckdb,elasticsearch,migration,mssql,mysql,oracle,postgres,redis,spanner
12
12
  Classifier: Development Status :: 4 - Beta
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3.8
@@ -24,6 +24,10 @@ Provides-Extra: cockroachdb
24
24
  Requires-Dist: psycopg; extra == 'cockroachdb'
25
25
  Provides-Extra: dragonfly
26
26
  Requires-Dist: redis; extra == 'dragonfly'
27
+ Provides-Extra: elasticsearch7
28
+ Requires-Dist: elasticsearch7[async]; extra == 'elasticsearch7'
29
+ Provides-Extra: elasticsearch8
30
+ Requires-Dist: elasticsearch8[async]; extra == 'elasticsearch8'
27
31
  Provides-Extra: keydb
28
32
  Requires-Dist: redis; extra == 'keydb'
29
33
  Provides-Extra: mssql
@@ -93,6 +97,7 @@ It is designed to offer pre-configured testing setups for many different types a
93
97
  - **Redis**: Latest server
94
98
  - **Dragonfly**: Latest server
95
99
  - **KeyDB**: Latest server
100
+ - **Elasticsearch**: Version 7 and 8 are available
96
101
 
97
102
  ## Contributing
98
103
 
@@ -49,6 +49,7 @@ It is designed to offer pre-configured testing setups for many different types a
49
49
  - **Redis**: Latest server
50
50
  - **Dragonfly**: Latest server
51
51
  - **KeyDB**: Latest server
52
+ - **Elasticsearch**: Version 7 and 8 are available
52
53
 
53
54
  ## Contributing
54
55
 
@@ -12,7 +12,7 @@ license = "MIT"
12
12
  name = "pytest-databases"
13
13
  readme = "README.md"
14
14
  requires-python = ">=3.8"
15
- version = "0.2.4"
15
+ version = "0.2.5"
16
16
  #
17
17
  authors = [{ name = "Cody Fincher", email = "cody.fincher@gmail.com" }]
18
18
  keywords = [
@@ -27,6 +27,7 @@ keywords = [
27
27
  "spanner",
28
28
  "cockroachdb",
29
29
  "redis",
30
+ "elasticsearch",
30
31
  ]
31
32
  # options under https://pypi.org/classifiers/
32
33
  classifiers = [
@@ -51,6 +52,8 @@ Source = "https://github.com/litestar-org/pytest-databases"
51
52
  [project.optional-dependencies]
52
53
  cockroachdb = ["psycopg"]
53
54
  dragonfly = ["redis"]
55
+ elasticsearch7 = ["elasticsearch7[async]"]
56
+ elasticsearch8 = ["elasticsearch8[async]"]
54
57
  keydb = ["redis"]
55
58
  mssql = ["aioodbc"]
56
59
  mysql = ["asyncmy>=0.2.9"]
@@ -101,7 +104,7 @@ extra-dependencies = [
101
104
  "pytest-click",
102
105
  "pytest-xdist",
103
106
  ]
104
- features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "spanner", "redis"]
107
+ features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "spanner", "redis", "elasticsearch7", "elasticsearch8"]
105
108
  template = "default"
106
109
  type = "virtual"
107
110
 
@@ -147,7 +150,7 @@ extra-dependencies = [
147
150
  "sphinxcontrib-mermaid>=0.9.2",
148
151
  "auto-pytabs[sphinx]>=0.4.0",
149
152
  ]
150
- features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "spanner", "redis"]
153
+ features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "spanner", "redis", "elasticsearch7", "elasticsearch8"]
151
154
  lock-filename = "requirements/requirements-docs.txt"
152
155
  pip-compile-constraint = "default"
153
156
  python = "3.11"
@@ -208,7 +211,7 @@ extra-dependencies = [
208
211
  "types-docutils",
209
212
  "types-redis",
210
213
  ]
211
- features = ["oracle", "mysql", "mssql", "postgres", "cockroachdb", "spanner", "redis"]
214
+ features = ["oracle", "mysql", "mssql", "postgres", "cockroachdb", "spanner", "redis", "elasticsearch7", "elasticsearch8"]
212
215
  lock-filename = "requirements/requirements-dev.txt"
213
216
  path = ".venv/"
214
217
  pip-compile-constraint = "docs"
@@ -236,7 +239,7 @@ extra-dependencies = [
236
239
  "types-docutils",
237
240
  "types-redis",
238
241
  ]
239
- features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "redis"]
242
+ features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "redis", "elasticsearch7", "elasticsearch8"]
240
243
  python = "3.11"
241
244
  template = "docs"
242
245
 
@@ -530,6 +533,7 @@ markers = [
530
533
  "spanner: Google Cloud Spanner Tests",
531
534
  "duckdb: DuckDB Tests",
532
535
  "mssql: Microsoft SQL Server Tests",
536
+ "elasticsearch: Elasticsearch Tests",
533
537
  ]
534
538
  minversion = "6.0"
535
539
  testpaths = ["tests"]
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # This file is autogenerated by hatch-pip-compile with Python 3.11
3
3
  #
4
- # [constraints] requirements/requirements-docs.txt (SHA256: a958627bb77a22b4985897b3caca965ef55f5c9d0f1477839af0ddc3d100cd1e)
4
+ # [constraints] requirements/requirements-docs.txt (SHA256: 9f7a8dd3e4bc82266beb5962c0cb3e3f2c508a1a44d0bebc5413327ebc29c57c)
5
5
  #
6
6
  # - nodeenv
7
7
  # - cython
@@ -39,6 +39,8 @@
39
39
  # - types-redis
40
40
  # - pytest
41
41
  # - psycopg
42
+ # - elasticsearch7[async]
43
+ # - elasticsearch8[async]
42
44
  # - aioodbc
43
45
  # - asyncmy>=0.2.9
44
46
  # - oracledb
@@ -49,7 +51,13 @@
49
51
 
50
52
  accessible-pygments==0.0.4
51
53
  # via pydata-sphinx-theme
54
+ aiohttp==3.9.3
55
+ # via
56
+ # elasticsearch7
57
+ # elasticsearch8
52
58
  aioodbc==0.5.0
59
+ aiosignal==1.3.1
60
+ # via aiohttp
53
61
  alabaster==0.7.16
54
62
  # via sphinx
55
63
  anyio==4.3.0
@@ -60,11 +68,15 @@ apeye-core==1.1.5
60
68
  astroid==3.1.0
61
69
  # via pylint
62
70
  async-timeout==4.0.3
63
- # via asyncpg
71
+ # via
72
+ # asyncpg
73
+ # redis
64
74
  asyncmy==0.2.9
65
75
  asyncpg==0.29.0
66
76
  # via asyncpg-stubs
67
77
  asyncpg-stubs==0.29.1
78
+ attrs==23.2.0
79
+ # via aiohttp
68
80
  auto-pytabs==0.4.0
69
81
  autodocsumm==0.2.12
70
82
  # via sphinx-toolbox
@@ -81,7 +93,10 @@ cachecontrol==0.14.0
81
93
  cachetools==5.3.3
82
94
  # via google-auth
83
95
  certifi==2024.2.2
84
- # via requests
96
+ # via
97
+ # elastic-transport
98
+ # elasticsearch7
99
+ # requests
85
100
  cffi==1.16.0
86
101
  # via cryptography
87
102
  cfgv==3.4.0
@@ -131,13 +146,21 @@ domdf-python-tools==3.8.0.post2
131
146
  # sphinx-toolbox
132
147
  duckdb==0.10.1
133
148
  # via harlequin
134
- execnet==2.0.2
149
+ elastic-transport==8.13.0
150
+ # via elasticsearch8
151
+ elasticsearch7==7.17.9
152
+ elasticsearch8==8.13.0
153
+ execnet==2.1.1
135
154
  # via pytest-xdist
136
- filelock==3.13.3
155
+ filelock==3.13.4
137
156
  # via
138
157
  # cachecontrol
139
158
  # sphinx-toolbox
140
159
  # virtualenv
160
+ frozenlist==1.4.1
161
+ # via
162
+ # aiohttp
163
+ # aiosignal
141
164
  google-api-core==2.18.0
142
165
  # via
143
166
  # google-cloud-core
@@ -212,7 +235,9 @@ mdurl==0.1.2
212
235
  msgpack==1.0.8
213
236
  # via cachecontrol
214
237
  multidict==6.0.5
215
- # via yarl
238
+ # via
239
+ # aiohttp
240
+ # yarl
216
241
  mypy==1.9.0
217
242
  mypy-extensions==1.0.0
218
243
  # via mypy
@@ -407,13 +432,13 @@ tree-sitter-languages==1.9.1
407
432
  # textual-textarea
408
433
  types-click==7.1.8
409
434
  types-decorator==5.1.8.20240310
410
- types-docutils==0.20.0.20240331
435
+ types-docutils==0.20.0.20240406
411
436
  types-pyopenssl==24.0.0.20240311
412
437
  # via types-redis
413
438
  types-pyyaml==6.0.12.20240311
414
- types-redis==4.6.0.20240311
439
+ types-redis==4.6.0.20240409
415
440
  types-six==1.16.21.20240311
416
- typing-extensions==4.10.0
441
+ typing-extensions==4.11.0
417
442
  # via
418
443
  # asyncpg-stubs
419
444
  # domdf-python-tools
@@ -425,8 +450,11 @@ typing-extensions==4.10.0
425
450
  # textual
426
451
  uc-micro-py==1.0.3
427
452
  # via linkify-it-py
428
- urllib3==2.2.1
429
- # via requests
453
+ urllib3==1.26.18
454
+ # via
455
+ # elastic-transport
456
+ # elasticsearch7
457
+ # requests
430
458
  vcrpy==6.0.1
431
459
  # via pytest-vcr
432
460
  virtualenv==20.25.1
@@ -440,4 +468,6 @@ wrapt==1.16.0
440
468
  # deprecated
441
469
  # vcrpy
442
470
  yarl==1.9.4
443
- # via vcrpy
471
+ # via
472
+ # aiohttp
473
+ # vcrpy
@@ -25,6 +25,8 @@
25
25
  # - auto-pytabs[sphinx]>=0.4.0
26
26
  # - pytest
27
27
  # - psycopg
28
+ # - elasticsearch7[async]
29
+ # - elasticsearch8[async]
28
30
  # - aioodbc
29
31
  # - asyncmy>=0.2.9
30
32
  # - oracledb
@@ -35,7 +37,13 @@
35
37
 
36
38
  accessible-pygments==0.0.4
37
39
  # via pydata-sphinx-theme
40
+ aiohttp==3.9.3
41
+ # via
42
+ # elasticsearch7
43
+ # elasticsearch8
38
44
  aioodbc==0.5.0
45
+ aiosignal==1.3.1
46
+ # via aiohttp
39
47
  alabaster==0.7.16
40
48
  # via sphinx
41
49
  anyio==4.3.0
@@ -44,9 +52,13 @@ apeye==1.4.1
44
52
  apeye-core==1.1.5
45
53
  # via apeye
46
54
  async-timeout==4.0.3
47
- # via asyncpg
55
+ # via
56
+ # asyncpg
57
+ # redis
48
58
  asyncmy==0.2.9
49
59
  asyncpg==0.29.0
60
+ attrs==23.2.0
61
+ # via aiohttp
50
62
  auto-pytabs==0.4.0
51
63
  autodocsumm==0.2.12
52
64
  # via sphinx-toolbox
@@ -63,7 +75,10 @@ cachecontrol==0.14.0
63
75
  cachetools==5.3.3
64
76
  # via google-auth
65
77
  certifi==2024.2.2
66
- # via requests
78
+ # via
79
+ # elastic-transport
80
+ # elasticsearch7
81
+ # requests
67
82
  cffi==1.16.0
68
83
  # via cryptography
69
84
  charset-normalizer==3.3.2
@@ -99,12 +114,20 @@ domdf-python-tools==3.8.0.post2
99
114
  # apeye-core
100
115
  # dict2css
101
116
  # sphinx-toolbox
102
- execnet==2.0.2
117
+ elastic-transport==8.13.0
118
+ # via elasticsearch8
119
+ elasticsearch7==7.17.9
120
+ elasticsearch8==8.13.0
121
+ execnet==2.1.1
103
122
  # via pytest-xdist
104
- filelock==3.13.3
123
+ filelock==3.13.4
105
124
  # via
106
125
  # cachecontrol
107
126
  # sphinx-toolbox
127
+ frozenlist==1.4.1
128
+ # via
129
+ # aiohttp
130
+ # aiosignal
108
131
  google-api-core==2.18.0
109
132
  # via
110
133
  # google-cloud-core
@@ -160,7 +183,9 @@ markupsafe==2.1.5
160
183
  msgpack==1.0.8
161
184
  # via cachecontrol
162
185
  multidict==6.0.5
163
- # via yarl
186
+ # via
187
+ # aiohttp
188
+ # yarl
164
189
  natsort==8.4.0
165
190
  # via domdf-python-tools
166
191
  nodeenv==1.8.0
@@ -298,14 +323,17 @@ termcolor==2.4.0
298
323
  # via pytest-sugar
299
324
  tornado==6.4
300
325
  # via livereload
301
- typing-extensions==4.10.0
326
+ typing-extensions==4.11.0
302
327
  # via
303
328
  # domdf-python-tools
304
329
  # psycopg
305
330
  # pydata-sphinx-theme
306
331
  # sphinx-toolbox
307
- urllib3==2.2.1
308
- # via requests
332
+ urllib3==1.26.18
333
+ # via
334
+ # elastic-transport
335
+ # elasticsearch7
336
+ # requests
309
337
  vcrpy==6.0.1
310
338
  # via pytest-vcr
311
339
  webencodings==0.5.1
@@ -315,4 +343,6 @@ wrapt==1.16.0
315
343
  # deprecated
316
344
  # vcrpy
317
345
  yarl==1.9.4
318
- # via vcrpy
346
+ # via
347
+ # aiohttp
348
+ # vcrpy
@@ -67,9 +67,7 @@ async def wait_until_responsive(
67
67
 
68
68
 
69
69
  SKIP_DOCKER_COMPOSE: bool = bool(os.environ.get("SKIP_DOCKER_COMPOSE", False))
70
- USE_LEGACY_DOCKER_COMPOSE: bool = bool(
71
- os.environ.get("USE_LEGACY_DOCKER_COMPOSE", os.getenv("GITHUB_ACTIONS") != "true")
72
- )
70
+ USE_LEGACY_DOCKER_COMPOSE: bool = bool(os.environ.get("USE_LEGACY_DOCKER_COMPOSE", False))
73
71
  COMPOSE_PROJECT_NAME: str = f"pytest-databases-{simple_string_hash(__file__)}"
74
72
 
75
73
 
@@ -125,7 +123,7 @@ class DockerServiceRegistry:
125
123
  )
126
124
 
127
125
  def stop(self, name: str) -> None:
128
- pass
126
+ self.run_command("down", "--remove-orphans", "--volumes", "-t", "10", name)
129
127
 
130
128
  def down(self) -> None:
131
129
  if not SKIP_DOCKER_COMPOSE:
@@ -176,6 +176,32 @@ services:
176
176
  # network_mode: "host"
177
177
  volumes:
178
178
  - dragonflydata:/data
179
+ elasticsearch7:
180
+ image: elasticsearch:7.17.19
181
+ ports:
182
+ - 9200:9200
183
+ - 9301:9300
184
+ environment:
185
+ - discovery.type=single-node
186
+ - xpack.security.enabled=false
187
+ healthcheck:
188
+ test: curl -s http://localhost:9200 >/dev/null || exit 1
189
+ interval: 30s
190
+ timeout: 10s
191
+ retries: 50
192
+ elasticsearch8:
193
+ image: elasticsearch:8.13.0
194
+ ports:
195
+ - 9201:9200
196
+ - 9300:9300
197
+ environment:
198
+ - discovery.type=single-node
199
+ - xpack.security.enabled=false
200
+ healthcheck:
201
+ test: curl -s http://localhost:9200 >/dev/null || exit 1
202
+ interval: 30s
203
+ timeout: 10s
204
+ retries: 50
179
205
  networks:
180
206
  default:
181
207
  driver: bridge
@@ -0,0 +1,127 @@
1
+ # MIT License
2
+
3
+ # Copyright (c) 2024 Litestar
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+
24
+ from __future__ import annotations
25
+
26
+ from typing import TYPE_CHECKING
27
+
28
+ import pytest
29
+ from elasticsearch7 import AsyncElasticsearch as Elasticsearch7
30
+ from elasticsearch7 import AsyncElasticsearch as Elasticsearch8
31
+
32
+ if TYPE_CHECKING:
33
+ from pytest_databases.docker import DockerServiceRegistry
34
+
35
+
36
+ async def elasticsearch7_responsive(scheme: str, host: str, port: int, user: str, password: str, database: str) -> bool:
37
+ try:
38
+ async with Elasticsearch7(
39
+ hosts=[{"host": host, "port": port, "scheme": scheme}], verify_certs=False, http_auth=(user, password)
40
+ ) as client:
41
+ return await client.ping()
42
+ except Exception: # noqa: BLE001
43
+ return False
44
+
45
+
46
+ async def elasticsearch8_responsive(scheme: str, host: str, port: int, user: str, password: str, database: str) -> bool:
47
+ try:
48
+ async with Elasticsearch8(
49
+ hosts=[{"host": host, "port": port, "scheme": scheme}], verify_certs=False, basic_auth=(user, password)
50
+ ) as client:
51
+ return await client.ping()
52
+ except Exception: # noqa: BLE001
53
+ return False
54
+
55
+
56
+ @pytest.fixture
57
+ def elasticsearch_user() -> str:
58
+ return "elastic"
59
+
60
+
61
+ @pytest.fixture
62
+ def elasticsearch_password() -> str:
63
+ return "changeme"
64
+
65
+
66
+ @pytest.fixture
67
+ def elasticsearch_database() -> str:
68
+ return "db"
69
+
70
+
71
+ @pytest.fixture
72
+ def elasticsearch_scheme() -> str:
73
+ return "http"
74
+
75
+
76
+ @pytest.fixture
77
+ def elasticsearch7_port() -> int:
78
+ return 9200
79
+
80
+
81
+ @pytest.fixture
82
+ def elasticsearch8_port() -> int:
83
+ return 9201
84
+
85
+
86
+ @pytest.fixture
87
+ async def elasticsearch7_service(
88
+ docker_services: DockerServiceRegistry,
89
+ elasticsearch7_port: int,
90
+ elasticsearch_database: str,
91
+ elasticsearch_user: str,
92
+ elasticsearch_password: str,
93
+ elasticsearch_scheme: str,
94
+ ) -> None:
95
+ await docker_services.start(
96
+ "elasticsearch7",
97
+ timeout=45,
98
+ pause=1,
99
+ check=elasticsearch7_responsive,
100
+ port=elasticsearch7_port,
101
+ database=elasticsearch_database,
102
+ user=elasticsearch_user,
103
+ password=elasticsearch_password,
104
+ scheme=elasticsearch_scheme,
105
+ )
106
+
107
+
108
+ @pytest.fixture
109
+ async def elasticsearch8_service(
110
+ docker_services: DockerServiceRegistry,
111
+ elasticsearch8_port: int,
112
+ elasticsearch_database: str,
113
+ elasticsearch_user: str,
114
+ elasticsearch_password: str,
115
+ elasticsearch_scheme: str,
116
+ ) -> None:
117
+ await docker_services.start(
118
+ "elasticsearch8",
119
+ timeout=45,
120
+ pause=1,
121
+ check=elasticsearch8_responsive,
122
+ port=elasticsearch8_port,
123
+ database=elasticsearch_database,
124
+ user=elasticsearch_user,
125
+ password=elasticsearch_password,
126
+ scheme=elasticsearch_scheme,
127
+ )
@@ -0,0 +1,161 @@
1
+ # MIT License
2
+
3
+ # Copyright (c) 2024 Litestar
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+
24
+ from __future__ import annotations
25
+
26
+ from typing import TYPE_CHECKING, Any, AsyncGenerator, Callable
27
+ from unittest import mock
28
+
29
+ import pytest
30
+ from elasticsearch7 import AsyncElasticsearch as Elasticsearch7
31
+ from elasticsearch8 import AsyncElasticsearch as Elasticsearch8
32
+
33
+ from pytest_databases.docker.elastic_search import elasticsearch7_responsive, elasticsearch8_responsive
34
+
35
+ if TYPE_CHECKING:
36
+ from pytest_databases.docker import DockerServiceRegistry
37
+
38
+ pytestmark = pytest.mark.anyio
39
+ pytest_plugins = [
40
+ "pytest_databases.docker.elastic_search",
41
+ ]
42
+
43
+
44
+ @pytest.fixture
45
+ async def elasticsearch7_service(
46
+ docker_services: DockerServiceRegistry,
47
+ elasticsearch7_port: int,
48
+ elasticsearch_database: str,
49
+ elasticsearch_user: str,
50
+ elasticsearch_password: str,
51
+ elasticsearch_scheme: str,
52
+ ) -> AsyncGenerator[Any, Any]:
53
+ """Overwrites fixture to stop container after the test."""
54
+ try:
55
+ await docker_services.start(
56
+ "elasticsearch7",
57
+ timeout=45,
58
+ pause=1,
59
+ check=elasticsearch7_responsive,
60
+ port=elasticsearch7_port,
61
+ database=elasticsearch_database,
62
+ user=elasticsearch_user,
63
+ password=elasticsearch_password,
64
+ scheme=elasticsearch_scheme,
65
+ )
66
+ yield
67
+ finally:
68
+ docker_services.stop("elasticsearch7")
69
+
70
+
71
+ @pytest.fixture
72
+ async def elasticsearch8_service(
73
+ docker_services: DockerServiceRegistry,
74
+ elasticsearch8_port: int,
75
+ elasticsearch_database: str,
76
+ elasticsearch_user: str,
77
+ elasticsearch_password: str,
78
+ elasticsearch_scheme: str,
79
+ ) -> AsyncGenerator[Any, Any]:
80
+ """Overwrites fixture to stop container after the test."""
81
+ try:
82
+ await docker_services.start(
83
+ "elasticsearch8",
84
+ timeout=45,
85
+ pause=1,
86
+ check=elasticsearch8_responsive,
87
+ port=elasticsearch8_port,
88
+ database=elasticsearch_database,
89
+ user=elasticsearch_user,
90
+ password=elasticsearch_password,
91
+ scheme=elasticsearch_scheme,
92
+ )
93
+ yield
94
+ finally:
95
+ docker_services.stop("elasticsearch8")
96
+
97
+
98
+ def test_elasticsearch7_default_config(
99
+ elasticsearch7_port: str, elasticsearch_user: str, elasticsearch_password: str, elasticsearch_scheme: str
100
+ ) -> None:
101
+ assert elasticsearch7_port == 9200
102
+ assert elasticsearch_user == "elastic"
103
+ assert elasticsearch_password == "changeme"
104
+ assert elasticsearch_scheme == "http"
105
+
106
+
107
+ def test_elasticsearch8_default_config(
108
+ elasticsearch8_port: str, elasticsearch_user: str, elasticsearch_password: str, elasticsearch_scheme: str
109
+ ) -> None:
110
+ assert elasticsearch8_port == 9201
111
+ assert elasticsearch_user == "elastic"
112
+ assert elasticsearch_password == "changeme"
113
+ assert elasticsearch_scheme == "http"
114
+
115
+
116
+ async def test_elasticsearch7_service(
117
+ docker_ip: str,
118
+ elasticsearch7_service: DockerServiceRegistry,
119
+ elasticsearch7_port: str,
120
+ elasticsearch_user: str,
121
+ elasticsearch_password: str,
122
+ elasticsearch_scheme: str,
123
+ ) -> None:
124
+ async with Elasticsearch7(
125
+ hosts=[{"host": docker_ip, "port": elasticsearch7_port, "scheme": elasticsearch_scheme}],
126
+ verify_certs=False,
127
+ http_auth=(elasticsearch_user, elasticsearch_password),
128
+ ) as client:
129
+ info = await client.info()
130
+
131
+ assert info["version"]["number"] == "7.17.19"
132
+
133
+
134
+ async def test_elasticsearch8_service(
135
+ docker_ip: str,
136
+ elasticsearch8_service: DockerServiceRegistry,
137
+ elasticsearch8_port: str,
138
+ elasticsearch_user: str,
139
+ elasticsearch_password: str,
140
+ elasticsearch_scheme: str,
141
+ ) -> None:
142
+ async with Elasticsearch8(
143
+ hosts=[{"host": docker_ip, "port": elasticsearch8_port, "scheme": elasticsearch_scheme}],
144
+ verify_certs=False,
145
+ basic_auth=(elasticsearch_user, elasticsearch_password),
146
+ ) as client:
147
+ info = await client.info()
148
+
149
+ assert info["version"]["number"] == "8.13.0"
150
+
151
+
152
+ @pytest.mark.parametrize(
153
+ "responsive, path_to_mock",
154
+ (
155
+ (elasticsearch7_responsive, "pytest_databases.docker.elastic_search.Elasticsearch7.ping"),
156
+ (elasticsearch8_responsive, "pytest_databases.docker.elastic_search.Elasticsearch8.ping"),
157
+ ),
158
+ )
159
+ async def test_elasticsearch_responsive(responsive: Callable, path_to_mock: str) -> None:
160
+ with mock.patch(path_to_mock, mock.Mock(side_effect=Exception)):
161
+ assert not await responsive(scheme="", host="", port="", user="", password="", database="")