alphakit setup

This commit is contained in:
GabbyPrecious
2021-10-09 09:53:46 +01:00
commit 0ca0a0b9ac
50 changed files with 2222 additions and 0 deletions

0
ak/__init__.py Normal file
View File

3
ak/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
ak/apps.py Normal file
View File

@@ -0,0 +1,5 @@
from django.apps import AppConfig
class AkConfig(AppConfig):
name = "ak"

View File

3
ak/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

0
ak/tests/__init__.py Normal file
View File

View File

@@ -0,0 +1,53 @@
import pytest
import random
def test_homepage(db, tp):
""" Ensure we can hit the homepage """
# Use any page that is named 'home' otherwise use /
url = tp.reverse("home")
if not url:
url = "/"
response = tp.get(url)
tp.response_200(response)
def test_200_page(db, tp):
""" Test a 200 OK page """
response = tp.get("ok")
tp.response_200(response)
def test_403_page(db, tp):
""" Test a 403 error page """
response = tp.get("forbidden")
tp.response_403(response)
def test_404_page(db, tp):
""" Test a 404 error page """
rando = random.randint(1000, 20000)
url = f"/this/should/not/exist/{rando}/"
response = tp.get(url)
tp.response_404(response)
response = tp.get("not_found")
tp.response_404(response)
def test_500_page(db, tp):
""" Test our 500 error page """
url = tp.reverse("internal_server_error")
# Bail out of this test if this view is not defined
if not url:
pytest.skip()
with pytest.raises(ValueError):
response = tp.get("internal_server_error")
print(response.status_code)

45
ak/views.py Normal file
View File

@@ -0,0 +1,45 @@
from django.core.exceptions import PermissionDenied
from django.http import Http404, HttpResponse
from django.views import View
from django.views.generic import TemplateView
class HomepageView(TemplateView):
"""
Our default homepage for AlphaKit. We expect you to not use this view
after you start working on your project.
"""
template_name = "homepage.html"
class ForbiddenView(View):
"""
This view raises an exception to test our 403.html template
"""
def get(self, *args, **kwargs):
raise PermissionDenied("403 Forbidden")
class InternalServerErrorView(View):
"""
This view raises an exception to test our 500.html template
"""
def get(self, *args, **kwargs):
raise ValueError("500 Internal Server Error")
class NotFoundView(View):
"""
This view raises an exception to test our 404.html template
"""
def get(self, *args, **kwargs):
raise Http404("404 Not Found")
class OKView(View):
def get(self, *args, **kwargs):
return HttpResponse("200 OK", status=200)