diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_pub1c-rest.py b/tests/test_pub1c-rest.py new file mode 100644 index 0000000..6aa8b4b --- /dev/null +++ b/tests/test_pub1c-rest.py @@ -0,0 +1,60 @@ +import os + +from flask import Flask +import pytest +import importlib +import yaml + + +@pytest.fixture +def temp_config(tmpdir) -> str: + configfile = str(tmpdir.join('config.yml')) + vrd_path = tmpdir.mkdir('vrds') + dir_path = tmpdir.mkdir('pubs') + apache_config = tmpdir.join('apache.cfg') + apache_config.write('#start\n') + flagfile = tmpdir.join('apache_restart') + + with open(configfile, 'w') as f: + yaml.dump({ + 'apache_config': str(apache_config), + 'vrd_path': str(vrd_path), + 'dir_path': str(dir_path), + 'url_base': '/1c', + 'platform_path': '/opt/1cv8/x86_64/current', + 'ws_module': 'wsap24.so', + 'vrd_params': { + 'debug': None, + 'server_addr': 'localhost' + }, + 'infobases': { + 'server_file': 'test/1CV8Clst.lst', + }, + 'apache_restart_flagfile': str(flagfile), + 'url_prefix': 'http://localhost', + }, f) + return configfile + + +@pytest.fixture +def flask_app(temp_config) -> Flask: + os.putenv('WEBPUB1C_CONFIG', temp_config) + pub1c = importlib.import_module('pub1c-rest') + return pub1c.app + + +@pytest.fixture +def client(flask_app): + return flask_app.test_client() + + +def test_index(client): + response = client.get('/') + assert b'' in response.data + + +def test_api_index(client): + response = client.get('/api/v1/') + data = response.get_json() + assert data == ['infobases-available', 'infobases-all', 'publications', + 'module', 'config', 'config-test', 'apache-restart']