Skip to content

Commit

Permalink
WIP on #487.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Aug 18, 2023
1 parent 5597827 commit 2783af6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 80 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id,title,field_model,field_display_hints
book1,Using Islandora Workbench for Fun and Profit,28,2
id,title,field_model
book1,Using Islandora Workbench for Fun and Profit,Digital Document
7 changes: 3 additions & 4 deletions tests/assets/create_paged_content_test/create.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
task: create
host: "http://localhost:8000"
host: https://islandora.traefik.me
username: admin
password: islandora
password: password
input_dir: "tests/assets/create_paged_content_test"
allow_missing_files: true
nodes_only: true
id_field: field_local_identifier
media_type: image
6 changes: 0 additions & 6 deletions tests/assets/create_paged_content_test/delete.yml

This file was deleted.

12 changes: 6 additions & 6 deletions tests/assets/create_paged_content_test/metadata.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
field_local_identifier,parent_id,field_weight,file,title,field_model,field_member_of
001,,,,Postcard 1,28,
003,001,1,,Front of postcard 1,29,
004,001,2,,Back of postcard 1,29,
002,,,,Postcard 2,28,
006,002,1,,Front of postcard 2,29,
007,002,2,,Back of postcard 2,29,
001,,,,Postcard 1,Compound Object,
003,001,1,,Front of postcard 1,Image,
004,001,2,,Back of postcard 1,Image,
002,,,,Postcard 2,Compound Object,
006,002,1,,Front of postcard 2,Image,
007,002,2,,Back of postcard 2,Image,
80 changes: 33 additions & 47 deletions tests/islandora_tests_paged_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,36 @@ class TestCreatePagedContent(unittest.TestCase):

def setUp(self):
self.current_dir = os.path.dirname(os.path.abspath(__file__))
create_config_file_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_test', 'create.yml')
self.create_config_file_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_test', 'create.yml')

yaml = YAML()
with open(create_config_file_path, 'r') as f:
with open(self.create_config_file_path, 'r') as f:
config_file_contents = f.read()
config_data = yaml.load(config_file_contents)
config = {}
for k, v in config_data.items():
config[k] = v
self.islandora_host = config['host']

self.create_cmd = ["./workbench", "--config", create_config_file_path]
self.create_cmd = ["./workbench", "--config", self.create_config_file_path]

self.temp_dir = tempfile.gettempdir()
self.nid_file = os.path.join(self.temp_dir, 'workbenchcreatepagedcontenttestnids.txt')

def test_create_paged_content(self):
nids = list()
self.nids = list()
create_output = subprocess.check_output(self.create_cmd)
create_output = create_output.decode().strip()

# Write a file to the system's temp directory containing the node IDs of the
# nodes created during this test so they can be deleted in tearDown().
create_lines = create_output.splitlines()
with open(self.nid_file, "a") as fh:
fh.write("node_id\n")
for line in create_lines:
if 'created at' in line:
nid = line.rsplit('/', 1)[-1]
nid = nid.strip('.')
nids.append(nid)
fh.write(nid + "\n")
for line in create_lines:
if 'created at' in line:
nid = line.rsplit('/', 1)[-1]
nid = nid.strip('.')
self.nids.append(nid)

self.assertEqual(len(nids), 6)
self.assertEqual(len(self.nids), 6)

# Test a page object's 'field_member_of' value to see if it matches
# its parent's node ID. In this test, the last paged content object's
Expand All @@ -67,9 +63,9 @@ def test_create_paged_content(self):
# uses hard-coded term IDs from the Islandora Models taxonomy as used
# in the Islandora Playbook. If they change or are different in the
# Islandora this test is running against, this test will fail.
parent_node_id_to_test = nids[3]
parent_node_id_to_test = self.nids[3]
# The last node to be created was a page.
child_node_id_to_test = nids[5]
child_node_id_to_test = self.nids[5]
node_url = self.islandora_host + '/node/' + child_node_id_to_test + '?_format=json'
response = requests.get(node_url)
node_json = json.loads(response.text)
Expand All @@ -78,14 +74,11 @@ def test_create_paged_content(self):
self.assertEqual(int(parent_node_id_to_test), field_member_of)

def tearDown(self):
delete_config_file_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_test', 'delete.yml')
delete_cmd = ["./workbench", "--config", delete_config_file_path]
delete_output = subprocess.check_output(delete_cmd)
delete_output = delete_output.decode().strip()
delete_lines = delete_output.splitlines()
os.remove(self.nid_file)

preprocessed_csv_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_test', 'metadata.csv.preprocessed')
for nid in self.nids:
quick_delete_cmd = ["./workbench", "--config", self.create_config_file_path, '--quick_delete_node', self.islandora_host + '/node/' + nid]
quick_delete_output = subprocess.check_output(quick_delete_cmd)

