Skip to content

Commit

Permalink
EXAMPLES : Add bad unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
crdoconnor committed Dec 10, 2023
1 parent c9a6fba commit e0b8303
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
28 changes: 18 additions & 10 deletions examples/website/app/todoApp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from pathlib import Path
import sys
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -74,17 +75,24 @@

# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": os.environ["SQL_ENGINE"],
"NAME": os.environ["SQL_DATABASE"],
"USER": os.environ["SQL_USER"],
"PASSWORD": os.environ["SQL_PASSWORD"],
"HOST": os.environ["SQL_HOST"],
"PORT": os.environ["SQL_PORT"],
if 'test' in sys.argv: # For unit tests
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "mydatabase"
}
}
else:
DATABASES = {
"default": {
"ENGINE": os.environ["SQL_ENGINE"],
"NAME": os.environ["SQL_DATABASE"],
"USER": os.environ["SQL_USER"],
"PASSWORD": os.environ["SQL_PASSWORD"],
"HOST": os.environ["SQL_HOST"],
"PORT": os.environ["SQL_PORT"],
}
}
}


# Password validation
Expand Down
16 changes: 15 additions & 1 deletion examples/website/app/todos/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
from django.test import TestCase
from unittest.mock import MagicMock, patch
from django.contrib.auth.models import User
from django.test.client import RequestFactory
from django.shortcuts import get_object_or_404
from todos.views import delete

# Create your tests here.

class DeleteTodo(TestCase):
@patch('todos.views.get_object_or_404')
def test_delete(self, get_object_or_404):
user = User.objects.create_user(
username="u", email="e", password="pwd"
)
request = RequestFactory().get("/delete/")
request.user = user
delete(request, 1)

0 comments on commit e0b8303

Please sign in to comment.