Skip to content

Commit

Permalink
Added a separate test class for RequestSite.
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Sep 28, 2017
1 parent 1d8cfa3 commit 2015f5f
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions tests/sites_tests/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db.models.signals import post_migrate from django.db.models.signals import post_migrate
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.test import TestCase, modify_settings, override_settings from django.test import (
SimpleTestCase, TestCase, modify_settings, override_settings,
)
from django.test.utils import captured_stdout from django.test.utils import captured_stdout




Expand Down Expand Up @@ -203,27 +205,24 @@ def test_site_natural_key(self):
self.assertEqual(Site.objects.get_by_natural_key(self.site.domain), self.site) self.assertEqual(Site.objects.get_by_natural_key(self.site.domain), self.site)
self.assertEqual(self.site.natural_key(), (self.site.domain,)) self.assertEqual(self.site.natural_key(), (self.site.domain,))


@override_settings(ALLOWED_HOSTS=['example.com'])
def test_requestsite_save_notimplemented_msg(self): @override_settings(ALLOWED_HOSTS=['example.com'])
# Test response msg for RequestSite.save NotImplementedError class RequestSiteTests(SimpleTestCase):

def setUp(self):
request = HttpRequest() request = HttpRequest()
request.META = { request.META = {'HTTP_HOST': 'example.com'}
"HTTP_HOST": "example.com", self.site = RequestSite(request)
}
def test_save(self):
msg = 'RequestSite cannot be saved.' msg = 'RequestSite cannot be saved.'
with self.assertRaisesMessage(NotImplementedError, msg): with self.assertRaisesMessage(NotImplementedError, msg):
RequestSite(request).save() self.site.save()


@override_settings(ALLOWED_HOSTS=['example.com']) def test_delete(self):
def test_requestsite_delete_notimplemented_msg(self):
# Test response msg for RequestSite.delete NotImplementedError
request = HttpRequest()
request.META = {
"HTTP_HOST": "example.com",
}
msg = 'RequestSite cannot be deleted.' msg = 'RequestSite cannot be deleted.'
with self.assertRaisesMessage(NotImplementedError, msg): with self.assertRaisesMessage(NotImplementedError, msg):
RequestSite(request).delete() self.site.delete()




class JustOtherRouter: class JustOtherRouter:
Expand Down

0 comments on commit 2015f5f

Please sign in to comment.