forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Django Test Compatibility (microsoft#23935)
implements and thus closes microsoft#22206 resolves microsoft#73!
- Loading branch information
1 parent
b872cb4
commit 59a8d03
Showing
26 changed files
with
702 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
23 changes: 23 additions & 0 deletions
23
python_files/tests/unittestadapter/.data/simple_django/manage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
2 changes: 2 additions & 0 deletions
2
python_files/tests/unittestadapter/.data/simple_django/mysite/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
9 changes: 9 additions & 0 deletions
9
python_files/tests/unittestadapter/.data/simple_django/mysite/asgi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') | ||
|
||
application = get_asgi_application() |
102 changes: 102 additions & 0 deletions
102
python_files/tests/unittestadapter/.data/simple_django/mysite/settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
""" | ||
Django settings for mysite project. | ||
Generated by 'django-admin startproject' using Django 3.2.22. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.2/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/3.2/ref/settings/ | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
"polls.apps.PollsConfig", | ||
"django.contrib.admin", | ||
"django.contrib.auth", | ||
"django.contrib.contenttypes", | ||
"django.contrib.sessions", | ||
"django.contrib.messages", | ||
"django.contrib.staticfiles", | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'mysite.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'mysite.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': BASE_DIR / 'db.sqlite3', | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/3.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/3.2/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
# Default primary key field type | ||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
9 changes: 9 additions & 0 deletions
9
python_files/tests/unittestadapter/.data/simple_django/mysite/urls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
|
||
urlpatterns = [ | ||
path("polls/", include("polls.urls")), | ||
path("admin/", admin.site.urls), | ||
] |
7 changes: 7 additions & 0 deletions
7
python_files/tests/unittestadapter/.data/simple_django/mysite/wsgi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
application = get_wsgi_application() |
2 changes: 2 additions & 0 deletions
2
python_files/tests/unittestadapter/.data/simple_django/polls/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
2 changes: 2 additions & 0 deletions
2
python_files/tests/unittestadapter/.data/simple_django/polls/admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
13 changes: 13 additions & 0 deletions
13
python_files/tests/unittestadapter/.data/simple_django/polls/apps.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
from django.apps import AppConfig | ||
from django.utils.functional import cached_property | ||
|
||
|
||
class PollsConfig(AppConfig): | ||
@cached_property | ||
def default_auto_field(self): | ||
return "django.db.models.BigAutoField" | ||
|
||
name = "polls" |
52 changes: 52 additions & 0 deletions
52
python_files/tests/unittestadapter/.data/simple_django/polls/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 5.0.8 on 2024-08-09 20:04 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Question", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("question_text", models.CharField(max_length=200, default="")), | ||
("pub_date", models.DateTimeField(verbose_name="date published", auto_now_add=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="Choice", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("choice_text", models.CharField(max_length=200)), | ||
("votes", models.IntegerField(default=0)), | ||
( | ||
"question", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="polls.question" | ||
), | ||
), | ||
], | ||
), | ||
] |
2 changes: 2 additions & 0 deletions
2
python_files/tests/unittestadapter/.data/simple_django/polls/migrations/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
25 changes: 25 additions & 0 deletions
25
python_files/tests/unittestadapter/.data/simple_django/polls/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
from django.db import models | ||
from django.utils import timezone | ||
import datetime | ||
|
||
|
||
class Question(models.Model): | ||
question_text = models.CharField(max_length=200) | ||
pub_date = models.DateTimeField("date published") | ||
def __str__(self): | ||
return self.question_text | ||
def was_published_recently(self): | ||
if self.pub_date > timezone.now(): | ||
return False | ||
return self.pub_date >= timezone.now() - datetime.timedelta(days=1) | ||
|
||
|
||
class Choice(models.Model): | ||
question = models.ForeignKey(Question, on_delete=models.CASCADE) | ||
choice_text = models.CharField(max_length=200) | ||
votes = models.IntegerField() | ||
def __str__(self): | ||
return self.choice_text |
38 changes: 38 additions & 0 deletions
38
python_files/tests/unittestadapter/.data/simple_django/polls/tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
from django.utils import timezone | ||
from django.test import TestCase | ||
from .models import Question | ||
import datetime | ||
|
||
class QuestionModelTests(TestCase): | ||
def test_was_published_recently_with_future_question(self): | ||
""" | ||
was_published_recently() returns False for questions whose pub_date | ||
is in the future. | ||
""" | ||
time = timezone.now() + datetime.timedelta(days=30) | ||
future_question: Question = Question.objects.create(pub_date=time) | ||
self.assertIs(future_question.was_published_recently(), False) | ||
|
||
def test_was_published_recently_with_future_question_2(self): | ||
""" | ||
was_published_recently() returns False for questions whose pub_date | ||
is in the future. | ||
""" | ||
time = timezone.now() + datetime.timedelta(days=30) | ||
future_question = Question.objects.create(pub_date=time) | ||
self.assertIs(future_question.was_published_recently(), True) | ||
|
||
def test_question_creation_and_retrieval(self): | ||
""" | ||
Test that a Question can be created and retrieved from the database. | ||
""" | ||
time = timezone.now() | ||
question = Question.objects.create(pub_date=time, question_text="What's new?") | ||
retrieved_question = Question.objects.get(question_text=question.question_text) | ||
self.assertEqual(question, retrieved_question) | ||
self.assertEqual(retrieved_question.question_text, "What's new?") | ||
self.assertEqual(retrieved_question.pub_date, time) | ||
|
11 changes: 11 additions & 0 deletions
11
python_files/tests/unittestadapter/.data/simple_django/polls/urls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
# ex: /polls/ | ||
path("", views.index, name="index"), | ||
] |
7 changes: 7 additions & 0 deletions
7
python_files/tests/unittestadapter/.data/simple_django/polls/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
from django.http import HttpResponse | ||
from .models import Question # noqa: F401 | ||
|
||
def index(request): | ||
return HttpResponse("Hello, world. You're at the polls index.") |
Oops, something went wrong.