2016-01-10 21:23:55 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.core.urlresolvers import reverse
|
2016-01-22 08:23:34 +00:00
|
|
|
import os.path
|
2016-01-24 19:54:57 +00:00
|
|
|
from django_dbq.models import Job
|
|
|
|
from . import jobs
|
|
|
|
from collections import namedtuple
|
2016-01-10 21:23:55 +00:00
|
|
|
|
2016-01-22 08:23:34 +00:00
|
|
|
PATH = os.path.dirname(os.path.abspath(__file__))
|
2016-01-10 21:23:55 +00:00
|
|
|
|
2016-01-22 08:40:01 +00:00
|
|
|
|
2016-01-10 21:23:55 +00:00
|
|
|
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)
|
2016-01-20 19:28:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReverserTestCase(TestCase):
|
|
|
|
REVERSER_IDENT = 'reverser:reverser'
|
2016-01-22 08:40:01 +00:00
|
|
|
|
2016-01-20 19:28:02 +00:00
|
|
|
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)
|
2016-01-22 08:23:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MarkdownViewTestCase(TestCase):
|
|
|
|
def test_accessable(self):
|
2016-01-26 22:41:43 +00:00
|
|
|
response = self.client.get(reverse('projects:project', args=['test']))
|
2016-01-22 08:23:34 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_parsing(self):
|
2016-01-26 22:41:43 +00:00
|
|
|
response = self.client.get(reverse('projects:project', args=['test']))
|
2016-01-22 08:23:34 +00:00
|
|
|
self.assertContains(response, '<h1>Testing</h1>')
|
|
|
|
|
|
|
|
def test_template_engine(self):
|
2016-01-26 22:41:43 +00:00
|
|
|
response = self.client.get(reverse('projects:project', args=['test']))
|
|
|
|
self.assertContains(response, reverse('projects:all'))
|
2016-01-22 08:23:34 +00:00
|
|
|
|
|
|
|
def test_invalid_template(self):
|
2016-01-26 22:41:43 +00:00
|
|
|
response = self.client.get(reverse('projects:project', args=['not-a-project']))
|
2016-01-22 08:23:34 +00:00
|
|
|
self.assertEqual(response.status_code, 404)
|
2016-01-24 19:54:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2016-01-26 22:41:43 +00:00
|
|
|
self.client.post(reverse('about:index'), data)
|
2016-01-24 19:54:57 +00:00
|
|
|
self.assertEqual(Job.objects.count(), 1)
|
|
|
|
job = Job.objects.all()[0]
|
|
|
|
self.assertEqual(job.workspace, workspace)
|
|
|
|
|
|
|
|
def test_email_error(self):
|
|
|
|
data = {
|
|
|
|
'name': 'Person',
|
|
|
|
'email': '123@123.123',
|
|
|
|
'message': 'Hi there, things.'
|
|
|
|
}
|
|
|
|
workspace = {
|
|
|
|
'template': 'email/contact_message.html',
|
|
|
|
'from_email': 'me@123.123',
|
|
|
|
'to_email': data['email'],
|
|
|
|
'context': data
|
|
|
|
}
|
|
|
|
job = MockJob(workspace)
|
|
|
|
errors = None
|
|
|
|
try:
|
|
|
|
jobs.send_email(job)
|
|
|
|
except Exception as e:
|
|
|
|
errors = e
|
|
|
|
|
|
|
|
self.assertFalse(errors)
|