Skip to content

Commit

Permalink
Migration derivative generation test.
Browse files Browse the repository at this point in the history
  • Loading branch information
emetsger committed Apr 6, 2021
1 parent fc6bd09 commit 25129bd
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/12-migration-derivative-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -e

BASE_TEST_FOLDER=12-migration-derivative-tests
DRUPAL_CONTAINER_NAME=$(docker ps | awk '{print $NF}'|grep drupal)
CURRENT_DIR=$(pwd)

# The Docker registry used to obtain the migration assets image
assets_repo=${MIGRATION_ASSETS_REPO:-ghcr.io/jhu-sheridan-libraries/idc-isle-dc}
# The name of the Docker image for migration assets
assets_image=${MIGRATION_ASSETS_IMAGE:-migration-assets}
# The migration assets image tag
assets_image_tag=${MIGRATION_ASSETS_IMAGE_TAG:-088c482.1617637226}
# The *external* port the migration assets HTTP server listens on
ext_assets_port=${MIGRATION_ASSETS_PORT:-8081}
# The name used by the migration assets container
assets_container=${MIGRATION_ASSETS_CONTAINER:-migration-assets}

# Locate test directory
if [ ! -d ${BASE_TEST_FOLDER} ] ;
then
BASE_TEST_FOLDER=tests/${BASE_TEST_FOLDER}
if [ ! -d ${BASE_TEST_FOLDER} ] ;
then
echo "Missing expected test directory ${BASE_TEST_FOLDER}"
exit 1
else
cd ${BASE_TEST_FOLDER}
fi
else
cd ${BASE_TEST_FOLDER}
fi

TESTCAFE_TESTS_FOLDER=$(pwd)/testcafe

# Start the backend that serves the media files to be migrated
# Listens internally on port 80 (addressed as http://<assets_container>/assets/)
docker run --name ${assets_container} --network gateway --rm -d ${assets_repo}/${assets_image}:${assets_image_tag}
trap "docker stop ${assets_container}" EXIT

# Execute migrations using testcafe
docker run --network gateway -v "${TESTCAFE_TESTS_FOLDER}":/tests testcafe/testcafe --screenshots path=/tests/screenshots,takeOnFails=true chromium /tests/**/*.js

# Back to parent directory
cd ${CURRENT_DIR}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {Selector} from 'testcafe';
import {adminUser} from './roles.js';


fixture`Migration Derivative Tests`
.page`https://islandora-idc.traefik.me/migrate_source_ui`
.beforeEach(async t => {
await t
.useRole(adminUser);
});

const migrate_new_items = 'idc_ingest_new_items';
const migrate_new_collection = 'idc_ingest_new_collection';
const migrate_media_file = 'idc_ingest_media_file';

const selectMigration = Selector('#edit-migrations');
const migrationOptions = selectMigration.find('option');

const contentList = "https://islandora-idc.traefik.me/admin/content";

test('Migrate Images for Derivative Generation', async t => {

// migrate the test objects into Drupal
await t
.click(selectMigration)
.click(migrationOptions.withAttribute('value', migrate_new_collection));

await t
.setFilesToUpload('#edit-source-file', [
'./migrations/derivative-collection.csv'
])
.click('#edit-import');

await t
.click(selectMigration)
.click(migrationOptions.withAttribute('value', migrate_new_items))

await t
.setFilesToUpload('#edit-source-file', [
'./migrations/derivative-islandora_object.csv'
])
.click('#edit-import');

await t
.click(selectMigration)
.click(migrationOptions.withAttribute('value', migrate_media_file))

await t
.setFilesToUpload('#edit-source-file', [
'./migrations/derivative-file.csv'
])
.click('#edit-import');

// verify the presence of the islandora object
const io_name = "Derivative Repository Item One"
await t.navigateTo(contentList)
const io = Selector('div.view-content').find('a').withText(io_name)
await t.expect(io.count).eql(1);

// list its media

await t.click(io)
await t.click(Selector('#rid-content').find('a').withText('Media'))

// assert the presence of the original media
const media_name = "Map Image";
const media = Selector('div.view-content').find('a').withText(media_name);
await t.expect(media.count).eql(1);

// assert expected attributes of the original media
await t.expect(media.parent('tr').child('td').nth(2).innerText).eql('File')
await t.expect(media.parent('tr').child('td').nth(3).innerText).eql('image/tiff')
await t.expect(media.parent('tr').child('td').nth(4).innerText).contains('Preservation Master File')
await t.expect(media.parent('tr').child('td').nth(4).innerText).contains('Original File')

// assert the presence of a derivative thumbnail and service image
// (increase timeout in case derivatives haven't been created yet?)
const service_derivative = Selector('div.view-content').find('a').withText('Service File.jpg');
const thumb_derivative = Selector('div.view-content').find('a').withText('Thumbnail Image.jpg');

console.log("Checking for derivatives ...")
const service_count = await service_derivative.count
const thumb_count = await thumb_derivative.count

// if a derivative isn't present yet, it may be because it hasn't been generated yet.
// in that case, wait 10 seconds and refresh the page, and see if it appears.
if (service_count < 1 || thumb_count < 1) {
console.log("Derivatives haven't appeared. Sleeping for 10 seconds, then trying again ...")
// sleep 10 seconds, refresh the page
await t.wait(10000);
await t.eval(() => location.reload(true));
}

await t.expect(service_derivative.count).eql(1);
await t.expect(thumb_derivative.count).eql(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local_id,title,title_language,alternative_title,member_of,contact_email,contact_name,collection_number,description,finding_aid
derivative-collection-01,Derivative Collection,eng,,,,,,Collection for Derivative tests;eng,
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local_id,name,original_name,mime_type,media_of,media_use,url
derivative_media_file_00001,Map Image,map-image.tif,image/tiff,derivative_io_01,Original File|Preservation Master File,http://migration-assets/assets/image/map-image.tif
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local_id,title,abstract,access_rights,access_terms,alt_title,collection_number,contributor,copyright,copyright_holder,creator,date_available,date_copyrighted,date_created,date_published,description,digital_identifier,digital_publisher,display_hints,dspace_identifier,dspace_itemid,extent,finding_aid,genre,geoportal_link,issn,is_part_of,item_barcode,jhir_uri,language,library_catalog_link,member_of,model,oclc_number,publisher,publisher_country,resource_type,spatial_coverage,subject,table_of_contents,title_language,years
derivative_io_01,Derivative Repository Item One,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,derivative-collection-01,Image,,,,,,,,,
11 changes: 11 additions & 0 deletions tests/12-migration-derivative-tests/testcafe/roles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Role } from 'testcafe';

/**
* Drupal administrator via local login
*/
export const adminUser = Role('https://islandora-idc.traefik.me/user/login', async t => {
await t
.typeText('#edit-name', 'admin')
.typeText('#edit-pass', 'password')
.click('#edit-submit');
});

0 comments on commit 25129bd

Please sign in to comment.