testzeus-cli 0.0.2__tar.gz → 0.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: testzeus-cli
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Command-line interface for TestZeus testing platform
5
5
  Home-page: https://github.com/test-zeus-ai/testzeus-cli
6
6
  Author: Shriyansh Agnihotri
@@ -15,7 +15,7 @@ Requires-Dist: keyring (>=24.0.0,<25.0.0)
15
15
  Requires-Dist: pydantic (>=2.0.0,<3.0.0)
16
16
  Requires-Dist: pyyaml (>=6.0,<7.0)
17
17
  Requires-Dist: rich (>=13.3.1,<14.0.0)
18
- Requires-Dist: testzeus-sdk (>=0.0.4,<0.0.5)
18
+ Requires-Dist: testzeus-sdk (>=0.0.6,<0.0.7)
19
19
  Project-URL: Repository, https://github.com/test-zeus-ai/testzeus-cli
20
20
  Description-Content-Type: text/markdown
21
21
 
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "testzeus-cli"
7
- version = "0.0.2"
7
+ version = "0.0.3"
8
8
  description = "Command-line interface for TestZeus testing platform"
9
9
  authors = ["Shriyansh Agnihotri <shriyansh@testzeus.com>"]
10
10
  readme = "README.md"
@@ -22,7 +22,7 @@ pydantic = "^2.0.0"
22
22
  pyyaml = "^6.0"
23
23
  keyring = "^24.0.0"
24
24
  ipdb = "^0.13.13"
25
- testzeus-sdk = "^0.0.4"
25
+ testzeus-sdk = "^0.0.6"
26
26
 
27
27
  [tool.poetry.group.dev.dependencies]
28
28
  pytest = "^7.3.1"
@@ -148,6 +148,35 @@ def create_test_data(ctx, name, type, status, input_data, file):
148
148
  # Apply token from config if available
149
149
  if token:
150
150
  initialize_client_with_token(client, token)
151
+ else:
152
+ await client.ensure_authenticated()
153
+
154
+ # Add tenant ID only if it's a valid one
155
+ tenant_id = client.get_tenant_id()
156
+ if (
157
+ tenant_id
158
+ and tenant_id != "_pb_users_auth_"
159
+ and tenant_id != "pbc_138639755"
160
+ ):
161
+ data["tenant"] = tenant_id
162
+ if ctx.obj.get("VERBOSE"):
163
+ console.print(f"[blue]Using tenant ID: {tenant_id}[/blue]")
164
+ else:
165
+ # Let the API determine the appropriate tenant
166
+ if ctx.obj.get("VERBOSE"):
167
+ console.print(
168
+ "[yellow]No valid tenant ID found, letting API determine it[/yellow]"
169
+ )
170
+
171
+ # Get user ID to include as modified_by
172
+ user_id = client.get_user_id()
173
+ if user_id: # Only include if user_id is not empty
174
+ data["modified_by"] = user_id
175
+
176
+ if ctx.obj.get("VERBOSE"):
177
+ console.print(
178
+ f"[blue]Creating test data with parameters: {data}[/blue]"
179
+ )
151
180
 
152
181
  new_test_data = await client.test_data.create(data)
153
182
  return new_test_data.data
@@ -164,16 +193,13 @@ def create_test_data(ctx, name, type, status, input_data, file):
164
193
  @click.option("--name", help="New test data name")
165
194
  @click.option("--type", help="New test data type")
166
195
  @click.option("--status", help="New test data status")
167
- @click.option("--input-data", "-d", help="Test data content as text")
196
+ @click.option("--input-data", "-d", help="New test data content as text")
168
197
  @click.option(
169
- "--file",
170
- "-f",
171
- type=click.Path(exists=True),
172
- help="Text file with test data content",
198
+ "--file", "-f", type=click.Path(exists=True), help="Text file with new test data"
173
199
  )
174
200
  @click.pass_context
175
201
  def update_test_data(ctx, test_data_id, name, type, status, input_data, file):
176
- """Update existing test data"""
202
+ """Update an existing test data"""
177
203
 
178
204
  async def _run():
