diff --git a/modules/weko-itemtypes-ui/tests/conftest.py b/modules/weko-itemtypes-ui/tests/conftest.py index 48cd86d114..8d0bb4d81e 100644 --- a/modules/weko-itemtypes-ui/tests/conftest.py +++ b/modules/weko-itemtypes-ui/tests/conftest.py @@ -961,9 +961,10 @@ def _create_itemtype_zip(id=1): 'schema': {'type': 'object', 'properties': {'key': {'type': 'string'}}}, 'form': {}, 'render': { - 'table_row': ['item_' + str(id)], + 'table_row': ['item_1001', 'item_1002'], 'meta_list': { - 'item_' + str(id): {'input_type': 'cus_' + str(id)} + 'item_1001': {'input_type': 'cus_' + str(id)}, + 'item_1002': {'input_type': 'cus_' + str(id)} } }, 'tag': 1, diff --git a/modules/weko-itemtypes-ui/tests/test_admin.py b/modules/weko-itemtypes-ui/tests/test_admin.py index a5e0671f44..01e6d97946 100644 --- a/modules/weko-itemtypes-ui/tests/test_admin.py +++ b/modules/weko-itemtypes-ui/tests/test_admin.py @@ -574,7 +574,7 @@ def test_item_type_import( 'Failed to import the item type. ' '"render" is missing or invalid in ItemType.json.' ) - + # Error if 'render' value does not have a 'table_row' key file = BytesIO(zip_file.getvalue()) no_table_row_zip = BytesIO() @@ -689,37 +689,9 @@ class MockProp: {'WEKO_ITEMTYPES_UI_FORCED_IMPORT_ENABLED': True} ): file = BytesIO(zip_file.getvalue()) - new_prop_zip = BytesIO() - file_contents = {} - with ZipFile(file, 'r') as zip_in: - for file_name in zip_in.namelist(): - with zip_in.open(file_name) as f: - content = f.read().decode('utf-8') - file_contents[file_name] = json.loads(content) - file_contents['ItemType.json']['render']['table_row'] = ['row1', 'row2'] - file_contents['ItemType.json']['render']['meta_list'] = { - 'row1': {'input_type': 'cus_1'}, - 'row2': {'input_type': 'cus_2'} - } - new_prop = { - 'id': 2, - 'name': 'test property 2', - 'schema': {'type': 'integer'}, - 'form': {'title_i18n': {'en': 'test property 2'}}, - 'forms': ['test form 2'], - 'delflg': False, - 'sort': None, - 'created': '2024-09-07T00:00:00+00:00', - 'updated': '2024-09-07T00:00:00+00:00' - } - file_contents['ItemTypeProperty.json'].append(new_prop) - with ZipFile(new_prop_zip, 'w', ZIP_DEFLATED) as zip_out: - for file_name, content in file_contents.items(): - zip_out.writestr(file_name, json.dumps(content)) - new_prop_zip.seek(0) data = { 'item_type_name': 'success test 3', - 'file': (new_prop_zip, 'test.zip') + 'file': (file, 'test.zip') } res = client.post(url, data=data, content_type='multipart/form-data') assert json.loads(res.data)['msg'] == ( @@ -761,11 +733,11 @@ class MockProp: res = client.post(url, data=data, content_type='multipart/form-data') assert res.status_code == 400 assert 'Failed to import the item type' in json.loads(res.data)['msg'] - + # Import suceeds but duplicated IDs reported with patch.dict( current_app.config, - {'WEKO_ITEMTYPES_UI_FORCED_IMPORT_ENABLED': True} + {'WEKO_ITEMTYPES_UI_FORCED_IMPORT_ENABLED': True} ): test_id = 1 expected_json = { diff --git a/modules/weko-itemtypes-ui/weko_itemtypes_ui/admin.py b/modules/weko-itemtypes-ui/weko_itemtypes_ui/admin.py index 4915119739..9a062e95c7 100644 --- a/modules/weko-itemtypes-ui/weko_itemtypes_ui/admin.py +++ b/modules/weko-itemtypes-ui/weko_itemtypes_ui/admin.py @@ -485,8 +485,8 @@ def item_type_import(self): prop.get('id'): prop for prop in import_data['ItemTypeProperty'] } - new_prop_ids = [] - duplicated_prop_ids = [] + new_prop_ids = set() + duplicated_prop_ids = set() for row_id in table_row_ids: # Extract the property ID from 'input_type' input_type = meta_list.get(row_id).get('input_type') @@ -494,14 +494,14 @@ def item_type_import(self): record = ItemTypeProps.get_record(prop_id) if not record: - new_prop_ids.append(prop_id) + new_prop_ids.add(prop_id) else: importing_prop = importing_props.get(prop_id) importing_updated = ( importing_prop.get('updated').split('+')[0]) record_updated = record.updated.isoformat() if importing_updated != record_updated: - duplicated_prop_ids.append(prop_id) + duplicated_prop_ids.add(prop_id) forced_import = current_app.config[ 'WEKO_ITEMTYPES_UI_FORCED_IMPORT_ENABLED'