def test__get_events_exception(mock__http_request): mock__http_request.side_effect = [ConnectionError] test_ksh = KodakSmartHome("fake_user", "fake_pass") test_ksh.devices = devices_response["data"]["devices"] test_ksh.token = "abcdef0123456789" with pytest.raises(ConnectionError): test_ksh._get_events()
def test__get_events_is_connected_false(mock__http_request, mock_connect): mock__http_request.return_value = events_response mock_connect.return_value = True test_ksh = KodakSmartHome("fake_user", "fake_pass") test_ksh.devices = devices_response["data"]["devices"] test_ksh.is_connected = False test_events = test_ksh._get_events() assert test_events == [{"device_id": "FAKEDEVICEID", "events": []}]
def test__get_events(mock__http_request): mock__http_request.return_value = events_response test_ksh = KodakSmartHome("fake_user", "fake_pass") test_ksh.devices = devices_response["data"]["devices"] test_ksh.is_connected = True test_events = test_ksh._get_events() expected_result = [ { "device_id": devices_response["data"]["devices"][0]["device_id"], "events": events_response["data"]["events"], } ] assert test_events == expected_result
def test__get_events_with_existent_events(mock__http_request): mock__http_request.return_value = events_response test_ksh = KodakSmartHome("fake_user", "fake_pass") test_ksh.devices = devices_response["data"]["devices"] test_ksh.is_connected = True test_events = test_ksh._get_events() test_events = test_ksh._get_events() # second call expected_result = [ { "device_id": devices_response["data"]["devices"][0]["device_id"], "events": events_response["data"]["events"], } ] assert sorted( [e.get("id") for e in expected_result[0].get("events")] ) == sorted( [e.get("id") for e in test_events[0].get("events")] )
def test__get_events_none(mock__http_request): events_response_none = { "status": HTTP_CODE.OK, "msg": "Success", "total_pages": 0, "data": {"total_events": 0, "total_pages": 0, "events": []}, } mock__http_request.return_value = events_response_none test_ksh = KodakSmartHome("fake_user", "fake_pass") test_ksh.devices = devices_response["data"]["devices"] test_ksh.token = "abcdef0123456789" test_ksh.is_connected = True test_events = test_ksh._get_events() expected_result = [ { "device_id": devices_response["data"]["devices"][0]["device_id"], "events": events_response_none["data"]["events"], } ] assert test_events == expected_result