From cf5658043a39c5a9962213317eafeb2639f0dd8f Mon Sep 17 00:00:00 2001 From: ShamaineChung Date: Fri, 16 Feb 2024 10:30:27 +0800 Subject: [PATCH] #1 updated db --- home/tests.py | 3 --- home/tests/test_views.py | 0 notes/migrations/0001_initial.py | 6 +++++- notes/migrations/0002_notes_user.py | 22 ---------------------- pytest.ini | 4 ++++ smartnotes/db_conn.py | 8 ++++++++ smartnotes/settings.py | 18 ++++++++++++------ 7 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 home/tests.py create mode 100644 home/tests/test_views.py delete mode 100644 notes/migrations/0002_notes_user.py create mode 100644 pytest.ini create mode 100644 smartnotes/db_conn.py diff --git a/home/tests.py b/home/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/home/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/home/tests/test_views.py b/home/tests/test_views.py new file mode 100644 index 00000000..e69de29b diff --git a/notes/migrations/0001_initial.py b/notes/migrations/0001_initial.py index 73c276ed..22db05ca 100644 --- a/notes/migrations/0001_initial.py +++ b/notes/migrations/0001_initial.py @@ -1,6 +1,8 @@ -# Generated by Django 3.2.2 on 2021-07-18 15:28 +# Generated by Django 4.0.10 on 2024-02-16 02:03 +from django.conf import settings from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -8,6 +10,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ @@ -18,6 +21,7 @@ class Migration(migrations.Migration): ('title', models.CharField(max_length=200)), ('text', models.TextField()), ('created', models.DateTimeField(auto_now_add=True)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes', to=settings.AUTH_USER_MODEL)), ], ), ] diff --git a/notes/migrations/0002_notes_user.py b/notes/migrations/0002_notes_user.py deleted file mode 100644 index b12cb206..00000000 --- a/notes/migrations/0002_notes_user.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 3.2.2 on 2021-07-28 21:40 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('notes', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='notes', - name='user', - field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='auth.user'), - preserve_default=False, - ), - ] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..09dcf2e2 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] + +DJANGO_SETTINGS_MODULE = smartnotes.settings +python_files = tests.py test_*.py \ No newline at end of file diff --git a/smartnotes/db_conn.py b/smartnotes/db_conn.py new file mode 100644 index 00000000..9c4a1182 --- /dev/null +++ b/smartnotes/db_conn.py @@ -0,0 +1,8 @@ +class dbconn: + engine = 'mssql' + name = 'myunittestdb' + user='' + password='' + port='' + host = 'MY-XUEERCHUNG\SQLEXPRESS' + driver = 'ODBC Driver 17 for SQL Server' \ No newline at end of file diff --git a/smartnotes/settings.py b/smartnotes/settings.py index 96500d29..6d801bf5 100644 --- a/smartnotes/settings.py +++ b/smartnotes/settings.py @@ -11,7 +11,7 @@ """ from pathlib import Path - +from .db_conn import dbconn # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -76,13 +76,19 @@ WSGI_APPLICATION = 'smartnotes.wsgi.application' -# Database -# https://docs.djangoproject.com/en/3.2/ref/settings/#databases +db = dbconn() DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + "default": { + "ENGINE": db.engine, + "NAME": db.name, + "USER": db.user, + "PASSWORD": db.password, + "HOST": db.host, + "PORT": db.port, + "OPTIONS": { + "driver": db.driver, + }, } }