update tests

This commit is contained in:
proddy
2025-03-13 22:45:26 +01:00
parent 67885950ef
commit ed7a9f43de
4 changed files with 56 additions and 36 deletions

View File

@@ -324,20 +324,15 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
if (command == "general") {
shell.printfln("Testing adding a boiler, thermostat, all sensors, scheduler and custom entities...");
// setup fake data
// EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS
// add devices
test("general");
// EMSESP::webCustomEntityService.test(); // add custom entities
// EMSESP::temperaturesensor_.test(); // add temperature sensors
// EMSESP::webSchedulerService.test(); // add scheduler items
EMSESP::webCustomEntityService.test(); // custom entities
EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS
EMSESP::temperaturesensor_.test(); // add temperature sensors
EMSESP::webSchedulerService.test(); // run scheduler tests, and conditions
// shell.invoke_command("show devices");
// shell.invoke_command("show values");
// shell.invoke_command("call system publish");
// shell.invoke_command("show mqtt");
shell.invoke_command("show values");
ok = true;
}
@@ -1089,6 +1084,10 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
// request.url("/api/boiler/comfort/value");
// EMSESP::webAPIService.webAPIService(&request);
// this should fail but it doesn't
// request.url("/api/boiler/bad/value");
// EMSESP::webAPIService.webAPIService(&request);
// POST COMMANDS
request.method(HTTP_POST);

View File

