Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions modules/weko-itemtypes-ui/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 4 additions & 32 deletions modules/weko-itemtypes-ui/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'] == (
Expand Down Expand Up @@ -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 = {
Expand Down
8 changes: 4 additions & 4 deletions modules/weko-itemtypes-ui/weko_itemtypes_ui/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,23 +485,23 @@ 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')
prop_id = int(input_type[4:])
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'
Expand Down