|
30 | 30 | TEST_URL_RESTART = "http://openevse.test.tld/restart" |
31 | 31 | TEST_URL_LIMIT = "http://openevse.test.tld/limit" |
32 | 32 | TEST_URL_WS = "ws://openevse.test.tld/ws" |
| 33 | +TEST_URL_CLAIMS = "http://openevse.test.tld/claims" |
33 | 34 | TEST_URL_GITHUB_v4 = ( |
34 | 35 | "https://api.github.com/repos/OpenEVSE/ESP32_WiFi_V4.x/releases/latest" |
35 | 36 | ) |
@@ -1682,3 +1683,71 @@ async def test_voltage(test_charger, test_charger_v2, mock_aioclient, caplog): |
1682 | 1683 | with caplog.at_level(logging.DEBUG): |
1683 | 1684 | await test_charger_v2.grid_voltage(210) |
1684 | 1685 | assert "Feature not supported for older firmware." in caplog.text |
| 1686 | + |
| 1687 | + |
| 1688 | +async def test_list_claims(test_charger, test_charger_v2, mock_aioclient, caplog): |
| 1689 | + """Test list_claims function.""" |
| 1690 | + await test_charger.update() |
| 1691 | + mock_aioclient.get( |
| 1692 | + TEST_URL_CLAIMS, |
| 1693 | + status=200, |
| 1694 | + body='[{"client":65540,"priority":10,"state":"disabled","auto_release":false}]', |
| 1695 | + repeat=True, |
| 1696 | + ) |
| 1697 | + with caplog.at_level(logging.DEBUG): |
| 1698 | + await test_charger.list_claims() |
| 1699 | + assert f"Getting claims on {TEST_URL_CLAIMS}" in caplog.text |
| 1700 | + |
| 1701 | + with pytest.raises(UnsupportedFeature): |
| 1702 | + with caplog.at_level(logging.DEBUG): |
| 1703 | + await test_charger_v2.list_claims() |
| 1704 | + assert "Feature not supported for older firmware." in caplog.text |
| 1705 | + |
| 1706 | + |
| 1707 | +async def test_release_claim(test_charger, test_charger_v2, mock_aioclient, caplog): |
| 1708 | + """Test release_claim function.""" |
| 1709 | + await test_charger.update() |
| 1710 | + mock_aioclient.delete( |
| 1711 | + f"{TEST_URL_CLAIMS}/4", |
| 1712 | + status=200, |
| 1713 | + body='[{"msg":"done"}]', |
| 1714 | + repeat=True, |
| 1715 | + ) |
| 1716 | + with caplog.at_level(logging.DEBUG): |
| 1717 | + await test_charger.release_claim() |
| 1718 | + assert f"Releasing claim on {TEST_URL_CLAIMS}/4" in caplog.text |
| 1719 | + |
| 1720 | + with pytest.raises(UnsupportedFeature): |
| 1721 | + with caplog.at_level(logging.DEBUG): |
| 1722 | + await test_charger_v2.release_claim() |
| 1723 | + assert "Feature not supported for older firmware." in caplog.text |
| 1724 | + |
| 1725 | + |
| 1726 | +async def test_make_claim(test_charger, test_charger_v2, mock_aioclient, caplog): |
| 1727 | + """Test make_claim function.""" |
| 1728 | + await test_charger.update() |
| 1729 | + mock_aioclient.post( |
| 1730 | + f"{TEST_URL_CLAIMS}/4", |
| 1731 | + status=200, |
| 1732 | + body='[{"msg":"done"}]', |
| 1733 | + repeat=True, |
| 1734 | + ) |
| 1735 | + with caplog.at_level(logging.DEBUG): |
| 1736 | + await test_charger.make_claim( |
| 1737 | + state="disabled", charge_current=20, max_current=20 |
| 1738 | + ) |
| 1739 | + assert ( |
| 1740 | + "Claim data: {'auto_release': True, 'state': 'disabled', 'charge_current': 20, 'max_current': 20}" |
| 1741 | + in caplog.text |
| 1742 | + ) |
| 1743 | + assert f"Setting up claim on {TEST_URL_CLAIMS}/4" in caplog.text |
| 1744 | + |
| 1745 | + with pytest.raises(ValueError): |
| 1746 | + with caplog.at_level(logging.DEBUG): |
| 1747 | + await test_charger.make_claim("invalid") |
| 1748 | + assert "Invalid claim state: invalid" in caplog.text |
| 1749 | + |
| 1750 | + with pytest.raises(UnsupportedFeature): |
| 1751 | + with caplog.at_level(logging.DEBUG): |
| 1752 | + await test_charger_v2.make_claim() |
| 1753 | + assert "Feature not supported for older firmware." in caplog.text |
0 commit comments