|
1 | 1 | """Tests for the project_info CLI command.""" |
2 | 2 |
|
3 | 3 | import json |
| 4 | +from datetime import datetime |
| 5 | +from unittest.mock import patch, AsyncMock |
4 | 6 |
|
5 | 7 | from typer.testing import CliRunner |
6 | 8 |
|
7 | 9 | from basic_memory.cli.main import app as cli_app |
| 10 | +from basic_memory.schemas.project_info import ( |
| 11 | + ProjectInfoResponse, |
| 12 | + ProjectStatistics, |
| 13 | + ActivityMetrics, |
| 14 | + SystemStatus, |
| 15 | +) |
8 | 16 |
|
9 | 17 |
|
10 | | -def test_info_stats_command(cli_env, test_graph, project_session): |
| 18 | +def test_info_stats(): |
11 | 19 | """Test the 'project info' command with default output.""" |
12 | 20 | runner = CliRunner() |
13 | 21 |
|
14 | | - # Run the command |
15 | | - result = runner.invoke(cli_app, ["project", "info"]) |
| 22 | + # Create mock project info data |
| 23 | + mock_info = ProjectInfoResponse( |
| 24 | + project_name="test-project", |
| 25 | + project_path="/test/path", |
| 26 | + default_project="test-project", |
| 27 | + statistics=ProjectStatistics( |
| 28 | + total_entities=10, |
| 29 | + total_observations=20, |
| 30 | + total_relations=5, |
| 31 | + total_unresolved_relations=1, |
| 32 | + isolated_entities=2, |
| 33 | + entity_types={"note": 8, "concept": 2}, |
| 34 | + observation_categories={"tech": 15, "note": 5}, |
| 35 | + relation_types={"connects_to": 3, "references": 2}, |
| 36 | + most_connected_entities=[], |
| 37 | + ), |
| 38 | + activity=ActivityMetrics(recently_created=[], recently_updated=[], monthly_growth={}), |
| 39 | + system=SystemStatus( |
| 40 | + version="0.13.0", |
| 41 | + database_path="/test/db.sqlite", |
| 42 | + database_size="1.2 MB", |
| 43 | + watch_status=None, |
| 44 | + timestamp=datetime.now(), |
| 45 | + ), |
| 46 | + available_projects={"test-project": {"path": "/test/path"}}, |
| 47 | + ) |
16 | 48 |
|
17 | | - # Verify exit code |
18 | | - assert result.exit_code == 0 |
| 49 | + # Mock the async project_info function |
| 50 | + with patch( |
| 51 | + "basic_memory.cli.commands.project.project_info", new_callable=AsyncMock |
| 52 | + ) as mock_func: |
| 53 | + mock_func.return_value = mock_info |
19 | 54 |
|
20 | | - # Check that key data is included in the output |
21 | | - assert "Basic Memory Project Info" in result.stdout |
| 55 | + # Run the command |
| 56 | + result = runner.invoke(cli_app, ["project", "info"]) |
22 | 57 |
|
| 58 | + # Verify exit code |
| 59 | + assert result.exit_code == 0 |
23 | 60 |
|
24 | | -def test_info_stats_json(cli_env, test_graph, project_session): |
| 61 | + # Check that key data is included in the output |
| 62 | + assert "Basic Memory Project Info" in result.stdout |
| 63 | + assert "test-project" in result.stdout |
| 64 | + assert "Statistics" in result.stdout |
| 65 | + |
| 66 | + |
| 67 | +def test_info_stats_json(): |
25 | 68 | """Test the 'project info --json' command for JSON output.""" |
26 | 69 | runner = CliRunner() |
27 | 70 |
|
28 | | - # Run the command with --json flag |
29 | | - result = runner.invoke(cli_app, ["project", "info", "--json"]) |
| 71 | + # Create mock project info data |
| 72 | + mock_info = ProjectInfoResponse( |
| 73 | + project_name="test-project", |
| 74 | + project_path="/test/path", |
| 75 | + default_project="test-project", |
| 76 | + statistics=ProjectStatistics( |
| 77 | + total_entities=10, |
| 78 | + total_observations=20, |
| 79 | + total_relations=5, |
| 80 | + total_unresolved_relations=1, |
| 81 | + isolated_entities=2, |
| 82 | + entity_types={"note": 8, "concept": 2}, |
| 83 | + observation_categories={"tech": 15, "note": 5}, |
| 84 | + relation_types={"connects_to": 3, "references": 2}, |
| 85 | + most_connected_entities=[], |
| 86 | + ), |
| 87 | + activity=ActivityMetrics(recently_created=[], recently_updated=[], monthly_growth={}), |
| 88 | + system=SystemStatus( |
| 89 | + version="0.13.0", |
| 90 | + database_path="/test/db.sqlite", |
| 91 | + database_size="1.2 MB", |
| 92 | + watch_status=None, |
| 93 | + timestamp=datetime.now(), |
| 94 | + ), |
| 95 | + available_projects={"test-project": {"path": "/test/path"}}, |
| 96 | + ) |
| 97 | + |
| 98 | + # Mock the async project_info function |
| 99 | + with patch( |
| 100 | + "basic_memory.cli.commands.project.project_info", new_callable=AsyncMock |
| 101 | + ) as mock_func: |
| 102 | + mock_func.return_value = mock_info |
| 103 | + |
| 104 | + # Run the command with --json flag |
| 105 | + result = runner.invoke(cli_app, ["project", "info", "--json"]) |
30 | 106 |
|
31 | | - # Verify exit code |
32 | | - assert result.exit_code == 0 |
| 107 | + # Verify exit code |
| 108 | + assert result.exit_code == 0 |
33 | 109 |
|
34 | | - # Parse JSON output |
35 | | - output = json.loads(result.stdout) |
| 110 | + # Parse JSON output |
| 111 | + output = json.loads(result.stdout) |
36 | 112 |
|
37 | | - # Verify JSON structure matches our sample data |
38 | | - assert output["default_project"] == "test-project" |
| 113 | + # Verify JSON structure matches our mock data |
| 114 | + assert output["default_project"] == "test-project" |
| 115 | + assert output["project_name"] == "test-project" |
| 116 | + assert output["statistics"]["total_entities"] == 10 |
0 commit comments