Gitlab Community Edition Instance

Commit a4059a07 authored by mhellka's avatar mhellka
Browse files

Fixed tests

parent 906b8506
import pytest
from pycdstar3.client import CDStar
from pycdstar3 import CDStar
import json
from pycdstar3.model import JsonObject
@pytest.fixture
......@@ -19,9 +22,9 @@ def mockserver(mocker):
json=mocker.Mock(return_value={
'error': 'e', 'message': 'm', 'status': 's', 'detail': [('x', 'y')]}))
json = {}
payload = {}
if method == 'GET' and path == '/':
json = {
payload = {
'vaults': ['demo'],
'version': {
'source': {
......@@ -35,9 +38,9 @@ def mockserver(mocker):
}
}
elif method == 'GET' and path == '/x':
json = {'public': True}
payload = {'public': True}
elif method == 'GET' and path == '/_tx/tx':
json = {
payload = {
'isolation': 'snapshot',
'timeout': 60,
'ttl': 60,
......@@ -45,7 +48,7 @@ def mockserver(mocker):
'id': 'tx'
}
elif method == 'POST' and path == '/_tx':
json = {
payload = {
'isolation': 'snapshot',
'timeout': 60,
'ttl': 60,
......@@ -56,7 +59,8 @@ def mockserver(mocker):
raise ValueError()
elif method == 'POST' and path == '/demo':
# create an archive:
json = {'id': 'archive', 'vault': 'demo', 'revision': '0'}
return mocker.Mock(json=mocker.Mock(return_value=json))
payload = {'id': 'archive', 'vault': 'demo', 'revision': '0'}
payload = json.loads(json.dumps(payload), object_hook=JsonObject)
return mocker.Mock(json=mocker.Mock(return_value=payload))
return CDStar('', _session=MockSession(), auth=('test', 'test'))
import pathlib
import os
from argparse import Namespace
import pytest
from pycdstar3.cli.context import CliContext, ArchiveDir, Config, CliError
from pycdstar3.cli.context import CliContext, Workspace
from pycdstar3.model import JsonObject
@pytest.fixture
def cfgfile(tmpdir):
cfg = pathlib.Path(str(tmpdir)) / 'cdstar.conf'
cfg.write_text(
'[DEFAULT]\nopt = value\nserver = http://example.org/v3/\nvault = demo', encoding='utf8')
return str(cfg)
def workspace(tmpdir):
work = Workspace(tmpdir)
work.store_config(server="http://example.org/v3/", vault="test")
return Workspace(tmpdir)
@pytest.fixture
def context(tmpdir):
workdir = pathlib.Path(str(tmpdir)) / 'work'
workdir.mkdir()
return CliContext(workdir=str(workdir))
def context(workspace):
args = Namespace(quiet=False, verbose=0)
return CliContext(args, workspace.root)
def test_CliContext_config(context, cfgfile, capsys):
assert context.config
def test_CliContext_override_settings(tmpdir):
""" Environment variables override workspace settings and command-line arguments override both. """
args = Namespace(quiet=False, verbose=0)
Workspace(tmpdir).store_config(server="http://work/v3/", vault="work")
ctx = CliContext(args, tmpdir)
assert "work" in ctx.client.url
assert ctx.vault == "work"
def test_CliContext_no_config(context, capsys):
with pytest.raises(CliError):
_ = context.config
os.environ["CDSTAR_SERVER"] = "https://env/v3/"
os.environ["CDSTAR_VAULT"] = "env"
ctx = CliContext(args, tmpdir)
assert "env" in ctx.client.url
assert ctx.vault == "env"
def test_CliContext_resolve_error(context):
with pytest.raises(ValueError):
context.resolve('http://example.org')
args.server = "https://args/v3/"
args.vault = "args"
ctx = CliContext(args, tmpdir)
assert "args" in ctx.client.url
assert ctx.vault == "args"
@pytest.mark.parametrize(
'ref,vault,archive,file',
[
('http://usr:pwd@example.org/v3/', 'demo', '', ''),
('/x/y/z', 'x', 'y', '/z'),
('y/z', 'demo', 'y', '/z'),
]
)
def test_CliContext_resolve(cfgfile, context, ref, vault, archive, file):
assert context.resolve(ref)[1:] == (vault, archive, file)
def test_ArchiveDir(tmpdir):
with pytest.raises(IOError):
_ = ArchiveDir(str(tmpdir.join('fname')))
ad = ArchiveDir(str(tmpdir))
pathlib.Path(ad.metadir).mkdir()
with pytest.raises(IOError):
_ = ArchiveDir(str(tmpdir))
def test_Config(cfgfile):
cfg = Config(cfgfile)
assert 'opt' in cfg
assert list(cfg)
assert cfg['opt'] == 'value'
with pytest.raises(KeyError):
_ = cfg['abc']
def test_CliContext_client(context):
assert context.client
......@@ -10,7 +10,7 @@ import os
import pytest
from pycdstar3.client import CDStar, ApiError, FormUpdate
from pycdstar3 import CDStar, ApiError, FormUpdate
SERVER = os.environ.get("TEST_CDSTAR", "http://127.0.0.1:8080/v3/")
VAULT = os.environ.get("TEST_VAULT", "test")
......@@ -79,7 +79,6 @@ def test_clone(mockserver):
def test_service_info2(mockserver):
si = mockserver.service_info()
print(si)
assert si['version']['api'] == "3.0"
......
Supports Markdown
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