Skip to content

Commit 987742f

Browse files
authored
Merge pull request #48 from Chive/feature/enhanced-testing
Add some utilities for easier testing
2 parents 06707c7 + 656b51e commit 987742f

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ nosetests.xml
3838
env/
3939
.venv/
4040
.idea/
41+
testing
42+
attachments

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
setup:
2+
make clean
3+
mkdir -p testing
4+
make prep-env envname=py3.9-dj2.2
5+
make prep-env envname=py3.9-dj3.1
6+
make prep-env envname=py3.9-dj3.2
7+
8+
start-22:
9+
make runserver envname=py3.9-dj2.2
10+
11+
start-31:
12+
make runserver envname=py3.9-dj3.1
13+
14+
start-32:
15+
make runserver envname=py3.9-dj3.2
16+
17+
18+
prep-env:
19+
mkdir testing/$(envname)
20+
.tox/$(envname)/bin/django-admin startproject testproject testing/$(envname)
21+
.tox/$(envname)/bin/pip install -e .
22+
23+
ln -s ../../examples/contact_form testing/$(envname)/
24+
ln -s ../../examples/simple testing/$(envname)/
25+
26+
gsed -i "40 i 'simple', 'contact_form'," testing/$(envname)/testproject/settings.py
27+
.tox/$(envname)/bin/python testing/$(envname)/manage.py migrate
28+
cp examples/testproject/urls.py testing/$(envname)/testproject/
29+
30+
# not supported in django 2.x
31+
# DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=admin [email protected] .tox/$(envname)/bin/python testing/$(envname)/manage.py createsuperuser --noinput
32+
echo "from django.contrib import auth; auth.get_user_model().objects.create_superuser('admin', '[email protected]', 'admin')" | .tox/$(envname)/bin/python testing/$(envname)/manage.py shell
33+
34+
runserver:
35+
.tox/$(envname)/bin/python testing/$(envname)/manage.py runserver localhost:8000
36+
37+
clean:
38+
rm -rf testing

examples/contact_form/admin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.contrib import admin
2+
3+
from . import models
4+
5+
6+
class AttachmentInline(admin.StackedInline):
7+
model = models.Attachment
8+
extra = 0
9+
10+
@admin.register(models.Message)
11+
class MessageAdmin(admin.ModelAdmin):
12+
inlines = [AttachmentInline]

examples/simple/admin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.contrib import admin
2+
3+
from . import models
4+
5+
6+
@admin.register(models.Attachment)
7+
class AttachmentAdmin(admin.ModelAdmin):
8+
pass

examples/simple/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.views.generic.edit import FormView
2+
from django.urls import reverse
23

34
from .forms import UploadForm
45
from .models import Attachment
@@ -7,9 +8,11 @@
78
class UploadView(FormView):
89
template_name = 'form.html'
910
form_class = UploadForm
10-
success_url = '/done/'
1111

1212
def form_valid(self, form):
1313
for each in form.cleaned_data['attachments']:
1414
Attachment.objects.create(file=each)
1515
return super(UploadView, self).form_valid(form)
16+
17+
def get_success_url(self):
18+
return reverse('admin:simple_attachment_changelist')

examples/testproject/urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.contrib import admin
2+
from django.urls import path, include
3+
4+
urlpatterns = [
5+
path('admin/', admin.site.urls),
6+
path('contact/', include('contact_form.urls')),
7+
path('simple/', include('simple.urls')),
8+
]

0 commit comments

Comments
 (0)