Skip to content
Snippets Groups Projects
Commit ffbb8ae5 authored by Enrique Garcia's avatar Enrique Garcia
Browse files

Add ci tests

parent ba5d1556
No related branches found
No related tags found
No related merge requests found
......@@ -8,23 +8,27 @@ deploy_zenodo:
### Ideally to be used within a ci pipeline in where a container of the source code is build in a previous stage.
### You can have a look into https://gitlab.in2p3.fr/escape2020/wp3/template_project_escape/-/blob/master/.gitlab-ci.yml
# - build_image
script:
before_script:
### 1 - Install dependencies in the image and upload the files to Zenodo
- apt-get -y update
### INFORMATION FOR THE USER; Python, pip and wget are already installed in the container
#- cat /etc/os-release # Debian GNU/Linux 10 (buster)
#- pip3 --version # pip 20.1.1
#- python3 --version # 3.6.11 as th
- pip3 install requests
#- python3 --version # 3.6.11 as expected
- pip3 install requests numpy
### 2 - Check that you can correctly communicate with (sandobox)zenodo - Uncomment if needed.
- python3 .zenodoci/test_connection_zenodo.py -t $SANDBOX_ZENODO_TOKEN -s True
#- python3 .zenodoci/test_connection_zenodo.py -t $ZENODO_TOKEN -s False
### 2 - Get the last tag/release of the repository
### 3 - Get the last tag/release of the repository
- export REPOSITORY_NAME=zenodoci
- export REPOSITORY_BASE_URL=https://gitlab.in2p3.fr/escape2020/wp3/$REPOSITORY_NAME
- export LAST_RELEASE=`git ls-remote --tags --refs --sort="v:refname" $REPOSITORY_BASE_URL.git | tail -n1 | sed 's/.*\///'`
### 3 - Download the repository and move it to the build directory
### 4 - Download the repository and move it to the build directory
### If no release is found/correctly parsed, the script will download the last commit pushed to the master branch
- mkdir -p build
......@@ -40,22 +44,22 @@ deploy_zenodo:
fi
- ls ./build
### 4 - To deploy a NEW DEPOSIT to ZENODO SANDBOX
script:
### 5 - To deploy a NEW DEPOSIT to ZENODO SANDBOX
- >
python3 .zenodoci/upload_new_deposit.py
--token $SANDBOX_ZENODO_TOKEN
--sandbox_zenodo True
--input-directory ./build
### 4 - To deploy a NEW DEPOSIT to ZENODO
### 5 - To deploy a NEW DEPOSIT to ZENODO
#- >
# python3 .zenodoci/upload_new_deposit.py
# --token $ZENODO_TOKEN
# --sandbox_zenodo False
# --input-directory ./build
### 4 - To deploy a NEW VERSION to ZENODO: The deposit_id of the entry to be `new_versioned` MUST be provided.
### 5 - To deploy a NEW VERSION to ZENODO: The deposit_id of the entry to be `new_versioned` MUST be provided.
- >
python3 .zenodoci/upload_new_version_deposit.py
--token $SANDBOX_ZENODO_TOKEN
......
# -*- coding: utf-8 -*-
import argparse
import requests
import numpy as np
from distutils.util import strtobool
from zenodoapi import ZenodoAPI
if __name__ == '__main__':
# Required arguments
parser = argparse.ArgumentParser(description="Upload new deposit entry to Zenodo")
parser.add_argument('--token', '-t', type=str,
dest='zenodo_token',
help='Personal access token to (sandbox)Zenodo')
parser.add_argument('--sandbox_zenodo', '-s', action='store',
type=lambda x: bool(strtobool(x)),
dest='sandbox_flag',
help='Set the Zenodo environment.'
'If True connects with Zenodo. If False with Sanbox Zenodo',
default=False)
args = parser.parse_args()
z = ZenodoAPI(access_token=args.zenodo_token,
sandbox=args.sandbox_flag # True for sandbox.zenodo.org !! False for zenodo.org
)
# Test that the you can communicate with (sandbox)zenodo - you have passed the correct token
parameters = {'access_token': z.access_token}
test_connection = requests.get(
f'{z.zenodo_api_url}/deposit/depositions',
params=parameters
)
np.testing.assert_equal(test_connection.status_code, 200)
# Test that you can create a new entry - then all the rest of the pipeline will work
new_entry = z.create_new_entry()
np.testing.assert_equal(new_entry.status_code, 201)
# Erase the un-submitted entry and test that the order has been passed correctly
entry_id = new_entry.json()['id']
erase_unsubmitted_entry = requests.delete(
f'{z.zenodo_api_url}/deposit/depositions/{entry_id}',
params=parameters
)
np.testing.assert_equal(erase_unsubmitted_entry.status_code, 204)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment