Commit 96c3b6e7 authored by Enrique Garcia's avatar Enrique Garcia
Browse files

add some tests to the package

parent a6e8817b
Pipeline #112088 failed with stages
in 1 minute and 16 seconds
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
stages:
- install
- test
- deploy
- test_container
test_install:
stage: test
.virtualenv_template: &virtualenv_definition |
python -V
pip install -U pip setuptools wheel virtualenv
virtualenv venv
source venv/bin/activate
pip install pytest pytest-cov
pip install -e .
pip freeze
.junit_template: &junit_definition
artifacts:
reports:
junit: "junit*.xml"
install_py36:
stage: install
image: python:3.6-buster
script:
- apt-get -y update
......@@ -12,6 +36,22 @@ test_install:
only:
- branches
test_py36:
stage: test
image: python:3.6-buster
script:
- *virtualenv_definition
- pytest tests/
--junitxml=junit_py36.xml
--color=yes
--verbose
--cov=.
--cov-report=xml
--cov-report=term
<<: *junit_definition
only:
- branches
deploy_zenodo:
stage: deploy
image: python:3.6-buster
......@@ -66,7 +106,7 @@ deploy_zenodo:
only:
### Ideally this stage should be run only when a new release / tag of the source code is created, i.e., (- tags).
# The script is changed to check that the both `upload_new_deposit` and `upload_new_version_deposit` works nicely.
- branches # For testing
- master # For testing
#deploy_from_container:
......
......@@ -2,7 +2,8 @@
[![pipeline status](https://gitlab.in2p3.fr/escape2020/wp3/zenodoci/badges/master/pipeline.svg)](
https://gitlab.in2p3.fr/escape2020/wp3/zenodoci/-/commits/master)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![coverage report](https://gitlab.in2p3.fr/escape2020/wp3/zenodoci/badges/add_tests/coverage.svg)](
https://gitlab.in2p3.fr/escape2020/wp3/zenodoci/-/commits/add_tests)
Library to manage an upload to Zenodo through its REST API.
......
#!/usr/bin/env python
import json
import unittest
# import requests
from pathlib import Path
from os.path import dirname, realpath
from zenodoci.zenodoapi import ZenodoAPI
ROOT_DIR = dirname(dirname(realpath(__file__)))
class TestZenodoApiSandbox(unittest.TestCase):
def test_initialization_sandbox(self):
token = 'FakeToken'
z = ZenodoAPI(access_token=token,
sandbox=True,
proj_root_dir=ROOT_DIR)
assert isinstance(z, ZenodoAPI)
assert z.zenodo_api_url == 'https://sandbox.zenodo.org/api'
assert z.access_token == token
assert type(z.exist_codemeta_file) == bool
assert type(z.exist_zenodo_metadata_file) == bool
assert z.path_codemeta_file == ROOT_DIR
assert z.path_zenodo_metadata_file == ROOT_DIR
assert z.proj_root_dir == Path(ROOT_DIR)
assert isinstance(z.proj_root_dir, (Path, str))
class TestZenodoAPI(unittest.TestCase):
def test_initialization(self):
token = 'FakeToken'
z = ZenodoAPI(access_token=token,
sandbox=False,
proj_root_dir=ROOT_DIR)
assert isinstance(z, ZenodoAPI)
assert z.zenodo_api_url == 'https://zenodo.org/api'
assert z.access_token == token
assert type(z.exist_codemeta_file) == bool
assert type(z.exist_zenodo_metadata_file) == bool
assert z.path_codemeta_file == ROOT_DIR
assert z.path_zenodo_metadata_file == ROOT_DIR
assert z.proj_root_dir == Path(ROOT_DIR)
assert isinstance(z.proj_root_dir, (Path, str))
# def test_zenodo_api_methods(self):
# token = 'FakeToken'
# z = ZenodoAPI(access_token=token,
# sandbox=False,
# proj_root_dir=ROOT_DIR)
#
# url = f'https://zenodo.org/api/deposit/depositions'
# test = requests.get(url)
#
# fetch_user_entry = z.fetch_user_entries()
#
# # self.assertIsInstance(fetch_user_entry, test)
# assert isinstance(fetch_user_entry, requests.get(url=url))
def test_search_codemeta_file(self):
token = 'FakeToken'
z = ZenodoAPI(access_token=token,
sandbox=False,
proj_root_dir=ROOT_DIR)
assert z.exist_codemeta_file is False
z.search_codemeta_file()
assert z.exist_codemeta_file is True
codemeta_file_path = Path(ROOT_DIR) / 'codemeta.json'
assert z.path_codemeta_file == codemeta_file_path
assert codemeta_file_path.is_file()
print(z.path_codemeta_file, type(z.path_codemeta_file))
with open(z.path_codemeta_file) as f:
json.load(f)
def test_search_zenodo_json_file(self):
token = 'FakeToken'
z = ZenodoAPI(access_token=token,
sandbox=False,
proj_root_dir=ROOT_DIR)
assert z.exist_zenodo_metadata_file is False
z.search_zenodo_json_file()
assert z.exist_zenodo_metadata_file is True
zenodo_file_path = Path(ROOT_DIR) / '.zenodo.json'
assert z.path_zenodo_metadata_file == zenodo_file_path
assert zenodo_file_path.is_file()
with open(z.path_zenodo_metadata_file) as f:
json.load(f)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment