From 927cc8d33b353aa7984c1b4d9fe6c116c69d618d Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Fri, 12 Jun 2020 18:58:58 -0700 Subject: [PATCH 1/4] Added tests for Django samples --- .../django_cloudsql/mysite/settings.py | 9 ++++ .../flexible/django_cloudsql/polls/tests.py | 21 +++------ appengine/flexible/django_cloudsql/pytest.ini | 3 ++ .../django_cloudsql/requirements-test.txt | 1 + appengine/standard/django/mysite/settings.py | 9 ++++ appengine/standard/django/polls/tests.py | 24 +++------- appengine/standard/django/pytest.ini | 3 ++ .../standard/django/requirements-test.txt | 1 + .../django/mysite/settings.py | 8 ++++ .../standard_python3/django/polls/tests.py | 45 ++++++++++++++++++- appengine/standard_python3/django/pytest.ini | 3 ++ .../django/requirements-test.txt | 1 + .../django/mysite/settings.py | 8 ++++ .../standard_python37/django/polls/tests.py | 45 ++++++++++++++++++- appengine/standard_python37/django/pytest.ini | 3 ++ .../django/requirements-test.txt | 1 + 16 files changed, 149 insertions(+), 36 deletions(-) create mode 100644 appengine/flexible/django_cloudsql/pytest.ini create mode 100644 appengine/standard/django/pytest.ini create mode 100644 appengine/standard_python3/django/pytest.ini create mode 100644 appengine/standard_python37/django/pytest.ini diff --git a/appengine/flexible/django_cloudsql/mysite/settings.py b/appengine/flexible/django_cloudsql/mysite/settings.py index 7bded4a47c3..89fc4567fea 100644 --- a/appengine/flexible/django_cloudsql/mysite/settings.py +++ b/appengine/flexible/django_cloudsql/mysite/settings.py @@ -116,6 +116,15 @@ DATABASES['default']['HOST'] = '127.0.0.1' # [END dbconfig] +# Use a in-memort sqlite3 database when testing in Kokoro +if os.getenv('TRAMPOLINE_IMAGE', None): + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') + } + } + # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ diff --git a/appengine/flexible/django_cloudsql/polls/tests.py b/appengine/flexible/django_cloudsql/polls/tests.py index 052a900bd6f..4d0499ba7de 100644 --- a/appengine/flexible/django_cloudsql/polls/tests.py +++ b/appengine/flexible/django_cloudsql/polls/tests.py @@ -1,15 +1,8 @@ -# Copyright 2015 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +from django.test import Client, TestCase # noqa: 401 -# Create your tests here. + +class PollViewTests(TestCase): + def test_index_view(self): + response = self.client.get('/') + assert response.status_code == 200 + assert 'Hello, world' in str(response.content) diff --git a/appengine/flexible/django_cloudsql/pytest.ini b/appengine/flexible/django_cloudsql/pytest.ini new file mode 100644 index 00000000000..2e745302cd9 --- /dev/null +++ b/appengine/flexible/django_cloudsql/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE = mysite.settings +python_files = tests.py \ No newline at end of file diff --git a/appengine/flexible/django_cloudsql/requirements-test.txt b/appengine/flexible/django_cloudsql/requirements-test.txt index 781d4326c94..622cd175afe 100644 --- a/appengine/flexible/django_cloudsql/requirements-test.txt +++ b/appengine/flexible/django_cloudsql/requirements-test.txt @@ -1 +1,2 @@ pytest==5.3.2 +pytest-django==3.9.0 diff --git a/appengine/standard/django/mysite/settings.py b/appengine/standard/django/mysite/settings.py index 58149c6cabf..fb63d504ffa 100644 --- a/appengine/standard/django/mysite/settings.py +++ b/appengine/standard/django/mysite/settings.py @@ -134,6 +134,15 @@ } # [END db_setup] +# Use a in-memort sqlite3 database when testing in Kokoro +if os.getenv('TRAMPOLINE_IMAGE', None): + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') + } + } + # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ diff --git a/appengine/standard/django/polls/tests.py b/appengine/standard/django/polls/tests.py index c3b029bad97..4d0499ba7de 100644 --- a/appengine/standard/django/polls/tests.py +++ b/appengine/standard/django/polls/tests.py @@ -1,20 +1,8 @@ -# Copyright 2015 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +from django.test import Client, TestCase # noqa: 401 -# Uncomment these imports and add tests here -# from django import http -# from django.test import TestCase - -# from . import views +class PollViewTests(TestCase): + def test_index_view(self): + response = self.client.get('/') + assert response.status_code == 200 + assert 'Hello, world' in str(response.content) diff --git a/appengine/standard/django/pytest.ini b/appengine/standard/django/pytest.ini new file mode 100644 index 00000000000..2e745302cd9 --- /dev/null +++ b/appengine/standard/django/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE = mysite.settings +python_files = tests.py \ No newline at end of file diff --git a/appengine/standard/django/requirements-test.txt b/appengine/standard/django/requirements-test.txt index 42999750563..f0d229cb671 100644 --- a/appengine/standard/django/requirements-test.txt +++ b/appengine/standard/django/requirements-test.txt @@ -1 +1,2 @@ pytest==4.6.9 +pytest-django==3.9.0 diff --git a/appengine/standard_python3/django/mysite/settings.py b/appengine/standard_python3/django/mysite/settings.py index 3ff8446771f..06e972089d7 100644 --- a/appengine/standard_python3/django/mysite/settings.py +++ b/appengine/standard_python3/django/mysite/settings.py @@ -118,6 +118,14 @@ } # [END db_setup] +# Use a in-memort sqlite3 database when testing in Kokoro +if os.getenv('TRAMPOLINE_IMAGE', None): + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') + } + } # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators diff --git a/appengine/standard_python3/django/polls/tests.py b/appengine/standard_python3/django/polls/tests.py index 1848508267c..4302e1beee2 100644 --- a/appengine/standard_python3/django/polls/tests.py +++ b/appengine/standard_python3/django/polls/tests.py @@ -1,3 +1,44 @@ -from django.test import TestCase # noqa: 401 +from django.test import Client, TestCase # noqa: 401 +from django.urls import reverse +from django.utils import timezone -# Create your tests here. +from .models import Choice, Question + + +class PollViewTests(TestCase): + def setUp(self): + question = Question( + question_text="This is a test question", + pub_date=timezone.now() + ) + question.save() + self.question = question + + choice = Choice( + choice_text="This is a test choice", + votes=0 + ) + choice.question = question + choice.save() + self.choice = choice + + self.client = Client() + + def test_index_view(self): + response = self.client.get('/') + assert response.status_code == 200 + assert self.question.question_text in str(response.content) + + def test_detail_view(self): + response = self.client.get( + reverse('polls:detail', args=(self.question.id,))) + assert response.status_code == 200 + assert self.question.question_text in str(response.content) + assert self.choice.choice_text in str(response.content) + + def test_results_view(self): + response = self.client.get( + reverse('polls:results', args=(self.question.id,))) + assert response.status_code == 200 + assert self.question.question_text in str(response.content) + assert self.choice.choice_text in str(response.content) diff --git a/appengine/standard_python3/django/pytest.ini b/appengine/standard_python3/django/pytest.ini new file mode 100644 index 00000000000..2e745302cd9 --- /dev/null +++ b/appengine/standard_python3/django/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE = mysite.settings +python_files = tests.py \ No newline at end of file diff --git a/appengine/standard_python3/django/requirements-test.txt b/appengine/standard_python3/django/requirements-test.txt index 781d4326c94..622cd175afe 100644 --- a/appengine/standard_python3/django/requirements-test.txt +++ b/appengine/standard_python3/django/requirements-test.txt @@ -1 +1,2 @@ pytest==5.3.2 +pytest-django==3.9.0 diff --git a/appengine/standard_python37/django/mysite/settings.py b/appengine/standard_python37/django/mysite/settings.py index 3ff8446771f..06e972089d7 100644 --- a/appengine/standard_python37/django/mysite/settings.py +++ b/appengine/standard_python37/django/mysite/settings.py @@ -118,6 +118,14 @@ } # [END db_setup] +# Use a in-memort sqlite3 database when testing in Kokoro +if os.getenv('TRAMPOLINE_IMAGE', None): + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') + } + } # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators diff --git a/appengine/standard_python37/django/polls/tests.py b/appengine/standard_python37/django/polls/tests.py index 1848508267c..4302e1beee2 100644 --- a/appengine/standard_python37/django/polls/tests.py +++ b/appengine/standard_python37/django/polls/tests.py @@ -1,3 +1,44 @@ -from django.test import TestCase # noqa: 401 +from django.test import Client, TestCase # noqa: 401 +from django.urls import reverse +from django.utils import timezone -# Create your tests here. +from .models import Choice, Question + + +class PollViewTests(TestCase): + def setUp(self): + question = Question( + question_text="This is a test question", + pub_date=timezone.now() + ) + question.save() + self.question = question + + choice = Choice( + choice_text="This is a test choice", + votes=0 + ) + choice.question = question + choice.save() + self.choice = choice + + self.client = Client() + + def test_index_view(self): + response = self.client.get('/') + assert response.status_code == 200 + assert self.question.question_text in str(response.content) + + def test_detail_view(self): + response = self.client.get( + reverse('polls:detail', args=(self.question.id,))) + assert response.status_code == 200 + assert self.question.question_text in str(response.content) + assert self.choice.choice_text in str(response.content) + + def test_results_view(self): + response = self.client.get( + reverse('polls:results', args=(self.question.id,))) + assert response.status_code == 200 + assert self.question.question_text in str(response.content) + assert self.choice.choice_text in str(response.content) diff --git a/appengine/standard_python37/django/pytest.ini b/appengine/standard_python37/django/pytest.ini new file mode 100644 index 00000000000..2e745302cd9 --- /dev/null +++ b/appengine/standard_python37/django/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE = mysite.settings +python_files = tests.py \ No newline at end of file diff --git a/appengine/standard_python37/django/requirements-test.txt b/appengine/standard_python37/django/requirements-test.txt index 781d4326c94..622cd175afe 100644 --- a/appengine/standard_python37/django/requirements-test.txt +++ b/appengine/standard_python37/django/requirements-test.txt @@ -1 +1,2 @@ pytest==5.3.2 +pytest-django==3.9.0 From 2f6f1d99a31ea2a2bd7428db3832cdcce5651ecb Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Fri, 12 Jun 2020 19:11:16 -0700 Subject: [PATCH 2/4] Use a different env var --- appengine/flexible/django_cloudsql/mysite/settings.py | 2 +- appengine/standard/django/mysite/settings.py | 2 +- appengine/standard_python3/django/mysite/settings.py | 2 +- appengine/standard_python37/django/mysite/settings.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appengine/flexible/django_cloudsql/mysite/settings.py b/appengine/flexible/django_cloudsql/mysite/settings.py index 89fc4567fea..8195326ef22 100644 --- a/appengine/flexible/django_cloudsql/mysite/settings.py +++ b/appengine/flexible/django_cloudsql/mysite/settings.py @@ -117,7 +117,7 @@ # [END dbconfig] # Use a in-memort sqlite3 database when testing in Kokoro -if os.getenv('TRAMPOLINE_IMAGE', None): +if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', diff --git a/appengine/standard/django/mysite/settings.py b/appengine/standard/django/mysite/settings.py index fb63d504ffa..353d061addc 100644 --- a/appengine/standard/django/mysite/settings.py +++ b/appengine/standard/django/mysite/settings.py @@ -135,7 +135,7 @@ # [END db_setup] # Use a in-memort sqlite3 database when testing in Kokoro -if os.getenv('TRAMPOLINE_IMAGE', None): +if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', diff --git a/appengine/standard_python3/django/mysite/settings.py b/appengine/standard_python3/django/mysite/settings.py index 06e972089d7..a2da71f75e1 100644 --- a/appengine/standard_python3/django/mysite/settings.py +++ b/appengine/standard_python3/django/mysite/settings.py @@ -119,7 +119,7 @@ # [END db_setup] # Use a in-memort sqlite3 database when testing in Kokoro -if os.getenv('TRAMPOLINE_IMAGE', None): +if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', diff --git a/appengine/standard_python37/django/mysite/settings.py b/appengine/standard_python37/django/mysite/settings.py index 06e972089d7..a2da71f75e1 100644 --- a/appengine/standard_python37/django/mysite/settings.py +++ b/appengine/standard_python37/django/mysite/settings.py @@ -119,7 +119,7 @@ # [END db_setup] # Use a in-memort sqlite3 database when testing in Kokoro -if os.getenv('TRAMPOLINE_IMAGE', None): +if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', From db10e6f8f4bbf31066ccf6a016b25ac55479f3d3 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Mon, 15 Jun 2020 12:28:09 -0700 Subject: [PATCH 3/4] Minor fixes --- .../django_cloudsql/mysite/settings.py | 2 +- .../django_cloudsql/noxfile_config.py | 39 +++++++++++++++++++ .../django_cloudsql/polls/test_polls.py | 22 +++++++++++ .../flexible/django_cloudsql/polls/tests.py | 8 ---- appengine/flexible/django_cloudsql/pytest.ini | 3 -- appengine/standard/django/mysite/settings.py | 2 +- appengine/standard/django/noxfile_config.py | 36 +++++++++++++++++ appengine/standard/django/polls/test_polls.py | 22 +++++++++++ appengine/standard/django/polls/tests.py | 8 ---- appengine/standard/django/pytest.ini | 3 -- .../django/mysite/settings.py | 2 +- .../standard_python3/django/noxfile_config.py | 39 +++++++++++++++++++ .../django/polls/{tests.py => test_polls.py} | 14 +++++++ appengine/standard_python3/django/pytest.ini | 3 -- .../django/mysite/settings.py | 2 +- .../django/noxfile_config.py | 39 +++++++++++++++++++ .../django/polls/{tests.py => test_polls.py} | 14 +++++++ appengine/standard_python37/django/pytest.ini | 3 -- 18 files changed, 229 insertions(+), 32 deletions(-) create mode 100644 appengine/flexible/django_cloudsql/noxfile_config.py create mode 100644 appengine/flexible/django_cloudsql/polls/test_polls.py delete mode 100644 appengine/flexible/django_cloudsql/polls/tests.py delete mode 100644 appengine/flexible/django_cloudsql/pytest.ini create mode 100644 appengine/standard/django/noxfile_config.py create mode 100644 appengine/standard/django/polls/test_polls.py delete mode 100644 appengine/standard/django/polls/tests.py delete mode 100644 appengine/standard/django/pytest.ini create mode 100644 appengine/standard_python3/django/noxfile_config.py rename appengine/standard_python3/django/polls/{tests.py => test_polls.py} (70%) delete mode 100644 appengine/standard_python3/django/pytest.ini create mode 100644 appengine/standard_python37/django/noxfile_config.py rename appengine/standard_python37/django/polls/{tests.py => test_polls.py} (70%) delete mode 100644 appengine/standard_python37/django/pytest.ini diff --git a/appengine/flexible/django_cloudsql/mysite/settings.py b/appengine/flexible/django_cloudsql/mysite/settings.py index 8195326ef22..c124f3cc187 100644 --- a/appengine/flexible/django_cloudsql/mysite/settings.py +++ b/appengine/flexible/django_cloudsql/mysite/settings.py @@ -116,7 +116,7 @@ DATABASES['default']['HOST'] = '127.0.0.1' # [END dbconfig] -# Use a in-memort sqlite3 database when testing in Kokoro +# Use a in-memory sqlite3 database when testing in CI systems if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { diff --git a/appengine/flexible/django_cloudsql/noxfile_config.py b/appengine/flexible/django_cloudsql/noxfile_config.py new file mode 100644 index 00000000000..546da53ddec --- /dev/null +++ b/appengine/flexible/django_cloudsql/noxfile_config.py @@ -0,0 +1,39 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': { + 'DJANGO_SETTINGS_MODULE': 'mysite.settings' + }, +} diff --git a/appengine/flexible/django_cloudsql/polls/test_polls.py b/appengine/flexible/django_cloudsql/polls/test_polls.py new file mode 100644 index 00000000000..4588d730242 --- /dev/null +++ b/appengine/flexible/django_cloudsql/polls/test_polls.py @@ -0,0 +1,22 @@ +# Copyright 2020 Google LLC. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.test import Client, TestCase # noqa: 401 + + +class PollViewTests(TestCase): + def test_index_view(self): + response = self.client.get('/') + assert response.status_code == 200 + assert 'Hello, world' in str(response.content) diff --git a/appengine/flexible/django_cloudsql/polls/tests.py b/appengine/flexible/django_cloudsql/polls/tests.py deleted file mode 100644 index 4d0499ba7de..00000000000 --- a/appengine/flexible/django_cloudsql/polls/tests.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.test import Client, TestCase # noqa: 401 - - -class PollViewTests(TestCase): - def test_index_view(self): - response = self.client.get('/') - assert response.status_code == 200 - assert 'Hello, world' in str(response.content) diff --git a/appengine/flexible/django_cloudsql/pytest.ini b/appengine/flexible/django_cloudsql/pytest.ini deleted file mode 100644 index 2e745302cd9..00000000000 --- a/appengine/flexible/django_cloudsql/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -DJANGO_SETTINGS_MODULE = mysite.settings -python_files = tests.py \ No newline at end of file diff --git a/appengine/standard/django/mysite/settings.py b/appengine/standard/django/mysite/settings.py index 353d061addc..5a4dcbdfcab 100644 --- a/appengine/standard/django/mysite/settings.py +++ b/appengine/standard/django/mysite/settings.py @@ -134,7 +134,7 @@ } # [END db_setup] -# Use a in-memort sqlite3 database when testing in Kokoro +# Use a in-memory sqlite3 database when testing in CI systems if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { diff --git a/appengine/standard/django/noxfile_config.py b/appengine/standard/django/noxfile_config.py new file mode 100644 index 00000000000..8bac9f7e26f --- /dev/null +++ b/appengine/standard/django/noxfile_config.py @@ -0,0 +1,36 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': { + 'DJANGO_SETTINGS_MODULE': 'mysite.settings' + }, +} diff --git a/appengine/standard/django/polls/test_polls.py b/appengine/standard/django/polls/test_polls.py new file mode 100644 index 00000000000..4588d730242 --- /dev/null +++ b/appengine/standard/django/polls/test_polls.py @@ -0,0 +1,22 @@ +# Copyright 2020 Google LLC. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.test import Client, TestCase # noqa: 401 + + +class PollViewTests(TestCase): + def test_index_view(self): + response = self.client.get('/') + assert response.status_code == 200 + assert 'Hello, world' in str(response.content) diff --git a/appengine/standard/django/polls/tests.py b/appengine/standard/django/polls/tests.py deleted file mode 100644 index 4d0499ba7de..00000000000 --- a/appengine/standard/django/polls/tests.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.test import Client, TestCase # noqa: 401 - - -class PollViewTests(TestCase): - def test_index_view(self): - response = self.client.get('/') - assert response.status_code == 200 - assert 'Hello, world' in str(response.content) diff --git a/appengine/standard/django/pytest.ini b/appengine/standard/django/pytest.ini deleted file mode 100644 index 2e745302cd9..00000000000 --- a/appengine/standard/django/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -DJANGO_SETTINGS_MODULE = mysite.settings -python_files = tests.py \ No newline at end of file diff --git a/appengine/standard_python3/django/mysite/settings.py b/appengine/standard_python3/django/mysite/settings.py index a2da71f75e1..f7ac261da88 100644 --- a/appengine/standard_python3/django/mysite/settings.py +++ b/appengine/standard_python3/django/mysite/settings.py @@ -118,7 +118,7 @@ } # [END db_setup] -# Use a in-memort sqlite3 database when testing in Kokoro +# Use a in-memory sqlite3 database when testing in CI systems if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { diff --git a/appengine/standard_python3/django/noxfile_config.py b/appengine/standard_python3/django/noxfile_config.py new file mode 100644 index 00000000000..546da53ddec --- /dev/null +++ b/appengine/standard_python3/django/noxfile_config.py @@ -0,0 +1,39 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': { + 'DJANGO_SETTINGS_MODULE': 'mysite.settings' + }, +} diff --git a/appengine/standard_python3/django/polls/tests.py b/appengine/standard_python3/django/polls/test_polls.py similarity index 70% rename from appengine/standard_python3/django/polls/tests.py rename to appengine/standard_python3/django/polls/test_polls.py index 4302e1beee2..2ef9121899e 100644 --- a/appengine/standard_python3/django/polls/tests.py +++ b/appengine/standard_python3/django/polls/test_polls.py @@ -1,3 +1,17 @@ +# Copyright 2020 Google LLC. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from django.test import Client, TestCase # noqa: 401 from django.urls import reverse from django.utils import timezone diff --git a/appengine/standard_python3/django/pytest.ini b/appengine/standard_python3/django/pytest.ini deleted file mode 100644 index 2e745302cd9..00000000000 --- a/appengine/standard_python3/django/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -DJANGO_SETTINGS_MODULE = mysite.settings -python_files = tests.py \ No newline at end of file diff --git a/appengine/standard_python37/django/mysite/settings.py b/appengine/standard_python37/django/mysite/settings.py index a2da71f75e1..f7ac261da88 100644 --- a/appengine/standard_python37/django/mysite/settings.py +++ b/appengine/standard_python37/django/mysite/settings.py @@ -118,7 +118,7 @@ } # [END db_setup] -# Use a in-memort sqlite3 database when testing in Kokoro +# Use a in-memory sqlite3 database when testing in CI systems if os.getenv('TRAMPOLINE_CI', None): DATABASES = { 'default': { diff --git a/appengine/standard_python37/django/noxfile_config.py b/appengine/standard_python37/django/noxfile_config.py new file mode 100644 index 00000000000..546da53ddec --- /dev/null +++ b/appengine/standard_python37/django/noxfile_config.py @@ -0,0 +1,39 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': { + 'DJANGO_SETTINGS_MODULE': 'mysite.settings' + }, +} diff --git a/appengine/standard_python37/django/polls/tests.py b/appengine/standard_python37/django/polls/test_polls.py similarity index 70% rename from appengine/standard_python37/django/polls/tests.py rename to appengine/standard_python37/django/polls/test_polls.py index 4302e1beee2..2ef9121899e 100644 --- a/appengine/standard_python37/django/polls/tests.py +++ b/appengine/standard_python37/django/polls/test_polls.py @@ -1,3 +1,17 @@ +# Copyright 2020 Google LLC. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from django.test import Client, TestCase # noqa: 401 from django.urls import reverse from django.utils import timezone diff --git a/appengine/standard_python37/django/pytest.ini b/appengine/standard_python37/django/pytest.ini deleted file mode 100644 index 2e745302cd9..00000000000 --- a/appengine/standard_python37/django/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -DJANGO_SETTINGS_MODULE = mysite.settings -python_files = tests.py \ No newline at end of file From bd1efd6c6366e456f388fe1f54d090763e6566c3 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Mon, 15 Jun 2020 12:47:42 -0700 Subject: [PATCH 4/4] Use pytest.ini instead for the App Engine standard (2.7) test --- appengine/standard/django/noxfile_config.py | 36 --------------------- appengine/standard/django/pytest.ini | 2 ++ 2 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 appengine/standard/django/noxfile_config.py create mode 100644 appengine/standard/django/pytest.ini diff --git a/appengine/standard/django/noxfile_config.py b/appengine/standard/django/noxfile_config.py deleted file mode 100644 index 8bac9f7e26f..00000000000 --- a/appengine/standard/django/noxfile_config.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Default TEST_CONFIG_OVERRIDE for python repos. - -# You can copy this file into your directory, then it will be inported from -# the noxfile.py. - -# The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py - -TEST_CONFIG_OVERRIDE = { - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - 'envs': { - 'DJANGO_SETTINGS_MODULE': 'mysite.settings' - }, -} diff --git a/appengine/standard/django/pytest.ini b/appengine/standard/django/pytest.ini new file mode 100644 index 00000000000..89b181d6952 --- /dev/null +++ b/appengine/standard/django/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +DJANGO_SETTINGS_MODULE=mysite.settings \ No newline at end of file