def main(domain, django_version, python_version, nuke): if domain == 'your-username.pythonanywhere.com': username = getpass.getuser().lower() pa_domain = os.environ.get('PYTHONANYWHERE_DOMAIN', 'pythonanywhere.com') domain = '{username}.{pa_domain}'.format(username=username, pa_domain=pa_domain) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.create_virtualenv(django_version, nuke=nuke) project.run_startproject(nuke=nuke) project.find_django_files() project.update_settings_file() project.run_collectstatic() project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.update_wsgi_file() project.webapp.reload() print( snakesay('All done! Your site is now live at https://{domain}'.format( domain=domain)))
def test_calls_startproject(self, mock_subprocess, fake_home): project = DjangoProject("mydomain.com", "python.version") project.run_startproject(nuke=False) assert mock_subprocess.check_call.call_args == call([ str(Path(project.virtualenv.path / "bin/django-admin.py")), "startproject", "mysite", str(fake_home / "mydomain.com"), ])
def test_calls_startproject(self, mock_subprocess, fake_home): project = DjangoProject('mydomain.com', 'python.version') project.run_startproject(nuke=False) assert mock_subprocess.check_call.call_args == call([ str(Path(project.virtualenv.path / 'bin/django-admin.py')), 'startproject', 'mysite', str(fake_home / 'mydomain.com'), ])
def test_nuke_option_deletes_directory_first(self, mock_subprocess, fake_home): project = DjangoProject('mydomain.com', 'python.version') (fake_home / project.domain).mkdir() old_file = fake_home / project.domain / 'old_file.py' old_file.write_text('old stuff') project.run_startproject(nuke=True) assert not old_file.exists()
def test_nuke_option_deletes_directory_first(self, mock_subprocess, fake_home, virtualenvs_folder): project = DjangoProject("mydomain.com", "python.version") (fake_home / project.domain).mkdir() old_file = fake_home / project.domain / "old_file.py" old_file.write_text("old stuff") project.run_startproject(nuke=True) assert not old_file.exists()
def main(domain, django_version, python_version, nuke): domain = ensure_domain(domain) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.create_virtualenv(django_version, nuke=nuke) project.run_startproject(nuke=nuke) project.find_django_files() project.update_settings_file() project.run_collectstatic() project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.update_wsgi_file() project.webapp.reload() print(snakesay('All done! Your site is now live at https://{domain}'.format(domain=domain)))
def start( domain_name: str = typer.Option( "your-username.pythonanywhere.com", "-d", "--domain", help="Domain name, eg www.mydomain.com", ), django_version: str = typer.Option( "latest", "-j", "--django-version", help="Django version, eg '3.1.2'", ), python_version: str = typer.Option( "3.6", "-p", "--python-version", help="Python version, eg '3.8'", ), nuke: bool = typer.Option( False, help= "*Irrevocably* delete any existing web app config on this domain. Irrevocably.", ), ): """ Create a new Django webapp with a virtualenv. Defaults to your free domain, the latest version of Django and Python 3.6 """ domain = ensure_domain(domain_name) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.create_virtualenv(django_version, nuke=nuke) project.run_startproject(nuke=nuke) project.find_django_files() project.update_settings_file() project.run_collectstatic() project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.update_wsgi_file() project.webapp.reload() typer.echo( snakesay(f"All done! Your site is now live at https://{domain}"))
def test_nuke_option_handles_directory_not_existing( self, mock_subprocess, fake_home): project = DjangoProject('mydomain.com', 'python.version') project.run_startproject(nuke=True) # should not raise
def test_creates_folder(self, mock_subprocess, fake_home): project = DjangoProject('mydomain.com', 'python.version') project.run_startproject(nuke=False) assert (fake_home / 'mydomain.com').is_dir()
def test_nuke_option_handles_directory_not_existing( self, mock_subprocess, fake_home, virtualenvs_folder): project = DjangoProject("mydomain.com", "python.version") project.run_startproject(nuke=True) # should not raise
def test_creates_folder(self, mock_subprocess, fake_home, virtualenvs_folder): project = DjangoProject("mydomain.com", "python.version") project.run_startproject(nuke=False) assert (fake_home / "mydomain.com").is_dir()