|
9 | 9 |
|
10 | 10 | # Standard |
11 | 11 | from datetime import datetime |
| 12 | +from pathlib import Path |
12 | 13 | from unittest.mock import Mock, patch |
| 14 | +import json |
| 15 | +import tempfile |
13 | 16 |
|
14 | 17 | # Third-Party |
15 | 18 | import pytest |
@@ -658,3 +661,30 @@ def test_profiles_create_with_existing_store(self, mock_console, mock_settings) |
658 | 661 | assert len(updated_store.profiles) == 2 |
659 | 662 | assert "existing-profile" in updated_store.profiles |
660 | 663 | assert "new-profile-id" in updated_store.profiles |
| 664 | + |
| 665 | + def test_profiles_create_data_file(self, mock_console, mock_settings) -> None: |
| 666 | + """Test successfully creating a new profile using a data file.""" |
| 667 | + with patch("cforge.commands.settings.profiles.get_console", return_value=mock_console): |
| 668 | + with patch("cforge.commands.settings.profiles.typer.confirm", return_value=False): |
| 669 | + data_file_content = { |
| 670 | + "name": "Test Profile", |
| 671 | + "email": "test@example.com", |
| 672 | + "api_url": "https://api.test.com", |
| 673 | + "is_active": False, |
| 674 | + } |
| 675 | + with tempfile.NamedTemporaryFile("w") as data_file: |
| 676 | + data_file.write(json.dumps(data_file_content)) |
| 677 | + data_file.flush() |
| 678 | + profiles_create(Path(data_file.name)) |
| 679 | + |
| 680 | + # Verify both profiles exist in the store |
| 681 | + updated_store = load_profile_store() |
| 682 | + assert updated_store is not None |
| 683 | + assert len(updated_store.profiles) == 1 |
| 684 | + profile_id = list(updated_store.profiles.keys())[0] |
| 685 | + profile = list(updated_store.profiles.values())[0] |
| 686 | + assert profile.id == profile_id |
| 687 | + assert profile.name == data_file_content["name"] |
| 688 | + assert profile.email == data_file_content["email"] |
| 689 | + assert profile.api_url == data_file_content["api_url"] |
| 690 | + assert profile.is_active == data_file_content["is_active"] |
0 commit comments