Exemple #1
0
def test_requests_exception():
    with requests_mock.Mocker() as req_mock:
        req_mock.get("http://127.0.0.1:80/instantaneousdemand",
                     exc=requests.exceptions.RequestException)
        dte = DteEnergyBridge('127.0.0.1', 1)
        with pytest.raises(exceptions.InvalidResponseError):
            dte.get_current_energy_usage()
Exemple #2
0
def test_non_200_status_code():
    with requests_mock.Mocker() as req_mock:
        req_mock.get("http://127.0.0.1:80/instantaneousdemand",
                     status_code=500)
        dte = DteEnergyBridge('127.0.0.1', 1)
        with pytest.raises(exceptions.InvalidResponseError):
            dte.get_current_energy_usage()
Exemple #3
0
def test_bad_formatted_response():
    with requests_mock.Mocker() as req_mock:
        req_mock.get("http://127.0.0.1:80/instantaneousdemand", text='411')
        dte = DteEnergyBridge('127.0.0.1', 1)
        with pytest.raises(exceptions.InvalidResponseError):
            dte.get_current_energy_usage()
Exemple #4
0
def test_incorrect_units_response():
    with requests_mock.Mocker() as req_mock:
        req_mock.get("http://127.0.0.1:80/instantaneousdemand", text='411 kW')
        dte = DteEnergyBridge('127.0.0.1', 1)
        assert dte.get_current_energy_usage() == .411
Exemple #5
0
def test_instantaneous_demand_v2():
    with requests_mock.Mocker() as req_mock:
        req_mock.get("http://127.0.0.1:8888/zigbee/se/instantaneousdemand",
                     text='.411 kW')
        dte = DteEnergyBridge('127.0.0.1', 2)
        assert dte.get_current_energy_usage() == .411
Exemple #6
0
def test_valid_bridge_version():
    """Tests to make sure constructor doesn't throw on valid bridge_version"""
    DteEnergyBridge('127.0.0.1', 1)
    DteEnergyBridge('127.0.0.1', 2)
Exemple #7
0
def test_invalid_bridge_version():
    """Tests to make sure constructor throws on invalid bridge_version"""
    with pytest.raises(exceptions.InvalidArgumentError):
        DteEnergyBridge('127.0.0.1', 3)