From 332b5446c624d98164ac9e63dcd3a251a435633f Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 5 Apr 2016 22:37:37 +0100 Subject: [PATCH] Update tests --- project/common/tests.py | 7 ++++--- project/pages/tests.py | 19 +++++++++++++++++++ project/pages/urls.py | 4 ++-- project/pages/views.py | 9 +++++---- 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 project/pages/tests.py diff --git a/project/common/tests.py b/project/common/tests.py index 049f1c5..0785cfc 100644 --- a/project/common/tests.py +++ b/project/common/tests.py @@ -1,13 +1,14 @@ from django.test import TestCase -from django.core.urlresolvers import reverse import os.path -from django_dbq.models import Job from . import jobs from collections import namedtuple + PATH = os.path.dirname(os.path.abspath(__file__)) -MockJob = namedtuple('MockJob', {'workspace': {}}) + +MockJob = namedtuple('MockJob', {'workspace': {}}) + class WorkerTestCase(TestCase): def test_email_error(self): diff --git a/project/pages/tests.py b/project/pages/tests.py new file mode 100644 index 0000000..7f2554e --- /dev/null +++ b/project/pages/tests.py @@ -0,0 +1,19 @@ +from django.test import TestCase +from django.conf import settings +import os.path +from glob import glob + + +class PagesTestCase(TestCase): + def setUp(self): + directories = glob(os.path.join(settings.BASE_DIR, 'templates') + '/**/*.*') + self.urls = [] + for directory in directories: + if 'email' in directory or 'blog' in directory: + continue + self.urls.append(directory.replace(os.path.join(settings.BASE_DIR, 'templates'), '').split('.')[0].replace('index', '')) + + def test_pages_accessable(self): + for path in self.urls: + response = self.client.get(path) + self.assertEqual(response.status_code, 200) diff --git a/project/pages/urls.py b/project/pages/urls.py index a1def4b..87c68de 100644 --- a/project/pages/urls.py +++ b/project/pages/urls.py @@ -1,5 +1,5 @@ -from django.conf.urls import include, url -from .views import page_view, index_view, AboutView +from django.conf.urls import url +from .views import page_view, AboutView urlpatterns = [ diff --git a/project/pages/views.py b/project/pages/views.py index e62dc02..c6e8a76 100644 --- a/project/pages/views.py +++ b/project/pages/views.py @@ -1,12 +1,17 @@ import os.path +from django.views.generic import FormView from django.conf import settings from django.http import HttpResponse, Http404 from django.template.loader import get_template from .utils import get_context, parse_content, get_title_from_markdown +from project.common.forms import ContactForm def page_view(request, path): template = None + if path.endswith('/'): + path = path[:-1] + if os.path.isdir(os.path.join(settings.BASE_DIR, 'templates', path)): path = os.path.join(path, 'index') for extension in ['md', 'html']: @@ -27,10 +32,6 @@ def page_view(request, path): return HttpResponse(parsed_content) -def index_view(request): - return page_view(request, 'index') - - class AboutView(FormView): template_name = 'about/index.html' success_url = '/about/?sent'