Skip to content

Commit 6c8ce2d

Browse files
Implemented initial tests. About 50% coverage.
1 parent 7d7b776 commit 6c8ce2d

File tree

11 files changed

+346
-48
lines changed

11 files changed

+346
-48
lines changed

django_postgresql_dag/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.conf import settings
2+
from django.conf.urls.static import static
3+
from django.urls import include, path, re_path
4+
5+
urlpatterns = [
6+
]
7+

manage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import sys
44

55
if __name__ == '__main__':
6-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_postgresql_dag.settings')
6+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
7+
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_postgresql_dag.settings')
78
try:
89
from django.core.management import execute_from_command_line
910
except ImportError as exc:

settings.py

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1717

1818

19-
# Quick-start development settings - unsuitable for production
20-
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
21-
2219
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'jac-=6t&d**x6qid9^g1y5b5e6ra@d9*==+7l()yg*g4rt4mcj'
20+
SECRET_KEY = "igk3EsnGJ&Nd5AiR%W89*mN&Of!qrb%W3bX4OvUXL6*6FZ*PFz0iU!7tG2uW"
2421

2522
# SECURITY WARNING: don't run with debug turned on in production!
2623
DEBUG = True
@@ -31,56 +28,57 @@
3128
# Application definition
3229

3330
INSTALLED_APPS = [
34-
'django.contrib.admin',
35-
'django.contrib.auth',
36-
'django.contrib.contenttypes',
37-
'django.contrib.sessions',
38-
'django.contrib.messages',
39-
'django.contrib.staticfiles',
31+
"django.contrib.admin",
32+
"django.contrib.auth",
33+
"django.contrib.contenttypes",
34+
"django.contrib.sessions",
35+
"django.contrib.messages",
36+
"django.contrib.staticfiles",
37+
"tests",
4038
]
4139

4240
MIDDLEWARE = [
43-
'django.middleware.security.SecurityMiddleware',
44-
'django.contrib.sessions.middleware.SessionMiddleware',
45-
'django.middleware.common.CommonMiddleware',
46-
'django.middleware.csrf.CsrfViewMiddleware',
47-
'django.contrib.auth.middleware.AuthenticationMiddleware',
48-
'django.contrib.messages.middleware.MessageMiddleware',
49-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
41+
"django.middleware.security.SecurityMiddleware",
42+
"django.contrib.sessions.middleware.SessionMiddleware",
43+
"django.middleware.common.CommonMiddleware",
44+
"django.middleware.csrf.CsrfViewMiddleware",
45+
"django.contrib.auth.middleware.AuthenticationMiddleware",
46+
"django.contrib.messages.middleware.MessageMiddleware",
47+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5048
]
5149

52-
ROOT_URLCONF = 'django_postgresql_dag.urls'
50+
ROOT_URLCONF = "django_postgresql_dag.urls"
5351

