2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 09:02:10 +00:00

[Minor] Added test case in bench test suite

This commit is contained in:
shreyas 2016-06-29 16:26:28 +05:30
parent 02922107f4
commit fd739aa199
5 changed files with 47 additions and 14 deletions

View File

@ -29,7 +29,8 @@ bench_command.add_command(switch_to_v5)
from bench.commands.utils import (start, restart, set_nginx_port, set_ssl_certificate, set_ssl_certificate_key, set_url_root,
set_mariadb_host, set_default_site, download_translations, shell, backup_site, backup_all_sites, release, renew_lets_encrypt)
set_mariadb_host, set_default_site, download_translations, shell, backup_site, backup_all_sites, release, renew_lets_encrypt,
disable_production)
bench_command.add_command(start)
bench_command.add_command(restart)
bench_command.add_command(set_nginx_port)
@ -44,10 +45,11 @@ bench_command.add_command(backup_site)
bench_command.add_command(backup_all_sites)
bench_command.add_command(release)
bench_command.add_command(renew_lets_encrypt)
from bench.commands.setup import setup, disable_production
bench_command.add_command(setup)
bench_command.add_command(disable_production)
from bench.commands.setup import setup
bench_command.add_command(setup)
from bench.commands.config import config
bench_command.add_command(config)

View File

@ -93,12 +93,6 @@ def setup_config():
from bench.config.common_site_config import make_config
make_config('.')
@click.command('disable-production')
def disable_production():
"""Disable production environment for the bench"""
from bench.config.production_setup import disbable_production
disable_production('.')
setup.add_command(setup_sudoers)
setup.add_command(setup_nginx)
setup.add_command(setup_supervisor)

View File

@ -128,3 +128,12 @@ def release(app, bump_type, develop, master, owner, repo_name, remote):
from bench.release import release
release(bench_path='.', app=app, bump_type=bump_type, develop=develop, master=master,
remote=remote, owner=owner, repo_name=repo_name)
@click.command('disable-production')
def disable_production():
"""Disables production environment for the bench."""
from bench.config.production_setup import disable_production
disable_production(bench_path='.')
click.echo("Please run 'bench setup procfile'")
click.echo("Run 'bench start' to start development environment")

View File

@ -44,7 +44,7 @@ def disable_production(bench_path='.'):
exec_cmd('supervisorctl reload')
# nginx
nginx_conf = '/etc/nginx/conf.f/{bench_name}.conf'.format(bench_name=bench_name)
nginx_conf = '/etc/nginx/conf.d/{bench_name}.conf'.format(bench_name=bench_name)
if os.path.islink(nginx_conf):
os.unlink(nginx_conf)

View File

@ -1,6 +1,6 @@
from __future__ import unicode_literals
from bench.tests import test_init
from bench.config.production_setup import setup_production, get_supervisor_confdir
from bench.config.production_setup import setup_production, get_supervisor_confdir, disable_production
import bench.utils
import os
import getpass
@ -47,6 +47,21 @@ class TestSetupProduction(test_init.TestBenchInit):
self.assert_supervisor_config(bench_name, use_rq=False)
self.assert_supervisor_process(bench_name, use_rq=False)
def test_disable_production(self):
bench_name = 'test-disable-prod'
self.test_init(bench_name, frappe_branch='master')
user = getpass.getuser()
bench_path = os.path.join(os.path.abspath(self.benches_path), bench_name)
setup_production(user, bench_path)
disable_production(bench_path)
self.assert_nginx_link(bench_name)
self.assert_supervisor_link(bench_name)
self.assert_supervisor_process(bench_name=bench_name, disable_production=True)
def assert_nginx_config(self, bench_name):
conf_src = os.path.join(os.path.abspath(self.benches_path), bench_name, 'config', 'nginx.conf')
conf_dest = "/etc/nginx/conf.d/{bench_name}.conf".format(bench_name=bench_name)
@ -128,7 +143,7 @@ class TestSetupProduction(test_init.TestBenchInit):
for key in tests:
self.assertTrue(key.format(bench_name=bench_name) in f)
def assert_supervisor_process(self, bench_name, use_rq=True):
def assert_supervisor_process(self, bench_name, use_rq=True, disable_production=False):
out = bench.utils.get_cmd_output("sudo supervisorctl status")
if "STARTING" in out:
@ -160,7 +175,20 @@ class TestSetupProduction(test_init.TestBenchInit):
])
for key in tests:
self.assertTrue(re.search(key.format(bench_name=bench_name), out))
if disable_production:
self.assertFalse(re.search(key.format(bench_name=bench_name), out))
else:
self.assertTrue(re.search(key.format(bench_name=bench_name), out))
def assert_nginx_link(self, bench_name):
nginx_conf_name = '{bench_name}.conf'.format(bench_name=bench_name)
nginx_conf_path = os.path.join('/etc/nginx/conf.d', nginx_conf_name)
self.assertFalse(os.path.islink(nginx_conf_path))
def assert_supervisor_link(self, bench_name):
supervisor_conf_dir = get_supervisor_confdir()
supervisor_conf_name = '{bench_name}.conf'.format(bench_name=bench_name)
supervisor_conf_path = os.path.join(supervisor_conf_dir, supervisor_conf_name)
self.assertFalse(os.path.islink(supervisor_conf_path))