Пример #1
0
    def test_raises_if_empty_project_folder(self, fake_home,
                                            virtualenvs_folder):
        project = DjangoProject("mydomain.com", "python.version")
        with pytest.raises(SanityException) as e:
            project.find_django_files()

        assert "Could not find your settings.py" in str(e.value)
Пример #2
0
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)))
Пример #3
0
    def test_raises_if_no_settings_in_any_subfolders(self, fake_home):
        project = DjangoProject('mydomain.com', 'python.version')
        not_this_folder = project.project_path / 'not_this_folder'
        not_this_folder.mkdir(parents=True)
        with pytest.raises(SanityException) as e:
            project.find_django_files()

        assert 'Could not find your settings.py' in str(e.value)
Пример #4
0
    def test_raises_if_no_settings_in_any_subfolders(self, fake_home,
                                                     virtualenvs_folder):
        project = DjangoProject("mydomain.com", "python.version")
        not_this_folder = project.project_path / "not_this_folder"
        not_this_folder.mkdir(parents=True)
        with pytest.raises(SanityException) as e:
            project.find_django_files()

        assert "Could not find your settings.py" in str(e.value)
Пример #5
0
    def test_raises_if_manage_py_not_found(self, fake_home,
                                           non_nested_submodule):
        project = DjangoProject('mydomain.com', 'python.version')
        shutil.copytree(str(non_nested_submodule), str(project.project_path))
        expected_manage_py = project.project_path / 'manage.py'
        assert expected_manage_py.exists()
        expected_manage_py.unlink()
        with pytest.raises(SanityException) as e:
            project.find_django_files()

        assert 'Could not find your manage.py' in str(e.value)
Пример #6
0
    def test_nested(self, fake_home, more_nested_submodule):
        project = DjangoProject('mydomain.com', 'python.version')
        shutil.copytree(str(more_nested_submodule), str(project.project_path))
        expected_settings_path = project.project_path / 'mysite/mysite/settings.py'
        assert expected_settings_path.exists()
        expected_manage_py = project.project_path / 'mysite/manage.py'
        assert expected_manage_py.exists()

        project.find_django_files()

        assert project.settings_path == expected_settings_path
        assert project.manage_py_path == expected_manage_py
Пример #7
0
    def test_raises_if_manage_py_not_found(self, fake_home,
                                           non_nested_submodule,
                                           virtualenvs_folder):
        project = DjangoProject("mydomain.com", "python.version")
        shutil.copytree(str(non_nested_submodule), str(project.project_path))
        expected_manage_py = project.project_path / "manage.py"
        assert expected_manage_py.exists()
        expected_manage_py.unlink()
        with pytest.raises(SanityException) as e:
            project.find_django_files()

        assert "Could not find your manage.py" in str(e.value)
    def test_non_nested(self, fake_home, non_nested_submodule):
        project = DjangoProject("mydomain.com", "python.version")
        shutil.copytree(str(non_nested_submodule), str(project.project_path))
        expected_settings_path = project.project_path / "myproject/settings.py"
        assert expected_settings_path.exists()
        expected_manage_py = project.project_path / "manage.py"
        assert expected_manage_py.exists()

        project.find_django_files()

        assert project.settings_path == expected_settings_path
        assert project.manage_py_path == expected_manage_py
Пример #9
0
    def test_actually_produces_wsgi_file_that_can_import_nested_project(
            self, fake_home, more_nested_submodule, virtualenvs_folder):
        project = DjangoProject('mydomain.com', '3.6')
        shutil.copytree(str(more_nested_submodule), str(project.project_path))
        project.create_virtualenv()
        project.find_django_files()
        project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name)

        project.update_wsgi_file()

        print(project.wsgi_file_path.open().read())
        subprocess.check_output([
            str(project.virtualenv.path / 'bin/python'),
            str(project.wsgi_file_path)
        ])
Пример #10
0
def autoconfigure(
    repo_url: str = typer.Argument(
        ..., help="url of remote git repository of your django project"),
    domain_name: str = typer.Option(
        "your-username.pythonanywhere.com",
        "-d",
        "--domain",
        help="Domain name, eg www.mydomain.com",
    ),
    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.",
    ),
):
    """
    Autoconfigure a Django project from on a github URL.

    \b
    - downloads the repo
    - creates a virtualenv and installs django (or detects a requirements.txt if available)
    - creates webapp via api
    - creates django wsgi configuration file
    - adds static files config
    """
    domain = ensure_domain(domain_name)
    project = DjangoProject(domain, python_version)
    project.sanity_checks(nuke=nuke)
    project.download_repo(repo_url, nuke=nuke),
    project.create_virtualenv(nuke=nuke)
    project.create_webapp(nuke=nuke)
    project.add_static_file_mappings()
    project.find_django_files()
    project.update_wsgi_file()
    project.update_settings_file()
    project.run_collectstatic()
    project.run_migrate()
    project.webapp.reload()
    typer.echo(
        snakesay(
            f"All done!  Your site is now live at https://{domain_name}\n"))
    project.start_bash()
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)))
Пример #12
0
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 main(repo_url, domain, python_version, nuke):
    domain = ensure_domain(domain)
    project = DjangoProject(domain, python_version)
    project.sanity_checks(nuke=nuke)
    project.download_repo(repo_url, nuke=nuke),
    project.create_virtualenv(nuke=nuke)
    project.create_webapp(nuke=nuke)
    project.add_static_file_mappings()
    project.find_django_files()
    project.update_wsgi_file()
    project.update_settings_file()
    project.run_collectstatic()
    project.run_migrate()
    project.webapp.reload()
    print(snakesay(f'All done!  Your site is now live at https://{domain}'))
    print()
    project.start_bash()
Пример #14
0
    def test_actually_produces_wsgi_file_that_can_import_nested_project(
            self, fake_home, more_nested_submodule, virtualenvs_folder):
        running_python_version = ".".join(python_version().split(".")[:2])
        project = DjangoProject("mydomain.com", running_python_version)
        shutil.copytree(str(more_nested_submodule), str(project.project_path))
        if running_python_version in ["3.7", "3.8"]:
            project.create_virtualenv(django_version="latest")
        else:
            project.create_virtualenv()
        project.find_django_files()
        project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name)

        project.update_wsgi_file()

        print(project.wsgi_file_path.open().read())
        subprocess.check_output([
            str(project.virtualenv.path / "bin/python"),
            str(project.wsgi_file_path)
        ])
Пример #15
0
def main(repo_url, domain, python_version, nuke):
    if domain == 'your-username.pythonanywhere.com':
        username = getpass.getuser().lower()
        pa_domain = os.environ.get('PYTHONANYWHERE_DOMAIN', 'pythonanywhere.com')
        domain = f'{username}.{pa_domain}'

    project = DjangoProject(domain, python_version)
    project.sanity_checks(nuke=nuke)
    project.download_repo(repo_url, nuke=nuke),
    project.create_virtualenv(nuke=nuke)
    project.create_webapp(nuke=nuke)
    project.add_static_file_mappings()
    project.find_django_files()
    project.update_wsgi_file()
    project.update_settings_file()
    project.run_collectstatic()
    project.run_migrate()
    project.webapp.reload()
    print(snakesay(f'All done!  Your site is now live at https://{domain}'))
    print()
    project.start_bash()
Пример #16
0
    def test_raises_if_empty_project_folder(self, fake_home):
        project = DjangoProject('mydomain.com', 'python.version')
        with pytest.raises(SanityException) as e:
            project.find_django_files()

        assert 'Could not find your settings.py' in str(e.value)