Skip to content

Commit f7c2e5e

Browse files
committed
Bug#35805288 Edit Rest Object issues
- The 'no_update' column was missing in the update statement - Disable the service and schema selection when editing a dbObject Change-Id: I6845a1558275d83f7d92c77624e729c4030f77e8
1 parent 9731fc5 commit f7c2e5e

File tree

14 files changed

+293
-70
lines changed

14 files changed

+293
-70
lines changed

gui/extension/tests/e2e/lib/db.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,17 +1161,25 @@ export class Database {
11611161

11621162
if (restObject.restServicePath) {
11631163
const inService = await dialog.findElement(locator.mrsDbObjectDialog.service);
1164-
await inService.click();
1165-
const popup = await driver.wait(until.elementLocated(locator.mrsDbObjectDialog.serviceList),
1166-
constants.wait5seconds, "Service list was not found");
1167-
await popup.findElement(By.id(restObject.restServicePath)).click();
1164+
const isDisabled = await inService.getAttribute("disabled")
1165+
.then(() => { return true; }).catch(() => { return false; });
1166+
if (!isDisabled) {
1167+
await inService.click();
1168+
const popup = await driver.wait(until.elementLocated(locator.mrsDbObjectDialog.serviceList),
1169+
constants.wait5seconds, "Service list was not found");
1170+
await popup.findElement(By.id(restObject.restServicePath)).click();
1171+
}
11681172
}
11691173
if (restObject.restSchemaPath) {
11701174
const inSchema = await dialog.findElement(locator.mrsDbObjectDialog.schema);
1171-
await inSchema.click();
1172-
const popup = await driver.wait(until.elementLocated(locator.mrsDbObjectDialog.schemaList),
1173-
constants.wait5seconds, "Schema drop down list was not found");
1174-
await popup.findElement(By.id(restObject.restSchemaPath)).click();
1175+
const isDisabled = await inSchema.getAttribute("disabled")
1176+
.then(() => { return true; }).catch(() => { return false; });
1177+
if (!isDisabled) {
1178+
await inSchema.click();
1179+
const popup = await driver.wait(until.elementLocated(locator.mrsDbObjectDialog.schemaList),
1180+
constants.wait5seconds, "Schema drop down list was not found");
1181+
await popup.findElement(By.id(restObject.restSchemaPath)).click();
1182+
}
11751183
}
11761184
if (restObject.restObjectPath) {
11771185
const inObjPath = await dialog.findElement(locator.mrsDbObjectDialog.requestPath);

gui/extension/tests/e2e/lib/until.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,14 @@ export const extensionIsReady = (): Condition<boolean> => {
270270
console.log("<<<<<DEV TOOLS Console log>>>>");
271271
console.log(await logs.get(logging.Type.BROWSER));
272272

273-
let text = `Extension was not loaded successfully after ${feLoadTries} tries. Check the logs. `;
273+
const text = `Extension was not loaded successfully after ${feLoadTries} tries. Check the logs.`;
274274
// one last try to recover
275275
const path = join(await Misc.getExtentionOutputLogsFolder(), constants.feLogFile);
276276
const output = (await fs.readFile(path)).toString();
277-
278-
if (output.match(/(ERROR|error)/) !== null) {
277+
console.log("-----OUTPUT LOGS------");
278+
console.log(output);
279+
throw new Error(text);
280+
/*if (output.match(/(ERROR|error)/) !== null) {
279281
console.log("An error was found on the OUTPUT tab, removing Internal DB");
280282
await Misc.removeInternalDB();
281283
text += `Internal DB was removed. Please re-run the tests`;
@@ -287,7 +289,7 @@ export const extensionIsReady = (): Condition<boolean> => {
287289
}
288290
} else {
289291
throw new Error(text);
290-
}
292+
}*/
291293
}
292294

293295
credentialHelperOk = await Misc.findOnMySQLShLog(/Failed to initialize the default helper/);

gui/extension/tests/e2e/tests/ui-rest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,6 @@ describe("MySQL REST Service", () => {
626626
const treeTable = await Misc.getTreeElement(constants.dbTreeSection,
627627
`/${tableToDump} (${tableToDump})`);
628628
const editedObject: interfaces.IRestObject = {
629-
//restServicePath: `${serviceToEdit.settings.hostNameFilter}${serviceToEdit.servicePath}`,
630629
restServicePath: `${globalService.settings.hostNameFilter}${globalService.servicePath}`,
631630
restSchemaPath: sakilaRestSchema.restSchemaPath,
632631
restObjectPath: `/editedObject`,

gui/frontend/src/modules/mrs/dialogs/MrsDbObjectDialog.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export class MrsDbObjectDialog extends AwaitableValueEditDialog {
142142
return request.values?.dbSchemaId === schema.id;
143143
});
144144

145+
let updateDisabled;
146+
if (!this.createDbObject) {
147+
updateDisabled = [CommonDialogValueOption.Disabled];
148+
}
149+
145150
const mainSection: IDialogSection = {
146151
caption: title,
147152
values: {
@@ -152,6 +157,7 @@ export class MrsDbObjectDialog extends AwaitableValueEditDialog {
152157
choices: services.map((service) => { return service.hostCtx; }),
153158
horizontalSpan: 2,
154159
description: "The path of the REST Service",
160+
options: updateDisabled,
155161
},
156162
schema: {
157163
type: "choice",
@@ -162,6 +168,7 @@ export class MrsDbObjectDialog extends AwaitableValueEditDialog {
162168
}),
163169
horizontalSpan: 2,
164170
description: "The path of the REST Schema",
171+
options: updateDisabled,
165172
},
166173
requestPath: {
167174
type: "text",

mrs_plugin/db_objects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ def set_crud_operations(db_object_id=None, crud_operations=None,
742742
current_crud, current_format = lib.db_objects.get_crud_operations(session, db_object_id)
743743

744744
objects = lib.db_objects.get_objects(session=session, db_object_id=db_object_id)
745+
for object in objects:
746+
object["fields"] = lib.db_objects.get_object_fields_with_references(session, object["id"])
745747

746748
try:
747749
lib.database.grant_db_object(

mrs_plugin/lib/db_objects.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ def add_db_object(session, schema_id, db_object_name, request_path, db_object_ty
261261
crud_operation_format, comments, media_type, auto_detect_media_type, auth_stored_procedure,
262262
options, objects, db_object_id=None, reuse_ids=False):
263263

264-
options = core.convert_json(options)
265-
objects = core.convert_json(objects)
266-
267264
if not isinstance(db_object_name, str):
268265
raise Exception('Invalid object name.')
269266

@@ -298,8 +295,6 @@ def add_db_object(session, schema_id, db_object_name, request_path, db_object_ty
298295
core.check_request_path(
299296
session, schema["host_ctx"] + schema["request_path"] + request_path)
300297

301-
core.check_mrs_object_names(session=session, db_schema_id=schema_id, objects=objects)
302-
303298
if db_object_type == "PROCEDURE" or db_object_type == "FUNCTION":
304299
crud_operations = ["UPDATE"]
305300

@@ -575,6 +570,7 @@ def set_object_fields_with_references(session, db_object_id, obj):
575570
"allow_filtering": field.get("allow_filtering"),
576571
"allow_sorting": field.get("allow_sorting", 0),
577572
"no_check": field.get("no_check"),
573+
"no_update": field.get("no_update"),
578574
"sdk_options": core.convert_dict_to_json_string(field.get("sdk_options")),
579575
"comments": field.get("comments"),
580576
}).exec(session)

mrs_plugin/tests/conftest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,23 @@ def init_mrs():
7070
temp_dirs.append(temp_dir)
7171
PHONE_BOOKS[db] = helpers.create_mrs_phonebook_schema(session, "/test", db, temp_dir)
7272

73+
lib.services.set_current_service_id(session, PHONE_BOOKS["PhoneBook"]["service_id"])
74+
7375
yield session
7476

7577
for temp_dir in temp_dirs:
7678
temp_dir.cleanup()
7779

7880
session.close()
79-
mysqlsh.globals.dba.stop_sandbox_instance(connection_data["port"], {
80-
"password": connection_data["password"],
81+
# mysqlsh.globals.dba.stop_sandbox_instance(connection_data["port"], {
82+
# "password": connection_data["password"],
83+
# "sandboxDir": deployment_dir.name
84+
# })
85+
86+
mysqlsh.globals.dba.kill_sandbox_instance(connection_data["port"], {
8187
"sandboxDir": deployment_dir.name
8288
})
8389

84-
8590
@pytest.fixture(scope="session")
8691
def phone_book(init_mrs):
8792
yield PHONE_BOOKS["PhoneBook"]
@@ -96,8 +101,8 @@ def analog_phone_book(init_mrs):
96101

97102

98103
@pytest.fixture(scope="session")
99-
def table_contents(phone_book) -> helpers.TableContents:
100-
def create_table_content_object(table_name, schema=None, take_snapshot=True):
104+
def table_contents(phone_book):
105+
def create_table_content_object(table_name, schema=None, take_snapshot=True) -> helpers.TableContents:
101106
schema = schema or phone_book
102107
return helpers.TableContents(schema["session"], table_name, take_snapshot)
103108
yield create_table_content_object

mrs_plugin/tests/unit/helpers.py

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525
import mysqlsh
2626
from mrs_plugin import lib
27-
from ... schemas import add_schema, delete_schema
28-
from ... services import add_service, delete_service, get_service
29-
from ... db_objects import add_db_object, delete_db_object
27+
from mrs_plugin.schemas import add_schema, delete_schema
28+
from mrs_plugin.services import add_service, delete_service, get_service
29+
from mrs_plugin.db_objects import add_db_object, delete_db_object
3030

31-
def get_default_db_object_init(schema_id, name=None, request_path=None):
31+
def get_default_db_object_init(session, schema_id, name=None, request_path=None):
32+
object_id = lib.core.get_sequence_id(session)
3233
return {
3334
"schema_id": schema_id,
3435
"db_object_name": name or "ContactBasicInfo",
@@ -44,12 +45,48 @@ def get_default_db_object_init(schema_id, name=None, request_path=None):
4445
"enabled": True,
4546
"media_type": "media type",
4647
"auto_detect_media_type": True,
47-
"auth_stored_procedure": False,
48+
"auth_stored_procedure": None,
4849
"options": {
4950
"aaa": "val aaa",
5051
"bbb": "val bbb"
5152
},
52-
"objects": [],
53+
"objects": [
54+
{
55+
"id": object_id,
56+
"name":"MyServicePhoneBookContactsWithEmail",
57+
"position":0,
58+
"kind":"RESULT",
59+
"comments": "Comment for object",
60+
"sdk_options": {
61+
"option1": "value 1",
62+
"option2": "value 2",
63+
},
64+
"fields":[
65+
{
66+
"id": lib.core.get_sequence_id(session),
67+
"object_id": object_id,
68+
"name":"id",
69+
"position":1,
70+
"db_column":{
71+
"comment":"",
72+
"datatype":"int",
73+
"id_generation":None,
74+
"is_generated":False,
75+
"is_primary":False,
76+
"is_unique":False,
77+
"name":"id",
78+
"not_null":True,
79+
"srid":None
80+
},
81+
"enabled":True,
82+
"allow_filtering":True,
83+
"allow_sorting":False,
84+
"no_check":False,
85+
"no_update":False
86+
}
87+
]
88+
}
89+
],
5390
}
5491

5592
def get_default_user_init(auth_app_id,
@@ -265,11 +302,14 @@ def take_snapshot(self):
265302
self._snapshot = TableContents.TableSnapshot(lib.core.select(table=self._table_name).exec(self._session).items)
266303

267304
@property
268-
def snapshot(self):
305+
def snapshot(self) -> TableSnapshot:
306+
assert self._snapshot is not None
269307
return self._snapshot
270308

271309
@property
272310
def same_as_snapshot(self):
311+
assert self._snapshot is not None
312+
273313
current = lib.core.select(table=self._table_name).exec(self._session).items
274314
if len(current) != len(self._snapshot):
275315
return False
@@ -281,6 +321,8 @@ def same_as_snapshot(self):
281321
return True
282322

283323
def assert_same(self):
324+
assert self._snapshot is not None
325+
284326
current = lib.core.select(table=self._table_name).exec(self._session).items
285327
if len(current) != len(self._snapshot):
286328
return False
@@ -290,6 +332,8 @@ def assert_same(self):
290332

291333
@property
292334
def diff_text(self):
335+
assert self._snapshot is not None
336+
293337
current = lib.core.select(table=self._table_name).exec(self._session).items
294338
if len(self._snapshot._data) != len(current):
295339
return f"\nCurrent:\n {current}\nExpected:\n {self._snapshot._data}"
@@ -444,7 +488,7 @@ def create_mrs_phonebook_schema(session, service_context_root, schema_name, temp
444488
}
445489
from ... schemas import add_schema
446490
schema_id = add_schema(**schema_data)
447-
schema = lib.schemas.get_schema(session, schema_id=schema_id)
491+
schema = lib.schemas.get_schema(session, schema_id=lib.core.id_to_binary(schema_id, "schema_id"))
448492

449493
content_set = lib.content_sets.get_content_set(session, service_id=service["id"], request_path="/test_content_set")
450494

0 commit comments

Comments
 (0)