Skip to content
Snippets Groups Projects
Commit 41333d54 authored by Romin's avatar Romin :eye:
Browse files

Add metadata_form test

parent 49348c94
No related branches found
No related tags found
No related merge requests found
...@@ -159,6 +159,27 @@ integration testing: ...@@ -159,6 +159,27 @@ integration testing:
paths: paths:
- ./report.md - ./report.md
###############################################################################
# This job tests the sourcecode in the python module.
###############################################################################
test metadata conformity:
stage: test
tags:
- "runner:docker"
- "env:devlef"
image: python:latest
before_script:
- python -V
- pip install .
script:
- COSCINE_API_TOKEN=${COSCINE_API_TOKEN}
- python ./tests/test_metadata_form.py
when: manual
artifacts:
paths:
- ./test-metadata-form-results.txt
############################################################################### ###############################################################################
# This job builds and deploys the Coscine Python SDK packge to the # This job builds and deploys the Coscine Python SDK packge to the
# Python Package index (PyPi). It is triggered with a new GitLab commit tag. # Python Package index (PyPi). It is triggered with a new GitLab commit tag.
......
import logging
from os import getenv
import coscine
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("test")
def main(fp):
token = getenv("COSCINE_API_TOKEN")
if not token:
raise ValueError(
"No Coscine API Token specified! "
"Create a new environment variable with "
"the name COSCINE_API_TOKEN!"
)
client = coscine.ApiClient(token)
application_profiles = client.application_profiles()
count = len(application_profiles)
valid = 0
invalid = 0
for index, ap in enumerate(application_profiles):
print(f"AP {index}/{count} {ap.uri}", file=fp)
try:
form = coscine.MetadataForm(client.application_profile(ap.uri))
form.test()
print(form, file=fp)
is_valid = form.validate()
print(f"Valid: {is_valid}", file=fp)
valid += 1
except Exception as ex:
print(f"Valid: {False}", file=fp)
print(ex, file=fp)
invalid += 1
print(f"Valid: {valid}", file=fp)
print(f"Invalid: {invalid}", file=fp)
print(f"Total: {count}", file=fp)
with open("test-metadata-form-results.txt", "w", encoding="utf-8") as fp:
main(fp)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment