Browse Source

add tests

subDesTagesMitExtraKaese 2 years ago
parent
commit
519a26f739
2 changed files with 23 additions and 5 deletions
  1. 21 2
      tests.py
  2. 2 3
      views.py

+ 21 - 2
tests.py

@@ -1,3 +1,22 @@
-from django.test import TestCase
+from django.test import TestCase, Client
 
-# Create your tests here.
+class StammbaumTest(TestCase):
+  def test_view_should_not_be_public(self):
+    client = Client(HTTP_HOST="127.0.0.1:8001")
+    response = client.get("/stammbaum/")
+    self.assertEqual(response.status_code, 403)
+    
+  def test_preview_should_not_be_public(self):
+    client = Client(HTTP_HOST="127.0.0.1:8001")
+    response = client.get("/stammbaum/person/1/thumb")
+    self.assertEqual(response.status_code, 301)
+
+  def test_image_should_not_be_public(self):
+    client = Client(HTTP_HOST="127.0.0.1:8001")
+    response = client.get("/stammbaum/person/1/image")
+    self.assertEqual(response.status_code, 301)
+
+  def test_upload_should_not_be_public(self):
+    client = Client(HTTP_HOST="127.0.0.1:8001")
+    response = client.post("/stammbaum/person/1/upload")
+    self.assertEqual(response.status_code, 301)

+ 2 - 3
views.py

@@ -31,10 +31,9 @@ def index(request, group_id=None):
       'pairs': list(partners.values_list()),
       'groups': list(Group.objects.values())
     }
+    return render(request, 'stammbaum/index.html', context, status=200)
   else:
-    context = {}
-  template = loader.get_template('stammbaum/index.html')
-  return HttpResponse(template.render(context, request))
+    return render(request, 'stammbaum/index.html', status=403)
 
 class Login(auth.views.LoginView):
   template_name = 'stammbaum/login.html'