weaviate-cli 3.1.4__tar.gz → 3.2.1__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 (71) hide show
  1. weaviate_cli-3.2.1/.github/workflows/main.yaml +132 -0
  2. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/PKG-INFO +6 -3
  3. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/README.md +1 -0
  4. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/requirements-dev.txt +2 -1
  5. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/setup.cfg +2 -1
  6. weaviate_cli-3.2.1/test/integration/test_auth_integration.py +56 -0
  7. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/integration/test_integration.py +1 -6
  8. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/test_defaults.py +17 -5
  9. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/test_managers/test_collection_manager.py +2 -1
  10. weaviate_cli-3.2.1/test/unittests/test_managers/test_config_manager.py +264 -0
  11. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/test_managers/test_data_manager.py +1 -0
  12. weaviate_cli-3.2.1/test/unittests/test_managers/test_user_manager.py +325 -0
  13. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/test_utils.py +16 -0
  14. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/assign.py +12 -2
  15. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/create.py +90 -0
  16. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/delete.py +47 -2
  17. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/get.py +53 -15
  18. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/query.py +7 -1
  19. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/revoke.py +12 -2
  20. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/update.py +135 -2
  21. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/defaults.py +32 -9
  22. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/collection_manager.py +25 -5
  23. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/config_manager.py +62 -2
  24. weaviate_cli-3.2.1/weaviate_cli/managers/data_manager.py +1248 -0
  25. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/role_manager.py +18 -5
  26. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/tenant_manager.py +56 -48
  27. weaviate_cli-3.2.1/weaviate_cli/managers/user_manager.py +173 -0
  28. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/utils.py +29 -11
  29. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli.egg-info/PKG-INFO +6 -3
  30. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli.egg-info/SOURCES.txt +2 -0
  31. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli.egg-info/requires.txt +2 -1
  32. weaviate_cli-3.1.4/.github/workflows/main.yaml +0 -77
  33. weaviate_cli-3.1.4/test/unittests/test_managers/test_config_manager.py +0 -141
  34. weaviate_cli-3.1.4/weaviate_cli/managers/data_manager.py +0 -637
  35. weaviate_cli-3.1.4/weaviate_cli/managers/user_manager.py +0 -54
  36. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/.github/dependabot.yml +0 -0
  37. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/.github/workflows/release.yaml +0 -0
  38. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/.gitignore +0 -0
  39. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/.pre-commit-config.yaml +0 -0
  40. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/CONTRIBUTING.md +0 -0
  41. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/Dockerfile +0 -0
  42. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/LICENSE +0 -0
  43. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/MANIFEST.in +0 -0
  44. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/Makefile +0 -0
  45. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/cli.py +0 -0
  46. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/publish.md +0 -0
  47. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/pyproject.toml +0 -0
  48. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/setup.py +0 -0
  49. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/README.md +0 -0
  50. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/__init__.py +0 -0
  51. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/conftest.py +0 -0
  52. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/test_cli.py +0 -0
  53. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/test_managers/test_node_manager.py +0 -0
  54. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/test/unittests/test_managers/test_shard_manager.py +0 -0
  55. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/__init__.py +0 -0
  56. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/__init__.py +0 -0
  57. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/cancel.py +0 -0
  58. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/commands/restore.py +0 -0
  59. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/completion/__init__.py +0 -0
  60. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/completion/complete.py +0 -0
  61. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/datasets/__init__.py +0 -0
  62. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/datasets/movies.json +0 -0
  63. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/__init__.py +0 -0
  64. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/backup_manager.py +0 -0
  65. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/node_manager.py +0 -0
  66. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/managers/shard_manager.py +0 -0
  67. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli/types/models.py +0 -0
  68. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli.egg-info/dependency_links.txt +0 -0
  69. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli.egg-info/entry_points.txt +0 -0
  70. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli.egg-info/not-zip-safe +0 -0
  71. {weaviate_cli-3.1.4 → weaviate_cli-3.2.1}/weaviate_cli.egg-info/top_level.txt +0 -0
