Tests: Simplify Django version compatibility

* Restructure runtests.py as suggested in
  https://docs.djangoproject.com/en/1.9/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications

* Load version-specific Django settings modules
  (rather than trying to make a single settings.configure()
  work with all supported versions).

* Use `django-admin startproject` defaults for all
  settings modules. (Tests compatibility with typical
  apps, middleware, and other settings.)

* Set up tests-specific url config; switch to literal
  urls in test cases. (Eliminates url `reverse` from
  tests.)

* Make runtests.py executable

Closes #18
This commit is contained in:
medmunds
2016-05-31 11:01:45 -07:00
parent 296f6cab50
commit 34af81aee6
10 changed files with 435 additions and 106 deletions

View File

@@ -1,7 +1,6 @@
import json
from datetime import datetime
from django.core.urlresolvers import reverse
from django.utils.timezone import get_fixed_timezone
from mock import ANY
@@ -12,8 +11,8 @@ from .webhook_cases import WebhookBasicAuthTestsMixin, WebhookTestCase
class PostmarkWebhookSecurityTestCase(WebhookTestCase, WebhookBasicAuthTestsMixin):
def call_webhook(self):
webhook = reverse('postmark_tracking_webhook')
return self.client.post(webhook, content_type='application/json', data=json.dumps({}))
return self.client.post('/anymail/postmark/tracking/',
content_type='application/json', data=json.dumps({}))
# Actual tests are in WebhookBasicAuthTestsMixin
@@ -36,8 +35,8 @@ class PostmarkDeliveryTestCase(WebhookTestCase):
"Subject": "Postmark event test",
"Content": "..."
}
webhook = reverse('postmark_tracking_webhook')
response = self.client.post(webhook, content_type='application/json', data=json.dumps(raw_event))
response = self.client.post('/anymail/postmark/tracking/',
content_type='application/json', data=json.dumps(raw_event))
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(self.tracking_handler, sender=PostmarkTrackingWebhookView,
event=ANY, esp_name='Postmark')
@@ -69,8 +68,8 @@ class PostmarkDeliveryTestCase(WebhookTestCase):
"ReceivedAt": "2016-04-27T16:21:41.2493688-04:00",
"Recipient": "recipient@example.com"
}
webhook = reverse('postmark_tracking_webhook')
response = self.client.post(webhook, content_type='application/json', data=json.dumps(raw_event))
response = self.client.post('/anymail/postmark/tracking/',
content_type='application/json', data=json.dumps(raw_event))
self.assertEqual(response.status_code, 200)
kwargs = self.assert_handler_called_once_with(self.tracking_handler, sender=PostmarkTrackingWebhookView,
event=ANY, esp_name='Postmark')