-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.py
50 lines (38 loc) · 1.4 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
from django.db import models
from django.utils.unittest import TestCase
from supergeneric.views import AllInOneView
class DjangoSupergenericTests(TestCase):
def test_001_pk_name_generation(self):
"""
Tests that all AllInOneView class attributes could be calculated from
Model class only.
"""
class TestModel(models.Model):
class Meta:
app_label = 'test'
class TestAllInOneView(AllInOneView):
model = TestModel
self.assertEqual(TestAllInOneView.pk_name, 'testallinoneview_pk',
'pk_name generation fail')
def test_002_get_queryset_security(self):
"""
Tests on Github#3 "Honor EmptyQuerySet".
"""
class TestModel(models.Model):
class Meta:
app_label = 'test'
class TestAllInOneView(AllInOneView):
model = TestModel
@classmethod
def get_queryset(cls, request, **kwargs):
eqs = models.query.EmptyQuerySet()
eqs.test_flag = True
return eqs
list_view = TestAllInOneView.ListView()
list_view.request = object()
list_view.kwargs = {}
qs = list_view.get_queryset()
self.assertTrue(qs.test_flag,
'Github#3 "Honor EmptyQuerySet" regression fail')