@@ -165,6 +165,7 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
}
return true;
}
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
if (Helpers::toLower(scheduleItem.name) == cmd) {
get_value_json(output, scheduleItem);
@@ -385,7 +386,6 @@ bool WebSchedulerService::command(const char * name, const std::string & command
snprintf(command_str, sizeof(command_str), "/api/%s", cmd.c_str());
uint8_t return_code = Command::process(command_str, true, input, output); // admin set
if (return_code == CommandRet::OK) {
#if defined(EMSESP_DEBUG)
EMSESP::logger().debug("Schedule command '%s' with data '%s' was successful", cmd.c_str(), data.c_str());
@@ -596,10 +596,6 @@ void WebSchedulerService::test() {
test_value = "(custom/seltemp)";
command("test5", test_cmd.c_str(), compute(test_value).c_str());
// note: this will fail unless test("boiler") is loaded before hand
test_value = "(boiler/outdoortemp)";
command("test6", test_cmd.c_str(), compute(test_value).c_str());
test_value = "boiler/flowtempoffset";
command("test7", test_cmd.c_str(), compute(test_value).c_str());
@@ -613,10 +609,35 @@ void WebSchedulerService::test() {
test_value = "(custom/seltemp - boiler/flowtempoffset) * 2.8 + 5";
command("test10", test_cmd.c_str(), compute(test_value).c_str());
test_cmd = "{\"method\":\"POST\",\"url\":\"http://192.168.1.42:8123/api/services/script/test_notify2\", \"header\":{\"authorization\":\"Bearer "
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhMmNlYWI5NDgzMmI0ODE2YWQ2NzU4MjkzZDE2YWMxZSIsImlhdCI6MTcyMTM5MTI0NCwiZXhwIjoyMDM2NzUxMjQ0fQ."
"S5sago1tEI6lNhrDCO0dM_WsVQHkD_laAjcks8tWAqo\"}}";
command("test11", test_cmd.c_str(), "");
// test case conversion
test_value = "(thermostat/hc1/modetype == \"comfort\")";
command("test11a", test_cmd.c_str(), compute(test_value).c_str()); // should be 1 true
test_value = "(thermostat/hc1/modetype == \"Comfort\")";
command("test11b", test_cmd.c_str(), compute(test_value).c_str()); // should be 1 true
test_value = "(thermostat/hc1/modetype == \"unknown\")";
command("test11c", test_cmd.c_str(), compute(test_value).c_str()); // should be 0 false
// can't find entity, should fail
test_value = "(boiler/storagetemp/value1)";
command("test12", test_cmd.c_str(), compute(test_value).c_str());
// can't find attribute, should fail
test_value = "(boiler/storagetemp1/value1)";
command("test13", test_cmd.c_str(), compute(test_value).c_str());
// check when entity has no value, should pass
test_value = "(boiler/storagetemp2/value)";
command("test14", test_cmd.c_str(), compute(test_value).c_str());
// should pass
test_value = "(boiler/storagetemp1/value)";
command("test15", test_cmd.c_str(), compute(test_value).c_str());
// test HTTP POST to call HA script
// test_cmd = "{\"method\":\"POST\",\"url\":\"http://192.168.1.42:8123/api/services/script/test_notify2\", \"header\":{\"authorization\":\"Bearer "
// "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhMmNlYWI5NDgzMmI0ODE2YWQ2NzU4MjkzZDE2YWMxZSIsImlhdCI6MTcyMTM5MTI0NCwiZXhwIjoyMDM2NzUxMjQ0fQ."
// "S5sago1tEI6lNhrDCO0dM_WsVQHkD_laAjcks8tWAqo\"}}";
// command("test99", test_cmd.c_str(), "");
}
#endif

View File

@@ -294,82 +294,82 @@ void test_36() {
}
void test_37() {
auto expected_response = "[{\"message\":\"no bad/value in boiler\"}]";
auto expected_response = "[{}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/bad/value"));
}
void test_38() {
auto expected_response = "[{\"message\":\"no valu in comfort\"}]";
auto expected_response = "[{\"message\":\"no attribute 'valu' in comfort\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/boiler/comfort/valu"));
}
void test_39() {
auto expected_response = "[{\"message\":\"no settings in system\"}]";
auto expected_response = "[{\"message\":\"no entity 'settings' in system\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings/locale2"));
}
void test_40() {
auto expected_response = "[{\"message\":\"no settings2 in system\"}]";
auto expected_response = "[{\"message\":\"no entity 'settings2' in system\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings2"));
}
void test_41() {
auto expected_response = "[{\"message\":\"no settings2 in system\"}]";
auto expected_response = "[{\"message\":\"no entity 'settings2' in system\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/system/settings2/locale2"));
}
void test_42() {
auto expected_response = "[{\"message\":\"no test_scheduler2 in scheduler\"}]";
auto expected_response = "[{\"message\":\"no entity 'test_scheduler2' in scheduler\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/test_scheduler2"));
}
void test_43() {
auto expected_response = "[{\"message\":\"no val in test_scheduler\"}]";
auto expected_response = "[{\"message\":\"no attribute 'val' in test_scheduler\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/test_scheduler/val"));
}
void test_44() {
auto expected_response = "[{\"message\":\"no test_scheduler2 in scheduler\"}]";
auto expected_response = "[{\"message\":\"no entity 'test_scheduler2' in scheduler\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/scheduler/test_scheduler2/val2"));
}
void test_45() {
auto expected_response = "[{\"message\":\"no seltemp2 in custom\"}]";
auto expected_response = "[{\"message\":\"no entity 'seltemp2' in custom\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/seltemp2"));
}
void test_46() {
auto expected_response = "[{\"message\":\"no val in seltemp\"}]";
auto expected_response = "[{\"message\":\"no attribute 'val' in seltemp\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/custom/seltemp/val"));
}
void test_47() {
auto expected_response = "[{\"message\":\"no test_sensor20 in temperaturesensor\"}]";
auto expected_response = "[{\"message\":\"no entity 'test_sensor20' in temperaturesensor\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/test_sensor20"));
}
void test_48() {
auto expected_response = "[{\"message\":\"no 0b_0c0d_0e0f_xxxx in temperaturesensor\"}]";
auto expected_response = "[{\"message\":\"no entity '0b_0c0d_0e0f_xxxx' in temperaturesensor\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/0B_0C0D_0E0F_XXXX"));
}
void test_49() {
auto expected_response = "[{\"message\":\"no bad in test_tempsensor2\"}]";
auto expected_response = "[{\"message\":\"no attribute 'bad' in test_tempsensor2\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/temperaturesensor/test_tempsensor2/bad"));
}
void test_50() {
auto expected_response = "[{\"message\":\"no bad in test_analogsensor1\"}]";
auto expected_response = "[{\"message\":\"no attribute 'bad' in test_analogsensor1\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analogsensor1/bad"));
}
void test_51() {
auto expected_response = "[{\"message\":\"no test_analog10 in analogsensor\"}]";
auto expected_response = "[{\"message\":\"no entity 'test_analog10' in analogsensor\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analog10"));
}
void test_52() {
auto expected_response = "[{\"message\":\"no test_analog10 in analogsensor\"}]";
auto expected_response = "[{\"message\":\"no entity 'test_analog10' in analogsensor\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("/api/analogsensor/test_analog10/bad2"));
}

View File

@@ -18,7 +18,7 @@ void shuntingYard_test2() {
}
void shuntingYard_test3() {
std::string expected_result = "rssi is -23 dbm";
std::string expected_result = "rssi is -23 dBm";
std::string test_value = "\"rssi is \"(system/network/rssi)\" dBm\"";
TEST_ASSERT_EQUAL_STRING(expected_result.c_str(), compute(test_value).c_str());
}