diff --git a/heptapod/tests/test_wsgi.py b/heptapod/tests/test_wsgi.py index 2e5babd588bed4f737c6382661809aae72f232d0_aGVwdGFwb2QvdGVzdHMvdGVzdF93c2dpLnB5..298421411299869c6a37936893b7978670271c63_aGVwdGFwb2QvdGVzdHMvdGVzdF93c2dpLnB5 100644 --- a/heptapod/tests/test_wsgi.py +++ b/heptapod/tests/test_wsgi.py @@ -1,3 +1,4 @@ +import os import pytest from mercurial import ( error, @@ -43,6 +44,24 @@ assert hgs.repos_root == str(tmpdir) +def test_config_from_environ(tmpdir): + assert 'HEPTAPOD_HGRC' not in os.environ # checking our premises + hgrc = tmpdir.join('hgrc') + repos = tmpdir.join('repositories') + hgrc.write('\n'.join(('[heptapod]\n', + 'repositories-root=' + str(repos), + ))) + try: + os.environ['HEPTAPOD_HGRC'] = str(hgrc) + hgs = HgServe.default_app() + assert hgs.repos_root == str(repos) + finally: + del os.environ['HEPTAPOD_HGRC'] + + # really make sure we won't pollute other tests + assert 'HEPTAPOD_HGRC' not in os.environ + + def test_apply_heptapod_headers(tmpdir): hgs = make_hgserve(tmpdir) diff --git a/heptapod/wsgi.py b/heptapod/wsgi.py index 2e5babd588bed4f737c6382661809aae72f232d0_aGVwdGFwb2Qvd3NnaS5weQ==..298421411299869c6a37936893b7978670271c63_aGVwdGFwb2Qvd3NnaS5weQ== 100644 --- a/heptapod/wsgi.py +++ b/heptapod/wsgi.py @@ -182,4 +182,9 @@ res.setbodygen((e.message or b'') + b"\n") return res.sendresponse() + @classmethod + def default_app(cls): + HEPTAPOD_HGRC = os.environ.get('HEPTAPOD_HGRC') + if HEPTAPOD_HGRC: + return HgServe(conf_path=HEPTAPOD_HGRC) @@ -185,4 +190,3 @@ -HEPTAPOD_HGRC = os.environ.get('HEPTAPOD_HGRC') -if HEPTAPOD_HGRC: - hgserve = HgServe(conf_path="/etc/gitlab/heptapod.hgrc") + +hgserve = HgServe.default_app()