Gitlab Community Edition Instance

Commit 497df874 authored by xrotwang's avatar xrotwang
Browse files

Refactoring for better testability

- marked tests requiring a running CDStar server
- added a fixture implementing a mock server
- moved package into an intermediate `src` directory
  (see https://hynek.me/articles/testing-packaging/)
- added `tox.ini` for cross-version testing
parent b2c96da0
__pycache__/
*.py[cod]
*.egg-info/
venv/
build/
......@@ -7,3 +8,5 @@ dist/
MANIFEST
.idea/
.pytest_cache/
.tox/
include *.txt
include *.md
include README.md
graft src
global-exclude *.py[co]
requests >= 2.22
requests-toolbelt >= 0.9.1
tqdm >= 4.32.2
# development environment: install in development mode
-e .[dev,test]
[tool:pytest]
markers =
with_server: Requires a CDStar server
addopts =
-m "not with_server"
from distutils.core import setup
import pycdstar3
from setuptools import setup, find_packages
def read(name):
......@@ -10,12 +8,45 @@ def read(name):
setup(
name='pycdstar3',
version=pycdstar3.__version__,
version='3.0.dev0',
author='Marcel Hellkamp',
author_email='marc@gsites.de',
packages=['pycdstar3'],
license='LICENSE.txt',
description="Library and command-line client to access CDSTAR (3.0+)",
long_description=read('README.md'),
install_requires=read('requirements.txt').splitlines(),
long_description_content_type='text/markdown',
packages=find_packages(where='src'),
package_dir={'': 'src'},
include_package_data=True,
zip_safe=False,
platforms='any',
python_requires='>=3.5',
install_requires=[
'requests >= 2.22',
'requests-toolbelt >= 0.9.1',
'tqdm >= 4.32.2',
],
extras_require={
'dev': ['flake8', 'wheel', 'twine'],
'test': [
'mock',
'pytest>=3.6',
'pytest-mock',
'pytest-cov',
'coverage>=4.2',
],
},
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy'
],
)
......@@ -8,7 +8,7 @@ __all__ = ("CDStar", "FormUpdate", "ApiError")
PATH_TYPES = (str,)
if sys.version_info >= (3, 6):
patH_TYPES = (str, os.PathLike)
PATH_TYPES = (str, os.PathLike)
class CDStar:
......
import pytest
from pycdstar3.client import CDStar
@pytest.fixture
def mockserver(mocker):
class MockSession(mocker.Mock):
def request(self, method, *args, **kw):
json = {}
if method == 'GET' and args == ('/',):
json = {
'vaults': ['demo'],
'version': {
'source': {
'date': '2019-10-01T11:39:44Z',
'branch': '4b7a9983731a8a29251f9b2c0cea54e92af2413e',
'commit': '4b7a9983731a8a29251f9b2c0cea54e92af2413e'
},
'java': '25.111-b14',
'api': '3.0',
'cdstar': '3.0.0-SNAPSHOT'
}
}
return mocker.Mock(json=mocker.Mock(return_value=json))
return CDStar('', _session=MockSession())
......@@ -8,18 +8,22 @@ Integration tests of the client library against a live CDSTAR server.
import hashlib
import os
import pytest
from pycdstar3.client import CDStar
SERVER = os.environ.get("TEST_CDSTAR", "http://127.0.0.1:8080/v3/")
VAULT = os.environ.get("TEST_VAULT", "test")
@pytest.mark.with_server
def test_service_info():
c = CDStar(SERVER)
si = c.service_info()
assert si['version']['api'] == "3.0"
@pytest.mark.with_server
def test_tx():
c = CDStar(SERVER)
with c.begin():
......@@ -30,6 +34,7 @@ def test_tx():
assert c.tx is None
@pytest.mark.with_server
def test_tx_commit():
c = CDStar(SERVER)
with c.begin():
......@@ -38,12 +43,14 @@ def test_tx_commit():
assert c.tx is None
@pytest.mark.with_server
def test_vault_info():
c = CDStar(SERVER)
vi = c.vault_info(VAULT)
assert 'public' in vi
@pytest.mark.with_server
def test_crud_file():
c = CDStar(SERVER)
......@@ -63,3 +70,9 @@ def test_crud_file():
assert fp.read() == fget.content
assert "text/x-python" == fget.headers['Content-Type']
# no commit
def test_init(mockserver):
si = mockserver.service_info()
print(si)
assert si['version']['api'] == "3.0"
[tox]
envlist = py{35,36,37}
skip_missing_interpreters = true
[testenv]
extras = test
commands = pytest -m "not with_server" {posargs}
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