preprocessed_csv_path = os.path.join(self.temp_dir, 'metadata.csv.preprocessed')
if os.path.exists(preprocessed_csv_path):
os.remove(preprocessed_csv_path)

Expand All @@ -98,10 +91,10 @@ class TestCreatePagedContentFromDirectories(unittest.TestCase):

def setUp(self):
self.current_dir = os.path.dirname(os.path.abspath(__file__))
create_config_file_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_from_directories_test', 'books.yml')
self.create_config_file_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_from_directories_test', 'books.yml')

yaml = YAML()
with open(create_config_file_path, 'r') as f:
with open(self.create_config_file_path, 'r') as f:
config_file_contents = f.read()
config_data = yaml.load(config_file_contents)
config = {}
Expand All @@ -111,29 +104,25 @@ def setUp(self):
self.islandora_username = config['username']
self.islandora_password = config['password']

self.create_cmd = ["./workbench", "--config", create_config_file_path]
self.create_cmd = ["./workbench", "--config", self.create_config_file_path]

self.temp_dir = tempfile.gettempdir()
self.nid_file = os.path.join(self.temp_dir, 'workbenchcreatepagedcontentfromdirectoriestestnids.txt')

def test_create_paged_content_from_directories(self):
nids = list()
self.nids = list()
create_output = subprocess.check_output(self.create_cmd)
create_output = create_output.decode().strip()

# Write a file to the system's temp directory containing the node IDs of the
# nodes created during this test so they can be deleted in tearDown().
create_lines = create_output.splitlines()
with open(self.nid_file, "a") as fh:
fh.write("node_id\n")
for line in create_lines:
if 'created at' in line:
nid = line.rsplit('/', 1)[-1]
nid = nid.strip('.')
nids.append(nid)
fh.write(nid + "\n")
for line in create_lines:
if 'created at' in line:
nid = line.rsplit('/', 1)[-1]
nid = nid.strip('.')
self.nids.append(nid)

self.assertEqual(len(nids), 4)
self.assertEqual(len(self.nids), 4)

# Test a page object's 'field_member_of' value to see if it matches its
# parent's node ID. In this test, we'll test the second page. Note: the
Expand All @@ -142,7 +131,7 @@ def test_create_paged_content_from_directories(self):
# in the Islandora Playbook. If they change or are different in the
# Islandora this test is running against, this test will fail. Also note
# that this test creates media and does not delete them.
parent_node_id_to_test = nids[0]
parent_node_id_to_test = self.nids[0]
# Get the REST feed for the parent node's members.
members_url = self.islandora_host + '/node/' + parent_node_id_to_test + '/members?_format=json'
# Need to provide credentials for this REST export.
Expand All @@ -160,14 +149,11 @@ def test_create_paged_content_from_directories(self):
self.assertEqual(expected_member_weights, retrieved_member_weights)

def tearDown(self):
delete_config_file_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_from_directories_test', 'delete.yml')
delete_cmd = ["./workbench", "--config", delete_config_file_path]
delete_output = subprocess.check_output(delete_cmd)
delete_output = delete_output.decode().strip()
delete_lines = delete_output.splitlines()
os.remove(self.nid_file)

preprocessed_csv_path = os.path.join(self.current_dir, 'assets', 'create_paged_content_from_directories_test', 'samplebooks', 'metadata.csv.preprocessed')
for nid in self.nids:
quick_delete_cmd = ["./workbench", "--config", self.create_config_file_path, '--quick_delete_node', self.islandora_host + '/node/' + nid]
quick_delete_output = subprocess.check_output(quick_delete_cmd)

preprocessed_csv_path = os.path.join(self.temp_dir, 'metadata.csv.preprocessed')
if os.path.exists(preprocessed_csv_path):
os.remove(preprocessed_csv_path)

Expand Down
6 changes: 5 additions & 1 deletion workbench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5571,7 +5571,11 @@ def create_children_from_directory(config, parent_csv_record, parent_node_id):
# Add field_model if that field exists in the child's content type.
entity_fields = get_entity_fields(config, 'node', config['paged_content_page_content_type'])
if 'field_model' in entity_fields:
node_json['field_model'] = [{'target_id': config['paged_content_page_model_tid'], 'target_type': 'taxonomy_term'}]
if not value_is_numeric(config['paged_content_page_model_tid'].strip()) and config['paged_content_page_model_tid'].strip().startswith('http'):
paged_content_model_tid = get_term_id_from_uri(config, config['paged_content_page_model_tid'].strip())
else:
paged_content_model_tid = config['paged_content_page_model_tid'].strip()
node_json['field_model'] = [{'target_id': paged_content_model_tid, 'target_type': 'taxonomy_term'}]

if 'field_display_hints' in parent_csv_record:
node_json['field_display_hints'] = [{'target_id': parent_csv_record['field_display_hints'], 'target_type': 'taxonomy_term'}]
Expand Down

0 comments on commit 2783af6

Please sign in to comment.