コード例 #1
0
    def test_updates_wsgi_file_from_template(self):
        project = DjangoProject('mydomain.com', 'python.version')
        project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name)
        project.settings_path = Path('/path/to/settingsfolder/settings.py')
        template = (Path(pythonanywhere.django_project.__file__).parent /
                    'wsgi_file_template.py').open().read()

        project.update_wsgi_file()

        with project.wsgi_file_path.open() as f:
            contents = f.read()
        print(contents)
        assert contents == template.format(project=project)
コード例 #2
0
    def test_adds_domain_to_ALLOWED_HOSTS(self):
        project = DjangoProject('mydomain.com', 'python.version')
        project.settings_path = Path(tempfile.NamedTemporaryFile().name)

        with project.settings_path.open('w') as f:
            f.write(
                dedent("""
                # settings file
                STATIC_URL = '/static/'
                ALLOWED_HOSTS = []
                """))

        project.update_settings_file()

        with project.settings_path.open() as f:
            lines = f.read().split('\n')

        assert "ALLOWED_HOSTS = ['mydomain.com']" in lines
コード例 #3
0
    def test_adds_domain_to_ALLOWED_HOSTS(self, virtualenvs_folder):
        project = DjangoProject("mydomain.com", "python.version")
        project.settings_path = Path(tempfile.NamedTemporaryFile().name)
        project.virtualenv.get_version = Mock(return_value="1.0")

        with project.settings_path.open("w") as f:
            f.write(
                dedent("""
                    # settings file
                    STATIC_URL = '/static/'
                    ALLOWED_HOSTS = []
                    """))

        project.update_settings_file()

        with project.settings_path.open() as f:
            lines = f.read().split("\n")

        assert "ALLOWED_HOSTS = ['mydomain.com']" in lines
コード例 #4
0
    def test_adds_STATIC_and_MEDIA_config_to_settings(self):
        project = DjangoProject('mydomain.com', 'python.version')
        project.settings_path = Path(tempfile.NamedTemporaryFile().name)

        with project.settings_path.open('w') as f:
            f.write(
                dedent("""
                # settings file
                STATIC_URL = '/static/'
                ALLOWED_HOSTS = []
                """))

        project.update_settings_file()

        with project.settings_path.open() as f:
            lines = f.read().split('\n')

        assert "STATIC_URL = '/static/'" in lines
        assert "MEDIA_URL = '/media/'" in lines
        assert "STATIC_ROOT = os.path.join(BASE_DIR, 'static')" in lines
        assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
コード例 #5
0
    def test_only_adds_MEDIA_ROOT_if_its_not_already_there(
            self, virtualenvs_folder):
        project = DjangoProject("mydomain.com", "python.version")
        project.settings_path = Path(tempfile.NamedTemporaryFile().name)
        project.virtualenv.get_version = Mock(return_value="1.0")

        with project.settings_path.open("w") as f:
            f.write(
                dedent("""
                    # settings file
                    STATIC_URL = '/static/'
                    ALLOWED_HOSTS = []
                    MEDIA_ROOT = media_root
                    """))

        project.update_settings_file()

        with project.settings_path.open() as f:
            lines = f.read().split("\n")

        assert "MEDIA_ROOT = media_root" in lines
        assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" not in lines
コード例 #6
0
    def test_adds_STATIC_and_MEDIA_config_to_settings_with_new_django(
            self, virtualenvs_folder):
        project = DjangoProject("mydomain.com", "python.version")
        project.settings_path = Path(tempfile.NamedTemporaryFile().name)
        project.virtualenv.get_version = Mock(return_value="3.1.1")

        with project.settings_path.open("w") as f:
            f.write(
                dedent("""
                    # settings file
                    STATIC_URL = '/static/'
                    ALLOWED_HOSTS = []
                    """))

        project.update_settings_file()

        with project.settings_path.open() as f:
            lines = f.read().split("\n")

        assert "STATIC_URL = '/static/'" in lines
        assert "MEDIA_URL = '/media/'" in lines
        assert "STATIC_ROOT = Path(BASE_DIR / 'static')" in lines
        assert "MEDIA_ROOT = Path(BASE_DIR / 'media')" in lines