179
205
  config, token = get_client_config(
@@ -190,21 +216,14 @@ def update_test_data(ctx, test_data_id, name, type, status, input_data, file):
190
216
  else:
191
217
  await client.ensure_authenticated()
192
218
 
193
- # First, fetch the existing test data to get ALL fields
194
- existing_test_data = await client.test_data.get_one(test_data_id_validated)
195
-
196
- if ctx.obj.get("VERBOSE"):
197
- console.print(
198
- f"[blue]Existing test data: {existing_test_data.data}[/blue]"
199
- )
200
-
201
- # Start with all existing data to ensure we don't lose anything
202
- updates = dict(existing_test_data.data)
219
+ # First get the existing test data
220
+ existing_data = await client.test_data.get_one(test_data_id_validated)
203
221
 
204
- # Track if we have any updates
222
+ # Prepare updates starting with all existing data
223
+ updates = dict(existing_data.data)
205
224
  has_updates = False
206
225
 
207
- # Add only the fields the user wants to update
226
+ # Update only the fields that were provided
208
227
  if name:
209
228
  updates["name"] = name
210
229
  has_updates = True
@@ -217,13 +236,11 @@ def update_test_data(ctx, test_data_id, name, type, status, input_data, file):
217
236
  updates["status"] = status
218
237
  has_updates = True
219
238
 
220
- # Add data content if provided directly
239
+ # Process input data (either from input or file)
221
240
  if input_data:
222
241
  updates["data_content"] = input_data
223
242
  has_updates = True
224
-
225
- # Read from file if provided
226
- if file:
243
+ elif file:
227
244
  try:
228
245
  file_content = _read_data_file(file)
229
246
  updates["data_content"] = file_content
@@ -232,27 +249,28 @@ def update_test_data(ctx, test_data_id, name, type, status, input_data, file):
232
249
  console.print(f"[red]Error reading file:[/red] {str(e)}")
233
250
  exit(1)
234
251
 
235
- if not has_updates:
236
- console.print("[yellow]No updates provided[/yellow]")
237
- return None
252
+ # Add user ID as modified_by
253
+ user_id = client.get_user_id()
254
+ if user_id: # Only include if user_id is not empty
255
+ updates["modified_by"] = user_id
256
+ has_updates = True
238
257
 
239
258
  if ctx.obj.get("VERBOSE"):
240
- console.print(f"[blue]Updating test data with: {updates}[/blue]")
241
-
242
- # Clean the data before sending to the API
243
- clean_updates = clean_data_for_api(updates)
244
-
245
- # The clean_data_for_api function now handles critical fields automatically
259
+ console.print(
260
+ f"[blue]Updating test data with parameters: {updates}[/blue]"
261
+ )
246
262
 
247
- if ctx.obj.get("VERBOSE"):
248
- console.print(f"[blue]Cleaned updates for API: {clean_updates}[/blue]")
263
+ if not has_updates:
264
+ console.print("[yellow]No updates provided[/yellow]")
265
+ return None
249
266
 
250
- updated_test_data = await client.test_data.update(
251
- test_data_id_validated, clean_updates
267
+ updated_data = await client.test_data.update(
268
+ test_data_id_validated, updates
252
269
  )
253
- return updated_test_data.data
270
+ return updated_data.data
254
271
 
255
272
  result = asyncio.run(_run())
273
+
256
274
  if result:
257
275
  console.print(
258
276
  f"[green]Test data updated successfully: {result['name']}[/green]"
@@ -46,7 +46,88 @@ def create_test_run(ctx, name, test):
46
46
  else:
47
47
  await client.ensure_authenticated()
48
48
 
49
- test_run = await client.test_runs.create_and_start(name=name, test=test)
49
+ # Here's the key fix - we need to generate a more unique name
50
+ # The API may be rejecting duplicate names
51
+ import datetime
52
+
53
+ timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
54
+ unique_name = f"{name}-{timestamp}-test-run"
55
+
56
+ # Get user ID to include as modified_by
57
+ user_id = client.get_user_id()
58
+
59
+ # If user_id is empty, try to get the user information to get a valid ID
60
+ if not user_id:
61
+ if ctx.obj.get("VERBOSE"):
62
+ console.print(
63
+ "[yellow]User ID not found in token, attempting to fetch user details[/yellow]"
64
+ )
65
+ try:
66
+ # Try to get the authenticated user's information
67
+ user_info = await client.pb.collection("users").auth_refresh()
68
+ # Access user record as a dictionary
69
+ if user_info and hasattr(user_info, "record"):
70
+ # Try various ways to access the user ID
71
+ record_dict = (
72
+ vars(user_info.record)
73
+ if hasattr(user_info.record, "__dict__")
74
+ else {}
75
+ )
76
+ user_id = record_dict.get("id") or getattr(
77
+ user_info.record, "id", ""
78
+ )
79
+ if ctx.obj.get("VERBOSE"):
80
+ console.print(f"[blue]Retrieved user ID: {user_id}[/blue]")
81
+ except Exception as e:
82
+ if ctx.obj.get("VERBOSE"):
83
+ console.print(
84
+ f"[yellow]Failed to get user ID: {str(e)}[/yellow]"
85
+ )
86
+
87
+ # Try to get test details to access its tenant ID
88
+ try:
89
+ test_id = validate_id(test, "test")
90
+ test_details = await client.tests.get_one(test_id)
91
+ tenant_id = test_details.data.get("tenant")
92
+ if ctx.obj.get("VERBOSE"):
93
+ console.print(
94
+ f"[blue]Using tenant ID from test: {tenant_id}[/blue]"
95
+ )
96
+ except Exception as e:
97
+ # If we can't get test details, use the tenant ID from the client
98
+ tenant_id = client.get_tenant_id()
99
+ if ctx.obj.get("VERBOSE"):
100
+ console.print(
101
+ f"[blue]Using tenant ID from client: {tenant_id}[/blue]"
102
+ )
103
+ if "_pb_users_auth_" in str(tenant_id):
104
+ console.print(
105
+ "[yellow]Warning: Using default tenant ID, which may not work[/yellow]"
106
+ )
107
+
108
+ # Create base parameters
109
+ params = {"name": unique_name, "test": test}
110
+
111
+ # Only set tenant if it's a valid ID (not the default PocketBase one)
112
+ if tenant_id and tenant_id != "_pb_users_auth_":
113
+ params["tenant"] = tenant_id
114
+
115
+ # Only add modified_by if we have a valid user ID
116
+ if user_id:
117
+ params["modified_by"] = user_id
118
+ if ctx.obj.get("VERBOSE"):
119
+ console.print(f"[blue]Setting modified_by to: {user_id}[/blue]")
120
+ else:
121
+ console.print(
122
+ "[red]Warning: No valid user ID found. Test run creation may fail.[/red]"
123
+ )
124
+
125
+ if ctx.obj.get("VERBOSE"):
126
+ console.print(
127
+ f"[blue]Creating test run with parameters: {params}[/blue]"
128
+ )
129
+
130
+ test_run = await client.test_runs.create_and_start(**params)
50
131
  return test_run.data
51
132
 
52
133
  result = asyncio.run(_run())
@@ -173,7 +254,20 @@ def cancel_test_run(ctx, test_run_id):
173
254
  else:
174
255
  await client.ensure_authenticated()
175
256
 
176
- cancelled_test = await client.test_runs.cancel(test_run_id_validated)
257
+ # Get user ID to include as modified_by
258
+ user_id = client.get_user_id()
259
+
260
+ # Only include modified_by if user_id is not empty
261
+ params = {"id": test_run_id_validated}
262
+ if user_id:
263
+ params["modified_by"] = user_id
264
+
265
+ if ctx.obj.get("VERBOSE"):
266
+ console.print(
267
+ f"[blue]Cancelling test run with parameters: {params}[/blue]"
268
+ )
269
+
270
+ cancelled_test = await client.test_runs.cancel(**params)
177
271
  return cancelled_test.data
178
272
 
179
273
  try:
@@ -212,7 +306,11 @@ def watch_test_run(ctx, test_run_id, interval):
212
306
  else:
213
307
  await client.ensure_authenticated()
214
308
 
309
+ # Store user ID for future operations that might need it
310
+ user_id = client.get_user_id()
311
+
215
312
  while True:
313
+ # get_one doesn't support modified_by parameter
216
314
  test_run = await client.test_runs.get_one(test_run_id_validated)
217
315
 
218
316
  # Update progress description with status
@@ -278,7 +376,7 @@ def download_attachments(ctx, test_run_id, output_dir):
278
376
  else:
279
377
  await client.ensure_authenticated()
280
378
 
281
- # Download all attachments for the test run
379
+ # Download all attachments for the test run using positional parameters
282
380
  result = await client.test_runs.download_all_attachments(
283
381
  test_run_id_validated, str(output_path)
284
382
  )
@@ -188,8 +188,32 @@ def create_test(ctx, name, feature, feature_file, status, data, tags, environmen
188
188
  else:
189
189
  await client.ensure_authenticated()
190
190
 
191
- # Add tenant ID from the client's authentication
192
- test_data["tenant"] = client.get_tenant_id()
191
+ # Add tenant ID only if it's a valid one
192
+ tenant_id = client.get_tenant_id()
193
+ if (
194
+ tenant_id
195
+ and tenant_id != "_pb_users_auth_"
196
+ and tenant_id != "pbc_138639755"
197
+ ):
198
+ test_data["tenant"] = tenant_id
199
+ if ctx.obj.get("VERBOSE"):
200
+ console.print(f"[blue]Using tenant ID: {tenant_id}[/blue]")
201
+ else:
202
+ # Let the API determine the appropriate tenant
203
+ if ctx.obj.get("VERBOSE"):
204
+ console.print(
205
+ "[yellow]No valid tenant ID found, letting API determine it[/yellow]"
206
+ )
207
+
208
+ # Get user ID to include as modified_by
209
+ user_id = client.get_user_id()
210
+ if user_id: # Only include if not empty
211
+ test_data["modified_by"] = user_id
212
+
213
+ if ctx.obj.get("VERBOSE"):
214
+ console.print(
215
+ f"[blue]Creating test with parameters: {test_data}[/blue]"
216
+ )
193
217
 
194
218
  new_test = await client.tests.create(test_data)
195
219
  return new_test.data
@@ -280,6 +304,12 @@ def update_test(
280
304
  updates["environment"] = environment
281
305
  has_updates = True
282
306
 
307
+ # Add user ID as modified_by
308
+ user_id = client.get_user_id()
309
+ if user_id: # Only include if not empty
310
+ updates["modified_by"] = user_id
311
+ has_updates = has_updates or True
312
+
283
313
  if not has_updates:
284
314
  console.print("[yellow]No updates provided[/yellow]")
285
315
  return None
@@ -312,50 +342,6 @@ def update_test(
312
342
  exit(1)
313
343
 
314
344
 
315
- @tests_group.command(name="solve")
316
- @click.argument("test_id")
317
- @click.option("--output-file", help="Save solution to this file path")
318
- @click.pass_context
319
- def solve_test(ctx, test_id, output_file):
320
- """Generate a solution for a test using the TestZeus platform"""
321
-
322
- async def _run():
323
- config, token = get_client_config(
324
- ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
325
- )
326
- client = TestZeusClient(**config)
327
-
328
- test_id_validated = validate_id(test_id, "test")
329
-
330
- async with client:
331
- # Apply token from config if available
332
- if token:
333
- initialize_client_with_token(client, token)
334
- else:
335
- await client.ensure_authenticated()
336
-
337
- # Get the test to fetch its features
338
- test = await client.tests.get_one(test_id_validated)
339
-
340
- # Generate solution
341
- solution = await client.tests.solve(test_id_validated)
342
-
343
- # Save to file if requested
344
- if output_file:
345
- with open(output_file, "w") as f:
346
- if isinstance(solution, dict):
347
- json.dump(solution, f, indent=2)
348
- else:
349
- f.write(str(solution))
350
- console.print(f"[green]Solution saved to: {output_file}[/green]")
351
-
352
- return solution
353
-
354
- result = asyncio.run(_run())
355
- console.print("[green]Solution generated successfully[/green]")
356
- format_output(result, ctx.obj["FORMAT"])
357
-
358
-
359
345
  @tests_group.command(name="delete")
360
346
  @click.argument("test_id")
361
347
  @click.confirmation_option(prompt="Are you sure you want to delete this test?")
@@ -51,6 +51,7 @@ def initialize_client_with_token(client: TestZeusClient, token: str) -> None:
51
51
  # Extract token data
52
52
  claims = decode_jwt_payload(token)
53
53
  tenant_id = None
54
+ user_id = None
54
55
 
55
56
  if claims:
56
57
  # Check for tenant ID in various possible locations within the token
@@ -58,21 +59,42 @@ def initialize_client_with_token(client: TestZeusClient, token: str) -> None:
58
59
  tenant_id = claims["tenant"]
59
60
  elif "record" in claims and "tenant" in claims["record"]:
60
61
  tenant_id = claims["record"]["tenant"]
61
- elif "collectionId" in claims:
62
- # Use collection ID as a fallback
62
+ elif "collectionId" in claims and claims["collectionId"] != "_pb_users_auth_":
63
+ # Use collection ID as a fallback if it's not the default auth collection
63
64
  tenant_id = claims["collectionId"]
64
65
 
65
- # If no tenant ID found in token, use the default
66
- if not tenant_id:
67
- tenant_id = "pbc_138639755" # Default tenant ID for TestZeus
66
+ # Extract user ID from the token
67
+ if "id" in claims:
68
+ user_id = claims["id"]
69
+ elif "sub" in claims:
70
+ user_id = claims["sub"]
71
+ elif "record" in claims and "id" in claims["record"]:
72
+ user_id = claims["record"]["id"]
68
73
 
69
- # Save the token to the auth store - don't try to set the model property directly
70
- # as it's read-only. Instead, just save the token and let PocketBase handle it.
74
+ # Save the token to the auth store - this should properly populate auth_store.model
71
75
  client.pb.auth_store.save(token, None)
72
76
 
73
- # Add tenant ID directly to the client for easy access
74
- # This is the important part - ensure the tenant ID is accessible
75
- setattr(client, "_tenant_id", tenant_id)
77
+ # If user_id was found but auth model wasn't populated correctly, we can set it manually
78
+ if user_id and (
79
+ not client.pb.auth_store.model or not hasattr(client.pb.auth_store.model, "id")
80
+ ):
81
+ # Try to set the ID on the auth model if it exists
82
+ if client.pb.auth_store.model:
83
+ setattr(client.pb.auth_store.model, "id", user_id)
84
+
85
+ # Only set a tenant ID if we found a valid one (not the default PocketBase authentication one)
86
+ if tenant_id and tenant_id != "_pb_users_auth_" and tenant_id != "pbc_138639755":
87
+ # Add tenant ID directly to the client for easy access
88
+ setattr(client, "_tenant_id", tenant_id)
89
+ else:
90
+ # Try to get tenant from test if this is a test-related token
91
+ if claims and "test" in claims:
92
+ # We'll try to resolve the tenant from the test itself
93
+ # This would require additional API calls, handled in the command functions
94
+ setattr(client, "_tenant_id", "")
95
+ else:
96
+ # Set empty tenant ID to indicate we need to resolve it from context
97
+ setattr(client, "_tenant_id", "")
76
98
 
77
99
 
78
100
  def extract_tenant_from_token(token: str) -> str:
@@ -83,7 +105,7 @@ def extract_tenant_from_token(token: str) -> str:
83
105
  token: The JWT token
84
106
 
85
107
  Returns:
86
- Tenant ID or default ID if not found
108
+ Tenant ID or empty string if not found
87
109
  """
88
110
  claims = decode_jwt_payload(token)
89
111
 
@@ -95,6 +117,13 @@ def extract_tenant_from_token(token: str) -> str:
95
117
  return str(claims["record"]["tenant"])
96
118
  elif "collectionId" in claims:
97
119
  return str(claims["collectionId"])
98
-
99
- # Default tenant ID for TestZeus
100
- return "pbc_138639755"
120
+ # Look for tenant in other possible locations
121
+ elif (
122
+ "record" in claims
123
+ and claims["record"].get("collectionId")
124
+ and claims["record"]["collectionId"] != "_pb_users_auth_"
125
+ ):
126
+ return str(claims["record"]["collectionId"])
127
+
128
+ # No default value - let the API determine the appropriate tenant
129
+ return ""
File without changes
File without changes