add tests

This commit is contained in:
Dmitry Belyaev 2021-09-22 13:57:03 +03:00
parent b4e04c5e46
commit 30a9e6400a
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
2 changed files with 60 additions and 0 deletions

0
tests/__init__.py Normal file
View File

60
tests/test_pub1c-rest.py Normal file
View File

@ -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'<!DOCTYPE html>' 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']