Skip to content

Commit

Permalink
Check that folder exists before metadata and tests for subfolder with…
Browse files Browse the repository at this point in the history
… spaces
  • Loading branch information
claravox authored Feb 7, 2024
1 parent bacf7a5 commit db69298
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
5 changes: 4 additions & 1 deletion meta_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def load(ctx, coll):
# - Who are we dealing with?
user_full_name = user.full_name(ctx)

if not collection.exists(ctx, coll):
return api.Error('nonexistent', 'The given path does not exist')

# - What kind of collection path is this?
space, zone, group, subpath = pathutil.info(coll)
if space not in [pathutil.Space.RESEARCH, pathutil.Space.DEPOSIT, pathutil.Space.VAULT]:
Expand Down Expand Up @@ -194,7 +197,7 @@ def load(ctx, coll):
except Exception as e:
log.write(ctx, 'Unknown error while validating <{}> against schema id <{}>: {}'
.format(meta_path, current_schema_id, str(e)))
return api.Error('internal', 'The metadata file is could not be validated due to an internal error.')
return api.Error('internal', 'The metadata file could not be validated due to an internal error.')
else:
# No errors! Offer automatic transformation.
return api.Error('transformation_needed',
Expand Down
25 changes: 20 additions & 5 deletions tests/features/ui/ui_meta.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Feature: Meta UI
Background:
Given user researcher is authenticated
And collection /tempZone/home/research-initial exists
And collection /tempZone/home/research-initial/folder space exists
And /tempZone/home/research-initial is unlocked


Expand All @@ -12,15 +13,29 @@ Feature: Meta UI
And module "research" is shown
When user browses to folder <folder>
And user opens metadata form
And users fills in metadata form
And users clicks save button
Then metadata form is saved as yoda-metadata.json
And user fills in metadata form
And user clicks save button
Then metadata form is saved as yoda-metadata.json for folder <folder>

Examples:
| folder |
| research-initial |


Scenario Outline: Save metadata subfolder
Given user researcher is logged in
And module "research" is shown
When user browses to folder <folder1>
When user browses to folder <folder2>
And user opens metadata form
And user clicks save button
Then metadata form is saved as yoda-metadata.json for folder <folder>

Examples:
| folder | folder1 | folder2 |
| research-initial/folder space | research-initial | folder space |


Scenario Outline: Delete metadata
Given user researcher is logged in
And module "research" is shown
Expand All @@ -46,10 +61,10 @@ Feature: Meta UI
| research-default-3 |


Scenario Outline: Check that path is safe
Scenario Outline: Script in path
Given user researcher is logged in
When the user navigates to <page>
Then the 404 error page is shown
Then an error is shown that the path does not exist

Examples:
| page |
Expand Down
10 changes: 10 additions & 0 deletions tests/step_defs/ui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ def ui_text_shown(browser, text):
@then(parsers.parse("user browses to folder {folder}"))
def ui_browse_folder(browser, folder):
link = []
counter = 0

while len(link) == 0:
link = browser.links.find_by_partial_text(folder)
if len(link) > 0:
link.click()
else:
browser.find_by_id('file-browser_next').click()
if counter > 6:
assert False
counter += 1


@when(parsers.parse("user clicks on file {file} in folder {folder}"))
def ui_browse_file(browser, file, folder):
browser.find_by_css("[data-path='/{}/{}']".format(folder, file)).click()


@when('user clicks go to group manager')
Expand Down
16 changes: 11 additions & 5 deletions tests/step_defs/ui/test_ui_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time

from pytest_bdd import (
parsers,
scenarios,
then,
when,
Expand All @@ -20,7 +21,7 @@ def ui_metadata_open(browser):
browser.find_by_css('button.metadata-form').click()


@when('users fills in metadata form')
@when('user fills in metadata form')
def ui_metadata_fill(browser):
for input in browser.find_by_css('input.is-invalid'):
if input.visible:
Expand Down Expand Up @@ -68,7 +69,7 @@ def ui_metadata_check_person_id_field(browser):
assert parent.find_by_css('.form-control')[0]['placeholder'] == '51161516100'


@when('users clicks save button')
@when('user clicks save button')
def ui_metadata_save(browser):
browser.find_by_css('.yodaButtons .btn-primary').click()

Expand All @@ -79,11 +80,16 @@ def ui_metadata_delete(browser):
browser.find_by_css('.confirm').click()


@then('metadata form is saved as yoda-metadata.json')
def ui_metadata_saved(browser):
assert browser.is_text_present("Updated metadata of folder </research-initial>")
@then(parsers.parse('metadata form is saved as yoda-metadata.json for folder {folder}'))
def ui_metadata_saved(browser, folder):
assert browser.is_text_present("Updated metadata of folder </{}>".format(folder))


@then('metadata is deleted from folder')
def ui_metadata_deleted(browser):
browser.is_text_present("Deleted metadata of folder </research-initial>", wait_time=3)


@then('an error is shown that the path does not exist')
def ui_metadata_path_not_exist(browser):
browser.is_text_present("The given path does not exist", wait_time=3)

0 comments on commit db69298

Please sign in to comment.