diff --git a/tests/unit/plugins/module_utils/test_table.py b/tests/unit/plugins/module_utils/test_table.py index f36c377c..e7b16893 100644 --- a/tests/unit/plugins/module_utils/test_table.py +++ b/tests/unit/plugins/module_utils/test_table.py @@ -152,6 +152,37 @@ def test_get_record_by_sys_id(self, client): assert dict(a=3, b="sys_id") == record client.get.assert_called_with("api/now/table/my_table/sys_id") + + def test_get_record_by_sys_id_must_exists(self, client): + client.get.return_value = Response( + 200, '{"result": {"a": 3, "b": "sys_id"}}', {"X-Total-Count": "1"} + ) + t = table.TableClient(client) + + record = t.get_record_by_sys_id("my_table", "sys_id", True) + + assert dict(a=3, b="sys_id") == record + client.get.assert_called_with("api/now/table/my_table/sys_id") + + def test_get_record_by_sys_id_no_record(self, client): + client.get.return_value = Response( + 404, '{"error": {"message": "no record found"}}', {} + ) + t = table.TableClient(client) + + record = t.get_record_by_sys_id("my_table", "sys_id") + + assert not record + client.get.assert_called_with("api/now/table/my_table/sys_id") + + def test_get_record_by_sys_id_no_record_must_exists(self, client): + client.get.return_value = Response( + 404, '{"error": {"message": "no record found"}}', {} + ) + t = table.TableClient(client) + + with pytest.raises(errors.ServiceNowError, match="No"): + t.get_record_by_sys_id("my_table", "sys_id", True) class TestTableCreateRecord: