-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_cli.py
84 lines (70 loc) · 2.95 KB
/
test_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
#
# This file is part of CERN Document Server.
# Copyright (C) 2016 CERN.
#
# CERN Document Server is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# CERN Document Server is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CERN Document Server; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
"""Test cds-dojson CLI and jsonschema compiler."""
from __future__ import absolute_import
import json
import os
import shutil
import pkg_resources
import pytest
from click.testing import CliRunner
from cds_dojson.cli import compile_schema, convert_yaml2json
@pytest.mark.parametrize('src, compiled', [
('records/videos/video/video_src-v1.0.0.json',
'records/videos/video/video-v1.0.0.json'),
('records/videos/project/project_src-v1.0.0.json',
'records/videos/project/project-v1.0.0.json'),
('deposits/records/videos/video/video_src-v1.0.0.json',
'deposits/records/videos/video/video-v1.0.0.json'),
('deposits/records/videos/project/project_src-v1.0.0.json',
'deposits/records/videos/project/project-v1.0.0.json'),
])
def test_cli(src, compiled):
"""Test cds-dojson CLI."""
runner = CliRunner()
result = runner.invoke(compile_schema, [
pkg_resources.resource_filename('cds_dojson.schemas', src)
])
assert 0 == result.exit_code
compiled_schema_result = json.loads(result.output)
with open(
pkg_resources.resource_filename('cds_dojson.schemas',
compiled), 'r') as f:
compile_schema_expected = json.load(f)
assert compile_schema_expected == compiled_schema_result
@pytest.mark.parametrize('source, destination', [
('./tests/fixtures/books/ymls/', './tests/fixtures/books/results/')
])
def test_cli_convert_yaml2json(source, destination):
"""Test cds-dojson CLI 'convert_yaml2json' command"""
runner = CliRunner()
result = runner.invoke(convert_yaml2json, [source, destination])
assert 0 == result.exit_code
with open('./tests/fixtures/books/books_title_mock.json') as s:
# read the mock JSON file
json_mock = json.load(s)
with open(os.path.join(destination, 'books_title.json')) as s:
# read the newly created JSON file
json_converted = json.load(s)
assert json_mock == json_converted