5452
TEMPLATES = [
5553
{
56-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57-
'DIRS': [],
58-
'APP_DIRS': True,
59-
'OPTIONS': {
60-
'context_processors': [
61-
'django.template.context_processors.debug',
62-
'django.template.context_processors.request',
63-
'django.contrib.auth.context_processors.auth',
64-
'django.contrib.messages.context_processors.messages',
54+
"BACKEND": "django.template.backends.django.DjangoTemplates",
55+
"DIRS": [],
56+
"APP_DIRS": True,
57+
"OPTIONS": {
58+
"context_processors": [
59+
"django.template.context_processors.debug",
60+
"django.template.context_processors.request",
61+
"django.contrib.auth.context_processors.auth",
62+
"django.contrib.messages.context_processors.messages",
6563
],
6664
},
6765
},
6866
]
6967

70-
WSGI_APPLICATION = 'django_postgresql_dag.wsgi.application'
68+
WSGI_APPLICATION = "django_postgresql_dag.wsgi.application"
7169

7270

7371
# Database
7472
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
7573

7674
DATABASES = {
77-
'default': {
78-
'ENGINE': 'django.db.backends.postgresql_psycopg2',
79-
'NAME': 'dbname',
80-
'USER': 'user',
81-
'PASSWORD': 'password',
82-
'HOST': 'hostaddress',
83-
'PORT': '25060',
75+
"default": {
76+
"ENGINE": "django.db.backends.postgresql_psycopg2",
77+
"NAME": "dagdb",
78+
"USER": "daguser",
79+
"PASSWORD": "daguser",
80+
"HOST": "localhost",
81+
"PORT": "5432",
8482
}
8583
}
8684

@@ -90,35 +88,32 @@
9088

9189
AUTH_PASSWORD_VALIDATORS = [
9290
{
93-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
9492
},
9593
{
96-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
9795
},
9896
{
99-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
10098
},
10199
{
102-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
103101
},
104102
]
105103

106104

107105
# Internationalization
108106
# https://docs.djangoproject.com/en/2.1/topics/i18n/
109107

110-
LANGUAGE_CODE = 'en-us'
111-
112-
TIME_ZONE = 'UTC'
113-
108+
LANGUAGE_CODE = "en-us"
109+
TIME_ZONE = "UTC"
114110
USE_I18N = True
115-
116111
USE_L10N = True
117-
118112
USE_TZ = True
119113

120114

121115
# Static files (CSS, JavaScript, Images)
122116
# https://docs.djangoproject.com/en/2.1/howto/static-files/
123117

124-
STATIC_URL = '/static/'
118+
STATIC_URL = "/static/"
119+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
from setuptools import setup
55

6-
version = '0.0.6'
6+
version = '0.0.7'
77

88
classifiers = [
99
"Development Status :: 3 - Alpha",
File renamed without changes.

tests/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class TestsConfig(AppConfig):
5+
name = "tests"
6+

tests/dag_output.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
expected_tree_output = '''# 1
2+
Descendants:
3+
# 5
4+
# 7
5+
# 2
6+
Descendants:
7+
# 8
8+
# 6
9+
# 8
10+
# 9
11+
# 7
12+
# 3
13+
Descendants:
14+
# 9
15+
# 7
16+
# 4
17+
Descendants:
18+
# 6
19+
# 8
20+
# 9
21+
# 7
22+
# 5
23+
# 6
24+
# 7
25+
Ancestors:
26+
# 3
27+
# 5
28+
# 1
29+
# 6
30+
# 2
31+
# 4
32+
# 8
33+
Ancestors:
34+
# 2
35+
# 6
36+
# 2
37+
# 4
38+
# 9
39+
Ancestors:
40+
# 3
41+
# 6
42+
# 2
43+
# 4
44+
# 10
45+
'''

tests/migrations/0001_initial.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Generated by Django 3.0.8 on 2020-10-19 02:55
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='NetworkEdge',
17+
fields=[
18+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('name', models.CharField(max_length=100)),
20+
],
21+
options={
22+
'abstract': False,
23+
},
24+
),
25+
migrations.CreateModel(
26+
name='NetworkNode',
27+
fields=[
28+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
29+
('name', models.CharField(max_length=100)),
30+
('children', models.ManyToManyField(blank=True, related_name='parents', through='tests.NetworkEdge', to='tests.NetworkNode')),
31+
],
32+
options={
33+
'abstract': False,
34+
},
35+
),
36+
migrations.AddField(
37+
model_name='networkedge',
38+
name='child',
39+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='NetworkNode_parent', to='tests.NetworkNode'),
40+
),
41+
migrations.AddField(
42+
model_name='networkedge',
43+
name='parent',
44+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='NetworkNode_child', to='tests.NetworkNode'),
45+
),
46+
]

tests/migrations/__init__.py

Whitespace-only changes.

tests/models.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django.db import models
2+
from django_postgresql_dag.models import node_factory, edge_factory
3+
4+
class NetworkEdge(edge_factory("NetworkNode", concrete=False)):
5+
name = models.CharField(max_length=100)
6+
7+
def __str__(self):
8+
return self.name
9+
10+
def save(self, *args, **kwargs):
11+
self.name = f"{self.parent.name} {self.child.name}"
12+
super().save(*args, **kwargs)
13+
14+
class Meta:
15+
app_label = 'tests'
16+
17+
18+
class NetworkNode(node_factory(NetworkEdge)):
19+
name = models.CharField(max_length=100)
20+
21+
def __str__(self):
22+
return self.name
23+
24+
class Meta:
25+
app_label = 'tests'

0 commit comments

Comments
 (0)