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
9 changes: 9 additions & 0 deletions embargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
* Create a .env file setting bash environment variables of `API_KEY` and `ADMIN_SET` and `SWORD_TENANT`
* Run `embargo.sh`

Alternatively, `runtests.py` in the parent directory can also be used to achieve
the same test, using `python3 runtests.py < embargo/embargo.csv` from the parent directory,
allowing for easier changing of test parameters.

Currently, `embargo.csv` is generated by `python3 json_test_to_csv.py embargo.json`,
where `json_test_to_csv.py` gives some convenience features for data entry, such
as using arrays for list of arguments, instead of newline separated values. Note,
that the CSV will still be the authoritative source, and the preferred input method.

## What it does

This script will create two new works in the specified Admin Set: one embargoed work, and one open work. Each work has mulitple filesets. It will check the visibility and embargo values returned in the ATOM, for the work and for the filesets.
Expand Down
23 changes: 23 additions & 0 deletions embargo/embargo.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Title,Method,URI,Headers,Form,Payload,Expected,Store,Test,NS
Load Configuration File,FILE,config.xml,,,,,"BASE_URL=/config/base_url
DEFAULT_ADMIN_SET=/config/default_admin_set
COLLECTION_ID=/config/rw_collection_id
RO_COLLECTION_ID=/config/ro_collection_id
DENY_COLLECTION_ID=/config/deny_collection_id
API_KEY=/config/api_key",,
Post a SimpleZip with embargo,POST,$BASE_URL/sword/v2/collections/$DEFAULT_ADMIN_SET/works,Api-key: $API_KEY,payload=files/EtdEmbargo.zip,,201,"temp/post.body.out=*
WORKID=//*[local-name() = ""id""]/text()
WORKEDIT=//*[local-name() = ""link"" and @rel=""edit""]/@href",,atom=http://www.w3.org/2005/Atom
Extract Filesets created under this work,XSLT,embargo/get-first-fileset.xsl,,,temp/post.body.out,,FILESET_URL=//resultroot/*[1]/text(),,
Extract ATOM response to metadata format,XSLT,embargo/h4cmeta.xsl,,,temp/post.body.out,,temp/post.metadata.xml=*,"embargo=//metadata/visibility/text()
*=//metadata/visibility_after_embargo
*=//metadata/visibility_during_embargo
*=//metadata/embargo_release_date",
Fileset should inherit same embargo...GET Fileset,GET,$FILESET_URL,Api-key: $API_KEY,,,200,temp/fileset.body.out=*,"embargo=//metadata/visibility/text()
*=//metadata/visibility_after_embargo
*=//metadata/visibility_during_embargo
*=//metadata/embargo_release_date",
Extract ATOM response to metadata and check embargo for Fileset,XSLT,embargo/h4cmeta.xsl,,,temp/fileset.body.out,,temp/fileset.metadata.xml=*,"embargo=//metadata/visibility/text()
*=//metadata/visibility_after_embargo
*=//metadata/visibility_during_embargo
*=//metadata/embargo_release_date",
71 changes: 71 additions & 0 deletions embargo/embargo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"Headers": ["Title","Method","URI","Headers",
"Form","Payload","Expected","Store","Test","NS"],
"steps": [ {
"Title": "Load Configuration File",
"Method": "FILE",
"URI": "config.xml" ,
"Store": ["BASE_URL=/config/base_url",
"DEFAULT_ADMIN_SET=/config/default_admin_set",
"COLLECTION_ID=/config/rw_collection_id",
"RO_COLLECTION_ID=/config/ro_collection_id",
"DENY_COLLECTION_ID=/config/deny_collection_id",
"API_KEY=/config/api_key"]
},
{
"Title": "Post a SimpleZip with embargo",
"Method": "POST",
"URI": "$BASE_URL/sword/v2/collections/$DEFAULT_ADMIN_SET/works",
"Headers":["Api-key: $API_KEY"],
"Form": ["payload=files/EtdEmbargo.zip"],
"Expected":201,
"Store":["temp/post.body.out=*",
"WORKID=//atom:id/text()",
"WORKEDIT=//atom:link[@rel=\"edit\"]/@href"],
"NS":"atom=http://www.w3.org/2005/Atom"
},
{
"Title": "Extract Filesets created under this work",
"Method": "XSLT",
"URI": "embargo/get-first-fileset.xsl",
"Payload": "temp/post.body.out",
"Store":["FILESET_URL=//resultroot/*[1]/text()"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a simpler xpath would be /resultroot/result.

},
{
"Title": "Extract ATOM response to metadata format",
"Method": "XSLT",
"URI": "embargo/h4cmeta.xsl",
"Payload": "temp/post.body.out",
"Store":["temp/post.metadata.xml=*"],
"Test": ["embargo=//metadata/visibility/text()",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of these would be better with a root match (/) rather than a global search (//),

"*=//metadata/visibility_after_embargo",
"*=//metadata/visibility_during_embargo",
"*=//metadata/embargo_release_date"
]
},
{
"Title": "Fileset should inherit same embargo...GET Fileset",
"Method": "GET",
"Headers": ["Api-key: $API_KEY"],
"URI": "$FILESET_URL",
"Expected": 200,
"Store":["temp/fileset.body.out=*"],
"Test": ["embargo=//metadata/visibility/text()",
"*=//metadata/visibility_after_embargo",
"*=//metadata/visibility_during_embargo",
"*=//metadata/embargo_release_date"
]
},
{
"Title": "Extract ATOM response to metadata and check embargo for Fileset",
"Method": "XSLT",
"URI": "embargo/h4cmeta.xsl",
"Payload": "temp/fileset.body.out",
"Store":["temp/fileset.metadata.xml=*"],
"Test": ["embargo=//metadata/visibility/text()",
"*=//metadata/visibility_after_embargo",
"*=//metadata/visibility_during_embargo",
"*=//metadata/embargo_release_date"
]
}
]}
14 changes: 14 additions & 0 deletions embargo/get-first-fileset.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:h4cmeta="https://hykucommons.org/schema/metadata" xmlns:atom="http://www.w3.org/2005/Atom" exclude-result-prefixes="h4cmeta atom">
<xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>

<xsl:template match="/atom:entry">
<resultroot>
<xsl:for-each select="atom:link[@rel='edit-media']">
<result>
<xsl:value-of select="@href" />
</result>
</xsl:for-each>
</resultroot>
</xsl:template>

</xsl:stylesheet>
47 changes: 47 additions & 0 deletions embargo/json_test_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Read json file (provided in argv), and convert it into a csv that can be fed into
runtests.py. CSV is written to stdout.
"""

import json
import csv
import sys

csv_headers = ("Title","Method","URI","Headers",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the CSV headers named here, but also in the YAMLs as a Headers entry?

"Form","Payload","Expected","Store","Test","NS")


def usage():
print(f"Usage: python3 {__file__} <input.json>", file=sys.stderr)
print("Read json file, and convert it into a csv that can be fed into"
"runtests.py. CSV is written to stdout.", file=sys.stderr)

def main():
"""
JSON assumed to have a base object, with a field "steps" which is an
array of json objects. Each of the json objects corresponds to a row of the
csv. If a field of a json object is not specified, it is assumed to be empty.
Strings and ints are treated in trivial ways. JSON arrays are translated into
multiline sequences within CSV.

See ../README.md for details about CSV
"""
if len(sys.argv) != 2:
print("Invalid Number of arguments")
usage()
return
json_file = sys.argv[1]
with open(json_file) as f:
input_file = json.load(f)
output = csv.DictWriter(sys.stdout, csv_headers)
output.writeheader()
for step in input_file['steps']:
for k, v in step.items():
if type(v) == list:
step[k] = '\n'.join(v)
output.writerow(step)



if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions qa-issues/issue_376.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Title,Method,URI,Headers,Form,Payload,Expected,Store,Test,NS
Load Configuration File,FILE,config.xml,,,,,"BASE_URL=/config/base_url
DEFAULT_ADMIN_SET=/config/default_admin_set
COLLECTION_ID=/config/rw_collection_id
RO_COLLECTION_ID=/config/ro_collection_id
DENY_COLLECTION_ID=/config/deny_collection_id
API_KEY=/config/api_key
AUTH_KEY=/config/basic_auth",,
Get service document and check type in correct namespace,GET,$BASE_URL/sword/v2/service_document,"Api-key: $API_KEY
Content-type: application/xml",,,200,temp/service_document=*,True=count(//h:type)>0 and count(//a:type)=0,"h=https://hykucommons.org/schema/system
a=http://www.w3.org/2005/Atom"
28 changes: 28 additions & 0 deletions qa-issues/issue_376.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{
"Headers": ["Title","Method","URI","Headers",
"Form","Payload","Expected","Store","Test","NS"],
"steps": [ {
"Title": "Load Configuration File",
"Method": "FILE",
"URI": "config.xml" ,
"Store": ["BASE_URL=/config/base_url",
"DEFAULT_ADMIN_SET=/config/default_admin_set",
"COLLECTION_ID=/config/rw_collection_id",
"RO_COLLECTION_ID=/config/ro_collection_id",
"DENY_COLLECTION_ID=/config/deny_collection_id",
"API_KEY=/config/api_key",
"AUTH_KEY=/config/basic_auth"]
},
{
"Title": "Get service document and check type in correct namespace",
"Method": "GET",
"URI": "$BASE_URL/sword/v2/service_document",
"Headers": ["Api-key: $API_KEY", "Content-type: application/xml"],
"Store": ["temp/service_document=*"],
"Test":["True=count(//h:type)>0 and count(//a:type)=0"],
"Expected": 200,
"NS": ["h=https://hykucommons.org/schema/system", "a=http://www.w3.org/2005/Atom"]
}
]
}
17 changes: 17 additions & 0 deletions qa-issues/test_feed_id_issue_379.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Title,Method,URI,Headers,Form,Payload,Expected,Store,Test,NS
Load Configuration File,FILE,config.xml,,,,,"BASE_URL=/config/base_url
DEFAULT_ADMIN_SET=/config/default_admin_set
COLLECTION_ID=/config/rw_collection_id
RO_COLLECTION_ID=/config/ro_collection_id
DENY_COLLECTION_ID=/config/deny_collection_id
API_KEY=/config/api_key
AUTH_KEY=/config/basic_auth",,
Check default admin set for id in feed and check if content url public,GET,$BASE_URL/sword/v2/collections/$DEFAULT_ADMIN_SET,"Api-key: $API_KEY
Content-type: application/xml",,,200,"temp/admin_get=*
CONTENT_URL_FIRST=(//r:content)[1]/@src
CONTENT_URL_LAST=(//r:content)[last()]/@src","*=//r:feed/r:id
True=contains((//r:content)[1]/@src, ""concern"")",r=http://www.w3.org/2005/Atom
Check entries describe themselves correctly i.e. content points to self id,FILE,temp/admin_get,,,,,,"True=count(//r:entry)=count((//r:entry)[contains(./r:content/@src, ./r:id)])
True=count(//r:entry)=count(//r:entry[contains(./r:link[@rel=""edit""]/@href, ./r:id)])",r=http://www.w3.org/2005/Atom
Check feed describes itself correctly,FILE,temp/admin_get,,,,,,"True=contains(//r:feed/r:link[@rel=""edit""]/@href, /r:feed/r:id)",r=http://www.w3.org/2005/Atom
Check all entries that have child file sets have file set links,FILE,temp/admin_get,,,,,,"True=count(//r:entry/r:link[@rel=""edit-media""])=count(//r:entry/r:link[@rel=""edit-media""][contains(./@href, ""file_sets"")])",r=http://www.w3.org/2005/Atom
50 changes: 50 additions & 0 deletions qa-issues/test_feed_id_issue_379.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"Headers": ["Title","Method","URI","Headers",
"Form","Payload","Expected","Store","Test","NS"],
"steps": [ {
"Title": "Load Configuration File",
"Method": "FILE",
"URI": "config.xml" ,
"Store": ["BASE_URL=/config/base_url",
"DEFAULT_ADMIN_SET=/config/default_admin_set",
"COLLECTION_ID=/config/rw_collection_id",
"RO_COLLECTION_ID=/config/ro_collection_id",
"DENY_COLLECTION_ID=/config/deny_collection_id",
"API_KEY=/config/api_key",
"AUTH_KEY=/config/basic_auth"]
},
{
"Title": "Check default admin set for id in feed and check if content url public",
"Method": "GET",
"URI": "$BASE_URL/sword/v2/collections/$DEFAULT_ADMIN_SET",
"Headers": ["Api-key: $API_KEY", "Content-type: application/xml"],
"Expected": 200,
"Store": ["temp/admin_get=*", "CONTENT_URL_FIRST=(//r:content)[1]/@src",
"CONTENT_URL_LAST=(//r:content)[last()]/@src"],
"Test": ["*=//r:feed/r:id", "True=contains((//r:content)[1]/@src, \"concern\")"],
"NS": "r=http://www.w3.org/2005/Atom"
},
{
"Title": "Check entries describe themselves correctly i.e. content points to self id",
"Method": "FILE",
"URI": "temp/admin_get",
"Test": ["True=count(//r:entry)=count((//r:entry)[contains(./r:content/@src, ./r:id)])",
"True=count(//r:entry)=count(//r:entry[contains(./r:link[@rel=\"edit\"]/@href, ./r:id)])"],
"NS": "r=http://www.w3.org/2005/Atom"
},
{
"Title": "Check feed describes itself correctly",
"Method": "FILE",
"URI": "temp/admin_get",
"Test": ["True=contains(//r:feed/r:link[@rel=\"edit\"]/@href, /r:feed/r:id)"],
"NS": "r=http://www.w3.org/2005/Atom"
},
{
"Title": "Check all entries that have child file sets have file set links",
"Method": "FILE",
"URI":"temp/admin_get",
"Test": ["True=count(//r:entry/r:link[@rel=\"edit-media\"])=count(//r:entry/r:link[@rel=\"edit-media\"][contains(./@href, \"file_sets\")])"],
"NS": "r=http://www.w3.org/2005/Atom"
}
]
}
28 changes: 28 additions & 0 deletions qa-issues/test_file_work_root_entry_issue_378.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Title,Method,URI,Headers,Form,Payload,Expected,Store,Test,NS
Load Configuration File,FILE,config.xml,,,,,"BASE_URL=/config/base_url
DEFAULT_ADMIN_SET=/config/default_admin_set
COLLECTION_ID=/config/rw_collection_id
RO_COLLECTION_ID=/config/ro_collection_id
DENY_COLLECTION_ID=/config/deny_collection_id
API_KEY=/config/api_key",,
Check default admin set for id in feed,GET,$BASE_URL/sword/v2/collections/$DEFAULT_ADMIN_SET,"Api-key: $API_KEY
Content-type: application/xml",,,200,"temp/admin_get=*
WORK=(//r:link[contains(@href, ""works"")])[1]/@href
FILESET=(//r:link[contains(@href, ""file_sets"")])[1]/@href
FILEID=substring-after((//r:link[contains(@href, ""file_sets"")])[1]/@href, ""file_sets/"")",*=//r:feed/r:id,r=http://www.w3.org/2005/Atom
Check file root node for fileset is entry: GET,GET,$FILESET,"Api-key: $API_KEY
Content-type: application/xml",,,200,temp/example_fileset=*,entry=local-name(/*),r=http://www.w3.org/2005/Atom
Check file root node for work is entry: GET,GET,$WORK,"Api-key: $API_KEY
Content-type: application/xml",,,200,temp/example_work=*,entry=local-name(/*),r=http://www.w3.org/2005/Atom
Modify file metadata check file root node is entry: PUT,PUT,$FILESET,"Api-key: $API_KEY
Content-type: application/xml
Packaging: application/atom+xml;type=entry",,files/generic.full.xml,200,temp/example_work=*,entry=local-name(/*),r=http://www.w3.org/2005/Atom
Modify work metadata check work root node is entry: PUT,PUT,$WORK,"Api-key: $API_KEY
Content-type: application/xml
Packaging: application/atom+xml;type=entry",,files/generic.full.xml,200,temp/example_work=*,entry=local-name(/*),r=http://www.w3.org/2005/Atom
Post file metadata check work root node (POST),POST,$BASE_URL/sword/v2/collections/$DEFAULT_ADMIN_SET/works/,"Api-key: $API_KEY
Content-type: application/xml
Packaging: application/atom+xml;type=entry",,files/generic.minimal.xml,201,temp/work_submit=*,entry=local-name(/*),atom=http://www.w3.org/2005/Atom
Modify file metadata check file root node (POST),POST,$FILESET/$FILEID,"Api-key: $API_KEY
Content-type: application/xml
Packaging: application/atom+xml;type=entry",,files/generic.minimal.xml,201,temp/work_submit=*,entry=local-name(/*),atom=http://www.w3.org/2005/Atom
Loading