|
9 | 9 |
|
10 | 10 | import pytest |
11 | 11 |
|
12 | | -from frequenz.client.microgrid import Location |
| 12 | +from frequenz.client.microgrid import Location, Metadata, MicrogridId |
13 | 13 |
|
14 | 14 |
|
15 | 15 | @pytest.fixture |
@@ -65,3 +65,46 @@ def test_location_timezone_lookup( |
65 | 65 | else: |
66 | 66 | assert location.timezone == ZoneInfo(key=timezone) |
67 | 67 | timezone_finder.timezone_at.assert_called_once_with(lat=52.52, lng=13.405) |
| 68 | + |
| 69 | + |
| 70 | +def test_metadata_initialization() -> None: |
| 71 | + """Test initialization of Metadata class.""" |
| 72 | + # Test with no parameters |
| 73 | + metadata = Metadata() |
| 74 | + assert metadata.microgrid_id is None |
| 75 | + assert metadata.location is None |
| 76 | + |
| 77 | + # Test with only microgrid_id |
| 78 | + microgrid_id = MicrogridId(42) |
| 79 | + metadata = Metadata(microgrid_id=microgrid_id) |
| 80 | + assert metadata.microgrid_id == microgrid_id |
| 81 | + assert metadata.location is None |
| 82 | + |
| 83 | + # Test with only location |
| 84 | + location = Location(latitude=52.52, longitude=13.405) |
| 85 | + metadata = Metadata(location=location) |
| 86 | + assert metadata.microgrid_id is None |
| 87 | + assert metadata.location == location |
| 88 | + |
| 89 | + # Test with both parameters |
| 90 | + metadata = Metadata(microgrid_id=microgrid_id, location=location) |
| 91 | + assert metadata.microgrid_id == microgrid_id |
| 92 | + assert metadata.location == location |
| 93 | + |
| 94 | + |
| 95 | +def test_metadata_microgrid_id_validation() -> None: |
| 96 | + """Test validation of microgrid_id in Metadata class.""" |
| 97 | + # Valid microgrid_id should work |
| 98 | + metadata = Metadata(microgrid_id=MicrogridId(0)) |
| 99 | + assert metadata.microgrid_id == MicrogridId(0) |
| 100 | + |
| 101 | + metadata = Metadata(microgrid_id=MicrogridId(42)) |
| 102 | + assert metadata.microgrid_id == MicrogridId(42) |
| 103 | + |
| 104 | + # None should be accepted as a valid value |
| 105 | + metadata = Metadata(microgrid_id=None) |
| 106 | + assert metadata.microgrid_id is None |
| 107 | + |
| 108 | + # Negative IDs should raise ValueError |
| 109 | + with pytest.raises(ValueError): |
| 110 | + Metadata(microgrid_id=MicrogridId(-1)) |
0 commit comments