From fd739aa199ed13774694bee2e694fa0bc9409fac Mon Sep 17 00:00:00 2001 From: shreyas Date: Wed, 29 Jun 2016 16:26:28 +0530 Subject: [PATCH] [Minor] Added test case in bench test suite --- bench/commands/__init__.py | 10 ++++---- bench/commands/setup.py | 6 ----- bench/commands/utils.py | 9 ++++++++ bench/config/production_setup.py | 2 +- bench/tests/test_setup_production.py | 34 +++++++++++++++++++++++++--- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 4326ba42..64526956 100644 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -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) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 9e547c7a..12406040 100644 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -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) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index c9517851..f70542e2 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -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") diff --git a/bench/config/production_setup.py b/bench/config/production_setup.py index c77608bb..b9067454 100755 --- a/bench/config/production_setup.py +++ b/bench/config/production_setup.py @@ -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) diff --git a/bench/tests/test_setup_production.py b/bench/tests/test_setup_production.py index afe1a85b..7320b254 100644 --- a/bench/tests/test_setup_production.py +++ b/bench/tests/test_setup_production.py @@ -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))