@@ -0,0 +1,132 @@
1
+ name: Main
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ lint-and-format:
11
+ name: Run Linter and Formatter
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.11"
18
+ - run: pip install -r requirements-dev.txt
19
+ - name: "Black"
20
+ run: black --check cli.py weaviate_cli test
21
+ - name: "Check release for pypi"
22
+ run: |
23
+ python -m build
24
+ python -m twine check dist/*
25
+
26
+ unit-tests:
27
+ name: Run Unit Tests
28
+ needs: [lint-and-format]
29
+ runs-on: ubuntu-latest
30
+ strategy:
31
+ matrix:
32
+ version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+ - uses: actions/setup-python@v5
36
+ with:
37
+ python-version: ${{ matrix.version }}
38
+ - run: pip install -e .
39
+ - name: Run unit tests with pytest
40
+ run: |
41
+ pip install pytest-html
42
+ pytest test/unittests --html=test-report-${{ matrix.version }}.html --self-contained-html
43
+ - name: Upload test results
44
+ if: always()
45
+ uses: actions/upload-artifact@v4
46
+ with:
47
+ name: test-results-${{ matrix.version }}
48
+ path: test-report-${{ matrix.version }}.html
49
+
50
+ get-latest-weaviate-version:
51
+ runs-on: ubuntu-latest
52
+ needs: [unit-tests]
53
+ name: Get latest Weaviate version
54
+ outputs:
55
+ LATEST_WEAVIATE_VERSION: ${{ steps.latest-version.outputs.latest_weaviate_version }}
56
+ steps:
57
+ - name: Retrieve latest Weaviate version
58
+ id: latest-version
59
+ uses: weaviate/github-common-actions/.github/actions/get-latest-weaviate-version@main
60
+
61
+ integration-tests:
62
+ needs: [unit-tests, get-latest-weaviate-version]
63
+ env:
64
+ WEAVIATE_VERSION: ${{ needs.get-latest-weaviate-version.outputs.LATEST_WEAVIATE_VERSION }}
65
+ MODULES: "text2vec-transformers,text2vec-contextionary"
66
+ name: Run Integration Tests
67
+ runs-on: ubuntu-latest
68
+ strategy:
69
+ matrix:
70
+ version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
71
+ steps:
72
+ - uses: actions/checkout@v4
73
+ - uses: actions/setup-python@v5
74
+ with:
75
+ python-version: ${{ matrix.version }}
76
+ - run: pip install -e .
77
+ - name: Start up Weaviate cluster
78
+ uses: weaviate/weaviate-local-k8s@v2
79
+ with:
80
+ workers: 1
81
+ replicas: 1
82
+ weaviate-version: ${{ env.WEAVIATE_VERSION }}
83
+ modules: ${{ env.MODULES }}
84
+ enable-backup: true
85
+ dynamic-users: true
86
+ - name: Run integration tests with pytest
87
+ run: |
88
+ pip install pytest-html
89
+ pytest test/integration/test_integration.py --html=test-report-${{ matrix.version }}.html --self-contained-html
90
+ integration-auth-tests:
91
+ needs: [unit-tests, get-latest-weaviate-version]
92
+ env:
93
+ WEAVIATE_VERSION: ${{ needs.get-latest-weaviate-version.outputs.LATEST_WEAVIATE_VERSION }}
94
+ MODULES: "text2vec-transformers,text2vec-contextionary"
95
+ name: Run Integration Tests Auth
96
+ runs-on: ubuntu-latest
97
+ strategy:
98
+ matrix:
99
+ version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
100
+ steps:
101
+ - uses: actions/checkout@v4
102
+ - uses: actions/setup-python@v5
103
+ with:
104
+ python-version: ${{ matrix.version }}
105
+ - run: pip install -e .
106
+ - name: Start up Weaviate cluster
107
+ uses: weaviate/weaviate-local-k8s@v2
108
+ with:
109
+ workers: 1
110
+ replicas: 1
111
+ weaviate-version: ${{ env.WEAVIATE_VERSION }}
112
+ modules: ${{ env.MODULES }}
113
+ enable-backup: true
114
+ rbac: true
115
+ dynamic-users: true
116
+ - name: Create config directory
117
+ run: mkdir -p ~/.config/weaviate
118
+ - name: Create config file
119
+ run: |
120
+ echo '{
121
+ "host": "localhost",
122
+ "http_port": "8080",
123
+ "grpc_port": "50051",
124
+ "auth": {
125
+ "type": "api_key",
126
+ "api_key": "admin-key"
127
+ }
128
+ }' > ~/.config/weaviate/config.json
129
+ - name: Run integration auth tests with pytest
130
+ run: |
131
+ pip install pytest-html
132
+ pytest test/integration/test_auth_integration.py --html=test-auth-report-${{ matrix.version }}.html --self-contained-html
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: weaviate-cli
3
- Version: 3.1.4
3
+ Version: 3.2.1
4
4
  Summary: Command line interface to interact with weaviate
5
5
  Home-page: https://github.com/weaviate/weaviate-cli
6
6
  Download-URL: https://github.com/weaviate/weaviate-cli
@@ -28,13 +28,15 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
28
28
  Requires-Python: >=3.9
29
29
  Description-Content-Type: text/markdown
30
30
  License-File: LICENSE
31
- Requires-Dist: weaviate-client>=4.11.0
31
+ Requires-Dist: weaviate-client>=4.14.3
32
32
  Requires-Dist: click==8.1.7
33
33
  Requires-Dist: semver>=3.0.2
34
34
  Requires-Dist: numpy>=1.24.0
35
35
  Requires-Dist: importlib-resources>=5.0.0
36
36
  Requires-Dist: prettytable>=3.1.0
37
+ Requires-Dist: faker>=20.0.0
37
38
  Dynamic: download-url
39
+ Dynamic: license-file
38
40
 
39
41
  # Weaviate CLI
40
42
 
@@ -118,6 +120,7 @@ The configuration file should be a JSON file with the following structure:
118
120
  "host": "your-weaviate-host",
119
121
  "http_port": "your-http-port",
120
122
  "grpc_port": "your-grpc-port",
123
+ "grpc_host": "your-grpc-host",
121
124
  "auth": {
122
125
  "type": "api_key",
123
126
  "api_key": "your-api-key"
@@ -80,6 +80,7 @@ The configuration file should be a JSON file with the following structure:
80
80
  "host": "your-weaviate-host",
81
81
  "http_port": "your-http-port",
82
82
  "grpc_port": "your-grpc-port",
83
+ "grpc_host": "your-grpc-host",
83
84
  "auth": {
84
85
  "type": "api_key",
85
86
  "api_key": "your-api-key"
@@ -1,4 +1,4 @@
1
- weaviate-client>=4.11.0
1
+ weaviate-client>=4.14.3
2
2
  click==8.1.7
3
3
  twine
4
4
  pytest
@@ -12,3 +12,4 @@ setuptools_scm
12
12
  black==24.3.0
13
13
  pre-commit==3.6.2
14
14
  prettytable>=3.1.0
15
+ faker>=20.0.0
@@ -36,12 +36,13 @@ classifiers =
36
36
  include_package_data = True
37
37
  python_requires = >=3.9
38
38
  install_requires =
39
- weaviate-client>=4.11.0
39
+ weaviate-client>=4.14.3
40
40
  click==8.1.7
41
41
  semver>=3.0.2
42
42
  numpy>=1.24.0
43
43
  importlib-resources>=5.0.0
44
44
  prettytable>=3.1.0
45
+ faker>=20.0.0
45
46
  setup_requires =
46
47
  pip
47
48
  setuptools
@@ -0,0 +1,56 @@
1
+ import pytest
2
+ import weaviate
3
+ import click
4
+ from click.testing import CliRunner
5
+ from weaviate_cli.managers.collection_manager import CollectionManager
6
+ from weaviate_cli.managers.config_manager import ConfigManager
7
+ from weaviate_cli.managers.user_manager import UserManager
8
+ import weaviate.classes.config as wvc
9
+
10
+
11
+ @pytest.fixture
12
+ def client() -> weaviate.Client:
13
+ config = ConfigManager()
14
+ return config.get_client()
15
+
16
+
17
+ @pytest.fixture
18
+ def collection_manager(client: weaviate.Client) -> CollectionManager:
19
+ return CollectionManager(client)
20
+
21
+
22
+ @pytest.fixture
23
+ def user_manager(client: weaviate.Client) -> UserManager:
24
+ return UserManager(client)
25
+
26
+
27
+ def test_user_lifecycle(user_manager: UserManager):
28
+ try:
29
+ user_name = "test_user"
30
+ # Create user
31
+ api_key = user_manager.create_user(user_name=user_name)
32
+ assert user_name in [user.user_id for user in user_manager.get_all_users()]
33
+ assert api_key is not None
34
+
35
+ # Update user
36
+ new_api_key = user_manager.update_user(user_name=user_name, rotate_api_key=True)
37
+ assert new_api_key is not None
38
+ assert new_api_key != api_key
39
+
40
+ # Deactivate user
41
+ user_manager.update_user(user_name=user_name, deactivate=True)
42
+ user = user_manager.get_user(user_name=user_name)
43
+ assert not user.active
44
+
45
+ # Activate user
46
+ user_manager.update_user(user_name=user_name, activate=True)
47
+ user = user_manager.get_user(user_name=user_name)
48
+ assert user.active
49
+
50
+ # Print user
51
+ user_manager.print_user(user=user_name)
52
+
53
+ finally:
54
+ # Delete user
55
+ user_manager.delete_user(user_name=user_name)
56
+ assert user_name not in [user.user_id for user in user_manager.get_all_users()]
@@ -1,6 +1,5 @@
1
1
  import pytest
2
2
  import weaviate
3
- import click
4
3
  from click.testing import CliRunner
5
4
  from weaviate_cli.managers.collection_manager import CollectionManager
6
5
  from weaviate_cli.managers.config_manager import ConfigManager
@@ -12,11 +11,7 @@ import weaviate.classes.config as wvc
12
11
  @pytest.fixture
13
12
  def client() -> weaviate.Client:
14
13
  config = ConfigManager()
15
- return weaviate.connect_to_local(
16
- host=config.config["host"],
17
- port=int(config.config["http_port"]),
18
- grpc_port=int(config.config["grpc_port"]),
19
- )
14
+ return config.get_client()
20
15
 
21
16
 
22
17
  @pytest.fixture
@@ -92,7 +92,7 @@ def test_create_tenants_defaults(runner):
92
92
  mock_collection.tenants.get.return_value = empty_tenants
93
93
 
94
94
  mock_tenants = {
95
- f"{CreateTenantsDefaults.tenant_suffix}{i}": MagicMock(
95
+ f"{CreateTenantsDefaults.tenant_suffix}-{i}": MagicMock(
96
96
  activity_status=TenantActivityStatus.ACTIVE
97
97
  )
98
98
  for i in range(CreateTenantsDefaults.number_tenants)
@@ -134,7 +134,19 @@ def test_create_data_defaults(runner):
134
134
  # Create mock context with config
135
135
  ctx = click.Context(create_data_cli)
136
136
  ctx.obj = {"config": MagicMock()}
137
- ctx.obj["config"].get_client = MagicMock()
137
+ mock_client = MagicMock()
138
+ mock_client.collections.exists.return_value = True
139
+
140
+ # Mock collection object
141
+ mock_collection = MagicMock()
142
+ mock_client.collections.get.return_value = mock_collection
143
+
144
+ # Mock multi-tenancy config
145
+ mock_config = MagicMock()
146
+ mock_config.multi_tenancy_config.enabled = False
147
+ mock_collection.config.get.return_value = mock_config
148
+
149
+ ctx.obj["config"].get_client.return_value = mock_client
138
150
 
139
151
  result = runner.invoke(create_data_cli, obj=ctx.obj)
140
152
  assert result.exit_code == 0, result.output
@@ -179,7 +191,7 @@ def test_delete_tenants_defaults(runner):
179
191
 
180
192
  # Mock tenants with side effect to return different values on subsequent calls
181
193
  mock_tenants = {
182
- f"{DeleteTenantsDefaults.tenant_suffix}{i}": MagicMock()
194
+ f"{DeleteTenantsDefaults.tenant_suffix}-{i}": MagicMock()
183
195
  for i in range(1, DeleteTenantsDefaults.number_tenants + 1)
184
196
  }
185
197
  empty_tenants = {}
@@ -365,7 +377,7 @@ def test_update_tenants_defaults(runner):
365
377
 
366
378
  # Mock tenants with side effect to return different values on subsequent calls
367
379
  mock_tenants = {
368
- f"{UpdateTenantsDefaults.tenant_suffix}{i}": MagicMock(
380
+ f"{UpdateTenantsDefaults.tenant_suffix}-{i}": MagicMock(
369
381
  activity_status=TenantActivityStatus.ACTIVE
370
382
  )
371
383
  for i in range(UpdateTenantsDefaults.number_tenants)
@@ -373,7 +385,7 @@ def test_update_tenants_defaults(runner):
373
385
  mock_collection.tenants.get.return_value = mock_tenants
374
386
 
375
387
  updated_tenants = {
376
- f"{UpdateTenantsDefaults.tenant_suffix}{i}": MagicMock(
388
+ f"{UpdateTenantsDefaults.tenant_suffix}-{i}": MagicMock(
377
389
  activity_status=TenantActivityStatus.ACTIVE
378
390
  )
379
391
  for i in range(UpdateTenantsDefaults.number_tenants)
@@ -146,6 +146,7 @@ def test_update_collection(mock_client):
146
146
  description="Updated description",
147
147
  vector_index="hnsw",
148
148
  async_enabled=True,
149
+ replication_factor=5,
149
150
  auto_tenant_creation=True,
150
151
  auto_tenant_activation=True,
151
152
  replication_deletion_strategy="delete_on_conflict",
@@ -157,7 +158,7 @@ def test_update_collection(mock_client):
157
158
  == "Updated description"
158
159
  )
159
160
  assert (
160
- mock_collection.config.update.call_args.kwargs["replication_config"].factor == 3
161
+ mock_collection.config.update.call_args.kwargs["replication_config"].factor == 5
161
162
  )
162
163
  assert (
163
164
  mock_collection.config.update.call_args.kwargs[
@@ -0,0 +1,264 @@
1
+ import socket
2
+ import pytest
3
+ import weaviate
4
+ from unittest.mock import MagicMock, mock_open, patch
5
+ from weaviate_cli.managers.config_manager import ConfigManager
6
+ import json
7
+
8
+
9
+ def test_init_with_config_file():
10
+ config_data = {"host": "localhost", "http_port": "8080", "grpc_port": "50051"}
11
+
12
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
13
+ with patch("os.path.isfile") as mock_isfile:
14
+ mock_isfile.return_value = True
15
+ config = ConfigManager(config_file="test_config.json")
16
+ assert config.config == config_data
17
+
18
+
19
+ def test_create_default_config():
20
+ with patch("pathlib.Path.exists") as mock_exists:
21
+ mock_exists.return_value = False
22
+ config = ConfigManager()
23
+ assert config.config["host"] == "localhost"
24
+ assert config.config["http_port"] == "8080"
25
+ assert config.config["grpc_port"] == "50051"
26
+
27
+
28
+ @patch("socket.create_connection")
29
+ def test_check_host_docker_internal(mock_socket):
30
+ config = ConfigManager()
31
+
32
+ # Test successful connection
33
+ mock_socket.return_value = MagicMock()
34
+ assert config._ConfigManager__check_host_docker_internal() == True
35
+
36
+
37
+ @patch("socket.create_connection")
38
+ def test_check_host_docker_internal_failed(mock_socket):
39
+ config = ConfigManager()
40
+
41
+ # Test failed connection
42
+ mock_socket.side_effect = socket.error()
43
+ assert config._ConfigManager__check_host_docker_internal() == False
44
+
45
+
46
+ def test_init_with_user():
47
+ config_data = {
48
+ "host": "localhost",
49
+ "http_port": "8080",
50
+ "grpc_port": "50051",
51
+ "auth": {"type": "user", "admin": "admin-key", "jose": "jose-key"},
52
+ }
53
+
54
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
55
+ with patch("os.path.isfile") as mock_isfile:
56
+ mock_isfile.return_value = True
57
+ config = ConfigManager(config_file="test_config.json", user="jose")
58
+ assert config.user == "jose"
59
+ assert config.config == config_data
60
+
61
+
62
+ def test_get_client_with_user_auth():
63
+ config_data = {
64
+ "host": "localhost",
65
+ "http_port": "8080",
66
+ "grpc_port": "50051",
67
+ "auth": {"type": "user", "admin": "admin-key", "jose": "jose-key"},
68
+ }
69
+
70
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
71
+ with patch("os.path.isfile") as mock_isfile:
72
+ mock_isfile.return_value = True
73
+ with patch("weaviate.connect_to_local") as mock_connect:
74
+ config = ConfigManager(config_file="test_config.json", user="jose")
75
+ config.get_client()
76
+
77
+ mock_connect.assert_called_once()
78
+ call_kwargs = mock_connect.call_args.kwargs
79
+ assert isinstance(
80
+ call_kwargs["auth_credentials"], weaviate.auth.AuthApiKey
81
+ )
82
+ assert call_kwargs["auth_credentials"].api_key == "jose-key"
83
+
84
+
85
+ def test_get_client_with_invalid_user():
86
+ config_data = {
87
+ "host": "localhost",
88
+ "http_port": "8080",
89
+ "grpc_port": "50051",
90
+ "auth": {"type": "user", "admin": "admin-key"},
91
+ }
92
+
93
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
94
+ with patch("os.path.isfile") as mock_isfile:
95
+ mock_isfile.return_value = True
96
+ config = ConfigManager(config_file="test_config.json", user="jose")
97
+ with pytest.raises(Exception) as exc_info:
98
+ config.get_client()
99
+ assert str(exc_info.value) == "User 'jose' not found in config file"
100
+
101
+
102
+ def test_get_client_missing_user():
103
+ config_data = {
104
+ "host": "localhost",
105
+ "http_port": "8080",
106
+ "grpc_port": "50051",
107
+ "auth": {"type": "user", "admin": "admin-key"},
108
+ }
109
+
110
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
111
+ with patch("os.path.isfile") as mock_isfile:
112
+ mock_isfile.return_value = True
113
+ config = ConfigManager(config_file="test_config.json")
114
+ with pytest.raises(Exception) as exc_info:
115
+ config.get_client()
116
+ assert (
117
+ str(exc_info.value) == "User must be specified when auth type is 'user'"
118
+ )
119
+
120
+
121
+ def test_get_client_with_api_key_auth():
122
+ config_data = {
123
+ "host": "localhost",
124
+ "http_port": "8080",
125
+ "grpc_port": "50051",
126
+ "auth": {"type": "api_key", "api_key": "test-key"},
127
+ }
128
+
129
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
130
+ with patch("os.path.isfile") as mock_isfile:
131
+ mock_isfile.return_value = True
132
+ with patch("weaviate.connect_to_local") as mock_connect:
133
+ config = ConfigManager(config_file="test_config.json")
134
+ config.get_client()
135
+
136
+ mock_connect.assert_called_once()
137
+ call_kwargs = mock_connect.call_args.kwargs
138
+ assert isinstance(
139
+ call_kwargs["auth_credentials"], weaviate.auth.AuthApiKey
140
+ )
141
+ assert call_kwargs["auth_credentials"].api_key == "test-key"
142
+
143
+
144
+ def test_get_client_with_ip_address():
145
+ config_data = {
146
+ "host": "127.0.0.1",
147
+ "grpc_host": "127.0.0.1",
148
+ "http_port": 8080,
149
+ "grpc_port": 50051,
150
+ }
151
+
152
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
153
+ with patch("os.path.isfile") as mock_isfile:
154
+ mock_isfile.return_value = True
155
+ with patch("weaviate.connect_to_custom") as mock_connect:
156
+ config = ConfigManager(config_file="test_config.json")
157
+ config.get_client()
158
+
159
+ mock_connect.assert_called_once()
160
+ call_kwargs = mock_connect.call_args.kwargs
161
+ assert call_kwargs["http_host"] == "127.0.0.1"
162
+ assert call_kwargs["grpc_host"] == "127.0.0.1"
163
+ assert call_kwargs["http_port"] == 8080
164
+ assert call_kwargs["grpc_port"] == 50051
165
+ assert call_kwargs["http_secure"] == False
166
+ assert call_kwargs["grpc_secure"] == False
167
+
168
+
169
+ def test_get_client_with_ip_address_and_secure_ports():
170
+ config_data = {
171
+ "host": "127.0.0.1",
172
+ "grpc_host": "127.0.0.1",
173
+ "http_port": 443,
174
+ "grpc_port": 443,
175
+ }
176
+
177
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
178
+ with patch("os.path.isfile") as mock_isfile:
179
+ mock_isfile.return_value = True
180
+ with patch("weaviate.connect_to_custom") as mock_connect:
181
+ config = ConfigManager(config_file="test_config.json")
182
+ config.get_client()
183
+
184
+ mock_connect.assert_called_once()
185
+ call_kwargs = mock_connect.call_args.kwargs
186
+ assert call_kwargs["http_host"] == "127.0.0.1"
187
+ assert call_kwargs["grpc_host"] == "127.0.0.1"
188
+ assert call_kwargs["http_port"] == 443
189
+ assert call_kwargs["grpc_port"] == 443
190
+ assert call_kwargs["http_secure"] == True
191
+ assert call_kwargs["grpc_secure"] == True
192
+
193
+
194
+ def test_get_client_with_ip_address_with_https():
195
+ config_data = {
196
+ "host": "https://85.10.20.30",
197
+ "grpc_host": "https://85.10.20.31",
198
+ "http_port": 443,
199
+ "grpc_port": 443,
200
+ }
201
+
202
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
203
+ with patch("os.path.isfile") as mock_isfile:
204
+ mock_isfile.return_value = True
205
+ with patch("weaviate.connect_to_custom") as mock_connect:
206
+ config = ConfigManager(config_file="test_config.json")
207
+ config.get_client()
208
+
209
+ mock_connect.assert_called_once()
210
+ call_kwargs = mock_connect.call_args.kwargs
211
+ assert call_kwargs["http_host"] == "85.10.20.30"
212
+ assert call_kwargs["grpc_host"] == "85.10.20.31"
213
+ assert call_kwargs["http_port"] == 443
214
+ assert call_kwargs["grpc_port"] == 443
215
+ assert call_kwargs["http_secure"] == True
216
+ assert call_kwargs["grpc_secure"] == True
217
+
218
+
219
+ def test_get_client_with_host_and_custom():
220
+ config_data = {
221
+ "host": "https://weaviate.google.my-cloud.com",
222
+ "grpc_host": "https://grpc.weaviate.google.my-cloud.com",
223
+ }
224
+
225
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
226
+ with patch("os.path.isfile") as mock_isfile:
227
+ mock_isfile.return_value = True
228
+ with patch("weaviate.connect_to_custom") as mock_connect:
229
+ config = ConfigManager(config_file="test_config.json")
230
+ config.get_client()
231
+
232
+ mock_connect.assert_called_once()
233
+ call_kwargs = mock_connect.call_args.kwargs
234
+ assert call_kwargs["http_host"] == "weaviate.google.my-cloud.com"
235
+ assert call_kwargs["grpc_host"] == "grpc.weaviate.google.my-cloud.com"
236
+ assert call_kwargs["http_port"] == 443
237
+ assert call_kwargs["grpc_port"] == 443
238
+ assert call_kwargs["http_secure"] == True
239
+ assert call_kwargs["grpc_secure"] == True
240
+
241
+
242
+ def test_get_client_with_host_and_custom_with_ports():
243
+ config_data = {
244
+ "host": "https://weaviate.google.my-cloud.com",
245
+ "grpc_host": "https://grpc.weaviate.google.my-cloud.com",
246
+ "http_port": 8080,
247
+ "grpc_port": 8080,
248
+ }
249
+
250
+ with patch("builtins.open", mock_open(read_data=json.dumps(config_data))):
251
+ with patch("os.path.isfile") as mock_isfile:
252
+ mock_isfile.return_value = True
253
+ with patch("weaviate.connect_to_custom") as mock_connect:
254
+ config = ConfigManager(config_file="test_config.json")
255
+ config.get_client()
256
+
257
+ mock_connect.assert_called_once()
258
+ call_kwargs = mock_connect.call_args.kwargs
259
+ assert call_kwargs["http_host"] == "weaviate.google.my-cloud.com"
260
+ assert call_kwargs["grpc_host"] == "grpc.weaviate.google.my-cloud.com"
261
+ assert call_kwargs["http_port"] == 8080
262
+ assert call_kwargs["grpc_port"] == 8080
263
+ assert call_kwargs["http_secure"] == True # URL contains https
264
+ assert call_kwargs["grpc_secure"] == True # URL contains https
@@ -22,6 +22,7 @@ def test_ingest_data(mock_client):
22
22
  collection="TestCollection",
23
23
  limit=100,
24
24
  randomize=True,
25
+ auto_tenants=10,
25
26
  )
26
27
 
27
28
  mock_client.collections.get.assert_called_once_with("TestCollection")