|
2 | 2 | import os
|
3 | 3 | import shutil
|
4 | 4 | import unittest
|
| 5 | +import uuid |
5 | 6 | from pathlib import Path
|
6 | 7 |
|
7 | 8 | from typer.testing import CliRunner
|
@@ -257,6 +258,146 @@ def test_projects_select(self):
|
257 | 258 | show_data = json.loads(result.stdout)
|
258 | 259 | self.assertEqual(show_data["project"]["id"], project_id)
|
259 | 260 |
|
| 261 | + def test_datasources_list(self): |
| 262 | + """Test datasource listing""" |
| 263 | + # First select an organization and team |
| 264 | + result = self.runner.invoke(app, ["orgs", "list", "--json"]) |
| 265 | + self.assertEqual(result.exit_code, 0) |
| 266 | + orgs_data = json.loads(result.stdout) |
| 267 | + |
| 268 | + if not orgs_data: |
| 269 | + self.skipTest("No organizations available for testing") |
| 270 | + |
| 271 | + # Set organization |
| 272 | + org_id = orgs_data[0]["id"] |
| 273 | + result = self.runner.invoke(app, ["orgs", "set", org_id]) |
| 274 | + self.assertEqual(result.exit_code, 0) |
| 275 | + |
| 276 | + # Get and set team |
| 277 | + result = self.runner.invoke(app, ["teams", "list", "--json"]) |
| 278 | + self.assertEqual(result.exit_code, 0) |
| 279 | + teams_data = json.loads(result.stdout) |
| 280 | + |
| 281 | + if not teams_data: |
| 282 | + self.skipTest("No teams available for testing") |
| 283 | + |
| 284 | + team_id = teams_data[0]["id"] |
| 285 | + result = self.runner.invoke(app, ["teams", "set", team_id]) |
| 286 | + self.assertEqual(result.exit_code, 0) |
| 287 | + |
| 288 | + # Get and set project |
| 289 | + result = self.runner.invoke(app, ["projects", "list", "--json"]) |
| 290 | + self.assertEqual(result.exit_code, 0) |
| 291 | + projects_data = json.loads(result.stdout) |
| 292 | + |
| 293 | + if not projects_data: |
| 294 | + self.skipTest("No projects available for testing") |
| 295 | + |
| 296 | + project_id = projects_data[0]["id"] |
| 297 | + result = self.runner.invoke(app, ["projects", "set", project_id]) |
| 298 | + self.assertEqual(result.exit_code, 0) |
| 299 | + |
| 300 | + # Test datasources list without project ID (using current project) |
| 301 | + result = self.runner.invoke(app, ["datasources", "list"]) |
| 302 | + self.assertEqual(result.exit_code, 0) |
| 303 | + self.assertIn("ID", result.stdout) |
| 304 | + self.assertIn("Name", result.stdout) |
| 305 | + self.assertIn("Type", result.stdout) |
| 306 | + self.assertIn("URI", result.stdout) |
| 307 | + |
| 308 | + # Test datasources list with explicit project ID |
| 309 | + result = self.runner.invoke( |
| 310 | + app, ["datasources", "list", "--project-id", project_id] |
| 311 | + ) |
| 312 | + self.assertEqual(result.exit_code, 0) |
| 313 | + self.assertIn("ID", result.stdout) |
| 314 | + self.assertIn("Name", result.stdout) |
| 315 | + self.assertIn("Type", result.stdout) |
| 316 | + self.assertIn("URI", result.stdout) |
| 317 | + |
| 318 | + def test_datasource_create(self): |
| 319 | + """Test datasource creation""" |
| 320 | + # First select an organization and team |
| 321 | + result = self.runner.invoke(app, ["orgs", "list", "--json"]) |
| 322 | + self.assertEqual(result.exit_code, 0) |
| 323 | + orgs_data = json.loads(result.stdout) |
| 324 | + |
| 325 | + if not orgs_data: |
| 326 | + self.skipTest("No organizations available for testing") |
| 327 | + |
| 328 | + # Set organization |
| 329 | + org_id = orgs_data[0]["id"] |
| 330 | + result = self.runner.invoke(app, ["orgs", "set", org_id]) |
| 331 | + self.assertEqual(result.exit_code, 0) |
| 332 | + |
| 333 | + # Get and set team |
| 334 | + result = self.runner.invoke(app, ["teams", "list", "--json"]) |
| 335 | + self.assertEqual(result.exit_code, 0) |
| 336 | + teams_data = json.loads(result.stdout) |
| 337 | + |
| 338 | + if not teams_data: |
| 339 | + self.skipTest("No teams available for testing") |
| 340 | + |
| 341 | + team_id = teams_data[0]["id"] |
| 342 | + result = self.runner.invoke(app, ["teams", "set", team_id]) |
| 343 | + self.assertEqual(result.exit_code, 0) |
| 344 | + |
| 345 | + # Get and set project |
| 346 | + result = self.runner.invoke(app, ["projects", "list", "--json"]) |
| 347 | + self.assertEqual(result.exit_code, 0) |
| 348 | + projects_data = json.loads(result.stdout) |
| 349 | + |
| 350 | + if not projects_data: |
| 351 | + self.skipTest("No projects available for testing") |
| 352 | + |
| 353 | + project_id = projects_data[0]["id"] |
| 354 | + result = self.runner.invoke(app, ["projects", "set", project_id]) |
| 355 | + self.assertEqual(result.exit_code, 0) |
| 356 | + |
| 357 | + # Test datasource creation without project ID (using current project) |
| 358 | + datasource_name = "test-ds-" + str(uuid.uuid4())[:8] |
| 359 | + result = self.runner.invoke( |
| 360 | + app, |
| 361 | + [ |
| 362 | + "datasources", |
| 363 | + "create", |
| 364 | + datasource_name, |
| 365 | + "--type", |
| 366 | + "postgres", |
| 367 | + "--uri", |
| 368 | + "postgresql://user:pass@localhost:5432/db", |
| 369 | + ], |
| 370 | + ) |
| 371 | + self.assertEqual(result.exit_code, 0) |
| 372 | + self.assertIn("Datasource created successfully!", result.stdout) |
| 373 | + self.assertIn("ID:", result.stdout) |
| 374 | + self.assertIn("Name: " + datasource_name, result.stdout) |
| 375 | + self.assertIn("Type: postgres", result.stdout) |
| 376 | + self.assertIn("URI:", result.stdout) |
| 377 | + |
| 378 | + # Test datasource creation with explicit project ID |
| 379 | + datasource_name2 = "test-ds-" + str(uuid.uuid4())[:8] |
| 380 | + result = self.runner.invoke( |
| 381 | + app, |
| 382 | + [ |
| 383 | + "datasources", |
| 384 | + "create", |
| 385 | + datasource_name2, |
| 386 | + "--type", |
| 387 | + "mysql", |
| 388 | + "--uri", |
| 389 | + "mysql://user:pass@localhost:3306/db", |
| 390 | + "--project-id", |
| 391 | + project_id, |
| 392 | + ], |
| 393 | + ) |
| 394 | + self.assertEqual(result.exit_code, 0) |
| 395 | + self.assertIn("Datasource created successfully!", result.stdout) |
| 396 | + self.assertIn("ID:", result.stdout) |
| 397 | + self.assertIn("Name: " + datasource_name2, result.stdout) |
| 398 | + self.assertIn("Type: mysql", result.stdout) |
| 399 | + self.assertIn("URI:", result.stdout) |
| 400 | + |
260 | 401 |
|
261 | 402 | if __name__ == "__main__":
|
262 | 403 | unittest.main()
|
0 commit comments