def test_calls_all_stuff_in_right_order(self):
     with patch('scripts.pa_autoconfigure_django.DjangoProject'
                ) as mock_DjangoProject:
         main('repo.url',
              'foo',
              'www.domain.com',
              'python.version',
              nuke='nuke option')
     assert mock_DjangoProject.call_args == call('www.domain.com',
                                                 'python.version')
     assert mock_DjangoProject.return_value.method_calls == [
         call.sanity_checks(nuke='nuke option'),
         call.download_repo('repo.url', nuke='nuke option'),
         call.ensure_branch("foo"),
         call.create_virtualenv(nuke='nuke option'),
         call.create_webapp(nuke='nuke option'),
         call.add_static_file_mappings(),
         call.find_django_files(),
         call.update_wsgi_file(),
         call.update_settings_file(),
         call.run_collectstatic(),
         call.run_migrate(),
         call.webapp.reload(),
         call.start_bash(),
     ]
Пример #2
0
 def test_lowercases_username(self):
     with patch('scripts.pa_autoconfigure_django.getpass') as mock_getpass:
         mock_getpass.getuser.return_value = 'UserName1'
         with patch('scripts.pa_autoconfigure_django.DjangoProject'
                    ) as mock_DjangoProject:
             main('a-url', 'your-username.pythonanywhere.com',
                  'python.version', 'nukey')
         assert mock_DjangoProject.call_args == call(
             'username1.pythonanywhere.com', 'python.version')
Пример #3
0
 def test_domain_defaults_to_using_current_username_and_domain_from_env(
         self, monkeypatch):
     username = getpass.getuser()
     monkeypatch.setenv('PYTHONANYWHERE_DOMAIN', 'pythonanywhere.domain')
     with patch('scripts.pa_autoconfigure_django.DjangoProject'
                ) as mock_DjangoProject:
         main('a-repo',
              'your-username.pythonanywhere.com',
              'python.version',
              nuke=False)
     assert mock_DjangoProject.call_args == call(
         username + '.pythonanywhere.domain', 'python.version')
    def test_actually_works_against_example_repo(self, fake_home,
                                                 virtualenvs_folder, api_token,
                                                 process_killer):
        running_python_version = ".".join(python_version().split(".")[:2])
        repo = 'https://github.com/pythonanywhere/example-django-project.git'
        domain = 'mydomain.com'
        with patch(
                'scripts.pa_autoconfigure_django.DjangoProject.update_wsgi_file'
        ):
            with patch(
                    'scripts.pa_autoconfigure_django.DjangoProject.start_bash'
            ):
                with patch('pythonanywhere.api.webapp.call_api'):
                    main(repo,
                         "None",
                         domain,
                         running_python_version,
                         nuke=False)

        expected_django_version = '3.0.6'
        expected_virtualenv = virtualenvs_folder / domain
        expected_project_path = fake_home / domain
        django_project_name = 'myproject'
        expected_settings_path = expected_project_path / django_project_name / 'settings.py'

        django_version = subprocess.check_output([
            str(expected_virtualenv / 'bin/python'), '-c'
            'import django; print(django.get_version())'
        ]).decode().strip()
        assert django_version == expected_django_version

        with expected_settings_path.open() as f:
            lines = f.read().split('\n')
        assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
        assert "ALLOWED_HOSTS = ['mydomain.com']  # type: List[str]" in lines

        assert 'base.css' in os.listdir(
            str(fake_home / domain / 'static/admin/css'))
        server = subprocess.Popen([
            str(expected_virtualenv / 'bin/python'),
            str(expected_project_path / 'manage.py'), 'runserver'
        ])
        process_killer.append(server)
        time.sleep(2)
        response = requests.get('http://localhost:8000/',
                                headers={'HOST': 'mydomain.com'})
        assert 'Hello from an example django project' in response.text