1
Fork 0

Cleanup old views and tests

This commit is contained in:
Jake Howard 2016-04-05 20:21:28 +01:00
parent c8c6b342a8
commit fee3b39eb6
4 changed files with 4 additions and 117 deletions

View file

@ -1,20 +1,20 @@
from project.common.views import CustomTemplate
from django.views.generic import TemplateView
from .utils import get_post, reformat_date
from django.http import Http404
class BlogView(CustomTemplate):
class BlogView(TemplateView):
template_name = "blog/post.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['blog'] = self.blog_data
context['blog']['date'] = reformat_date(self.blog_data['date'])
context['html_title'] = self.blog_data['title']
return context
def dispatch(self, request, *args, **kwargs):
self.blog_data = get_post(kwargs['slug'])
if not self.blog_data:
raise Http404
self.html_title = self.blog_data['title']
return super().dispatch(request, *args, **kwargs)

View file

@ -7,73 +7,9 @@ from collections import namedtuple
PATH = os.path.dirname(os.path.abspath(__file__))
class CustomTemplateTestCase(TestCase):
def setUp(self):
self.template = 'pages:index'
def test_accessable(self):
response = self.client.get(reverse(self.template))
self.assertEqual(response.status_code, 200)
def test_context(self):
response = self.client.get(reverse(self.template))
for item in ['html_title', 'body_class', 'js_redirect']:
self.assertIn(item, response.context)
class ReverserTestCase(TestCase):
REVERSER_IDENT = 'reverser:reverser'
def test_reverser(self):
response = self.client.post(reverse(self.REVERSER_IDENT), data={'ident': 'pages:index'})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.data, reverse('pages:index'))
def test_invalid_reverser(self):
response = self.client.post(reverse(self.REVERSER_IDENT), data={'ident': 'pages:i-dont-exist'})
self.assertEqual(response.status_code, 404)
class MarkdownViewTestCase(TestCase):
def test_accessable(self):
response = self.client.get(reverse('projects:project', args=['test']))
self.assertEqual(response.status_code, 200)
def test_parsing(self):
response = self.client.get(reverse('projects:project', args=['test']))
self.assertContains(response, '<h1>Testing</h1>')
def test_template_engine(self):
response = self.client.get(reverse('projects:project', args=['test']))
self.assertContains(response, reverse('projects:all'))
def test_invalid_template(self):
response = self.client.get(reverse('projects:project', args=['not-a-project']))
self.assertEqual(response.status_code, 404)
MockJob = namedtuple('MockJob', {'workspace': {}})
class WorkerTestCase(TestCase):
def test_mail_job_creation(self):
data = {
'name': 'Person',
'email': '123@123.123',
'message': 'Hi there, things.'
}
workspace = {
'template': 'email/contact_message.html',
'from_email': data['email'],
'to_email': 'info@theorangeone.net',
'context': data
}
self.client.post(reverse('about:index'), data)
self.assertEqual(Job.objects.count(), 1)
job = Job.objects.all()[0]
self.assertEqual(job.workspace, workspace)
def test_email_error(self):
data = {
'name': 'Person',

View file

@ -1,48 +0,0 @@
from django.views.generic import TemplateView, FormView
from django.template import loader, Context
from django.template.base import TemplateDoesNotExist
from django.http import Http404
import markdown2
class CustomTemplate(TemplateView):
html_title = ""
body_class = ""
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['html_title'] = self.html_title
context['body_class'] = self.body_class
context['js_redirect'] = True
return context
class CustomFormTemplate(FormView):
html_title = ""
body_class = ""
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['html_title'] = self.html_title
context['body_class'] = self.body_class
context['js_redirect'] = True
return context
class MarkdownView(CustomTemplate):
template_name = 'markdown_content.html'
page_title = ""
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['page_title'] = self.page_title
try:
markdown_template = loader.get_template(self.markdown)
except TemplateDoesNotExist:
raise Http404
c = Context(self.get_markdown_context().update(context))
context['markdown_content'] = markdown2.markdown(markdown_template.render(c))
return context
def get_markdown_context(self):
return {}

View file

@ -1,4 +1,3 @@
from project.common.views import CustomTemplate
import os.path
from django.conf import settings
from django.http import HttpResponse, Http404