def test_nuke_option_overrides_all_but_token_check(self, api_token, api_responses, fake_home, virtualenvs_folder): webapp = Webapp(self.domain) (fake_home / self.domain).mkdir() (virtualenvs_folder / self.domain).mkdir() webapp.sanity_checks(nuke=True) # should not raise
def test_raises_if_webapp_already_exists(self, api_token, api_responses): webapp = Webapp(self.domain) api_responses.add(responses.GET, self.expected_url, status=200, body=json.dumps({ "id": 1, "domain_name": self.domain })) with pytest.raises(SanityException) as e: webapp.sanity_checks(nuke=False) assert "You already have a webapp for " + self.domain in str(e.value) assert "nuke" in str(e.value)
class Project: def __init__(self, domain, python_version): self.domain = domain self.python_version = python_version self.project_path = Path( '~/{domain}'.format(domain=domain)).expanduser() self.virtualenv = Virtualenv(self.domain, self.python_version) self.wsgi_file_path = Path('/var/www/{mangled_domain}_wsgi.py'.format( mangled_domain=domain.replace(".", "_"))) self.webapp = Webapp(domain) def sanity_checks(self, nuke): self.webapp.sanity_checks(nuke=nuke) if nuke: return if self.virtualenv.path.exists(): raise SanityException( "You already have a virtualenv for {domain}.\n\n" "Use the --nuke option if you want to replace it.".format( domain=self.domain)) if self.project_path.exists(): raise SanityException( "You already have a project folder at {project_path}.\n\n" "Use the --nuke option if you want to replace it.".format( project_path=self.project_path)) def create_webapp(self, nuke): self.webapp.create(self.python_version, self.virtualenv.path, self.project_path, nuke=nuke) def add_static_file_mappings(self): self.webapp.add_default_static_files_mappings(self.project_path) def start_bash(self): print( snakesay( 'Starting Bash shell with activated virtualenv in project directory. Press Ctrl+D to exit.' )) unique_id = str(uuid.uuid4()) launch_bash_in_virtualenv(self.virtualenv.path, unique_id, self.project_path)
def test_raises_if_no_api_token_exists(self, api_responses, no_api_token): webapp = Webapp(self.domain) with pytest.raises(SanityException) as e: webapp.sanity_checks(nuke=False) assert "Could not find your API token" in str(e.value)
def test_does_not_complain_if_api_token_exists(self, api_token, api_responses): webapp = Webapp(self.domain) api_responses.add(responses.GET, self.expected_url, status=404) webapp.sanity_checks(nuke=False) # should not raise