Coverage for wagtailsharing/tests/test_models.py: 100%

# Coverage for wagtailsharing/tests/test_models.py : 100%

## 50 statements 50 run 0 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | from django.db import IntegrityError from django.test import RequestFactory, TestCase from wagtail.wagtailcore.models import Site from wagtailsharing.models import SharingSite class TestSharingSite(TestCase): def setUp(self): self.default_site = Site.objects.get(is_default_site=True) self.factory = RequestFactory() def create(self, **kwargs): return SharingSite.objects.create(site=self.default_site, **kwargs) def test_can_create(self): self.create(hostname='hostname', port=8000) def test_site_related_name_default_empty(self): with self.assertRaises(SharingSite.DoesNotExist): self.default_site.sharing_site def test_site_related_name(self): self.create(hostname='hostname', port=8000) self.assertIsNotNone(self.default_site.sharing_site) def test_str(self): site = self.create(hostname='hostname', port=8000) self.assertEqual(str(site), 'hostname:8000') def test_str_no_port(self): site = self.create(hostname='hostname') self.assertEqual(str(site), 'hostname') def test_uniqueness(self): self.create(hostname='hostname', port=1234) with self.assertRaises(IntegrityError): self.create(hostname='hostname', port=1234) def test_multiple_sharing_sites_not_allowed(self): self.create(hostname='hostname', port=1234) with self.assertRaises(IntegrityError): self.create(hostname='otherhost', port=5678) def test_find_for_request(self): sharing_site = self.create(hostname='hostname', port=1234) request = self.factory.get('/', HTTP_HOST='hostname', SERVER_PORT=1234) self.assertEqual(SharingSite.find_for_request(request), sharing_site) def test_find_for_request_no_sites(self): request = self.factory.get('/', HTTP_HOST='hostname', SERVER_PORT=1234) with self.assertRaises(SharingSite.DoesNotExist): SharingSite.find_for_request(request) def test_find_for_request_wrong_port(self): self.create(hostname='hostname', port=1234) request = self.factory.get('/', HTTP_HOST='hostname', SERVER_PORT=5678) with self.assertRaises(SharingSite.DoesNotExist): SharingSite.find_for_request(request) def test_find_for_request_hostname_keyerror(self): request = self.factory.get('/', SERVER_PORT=5678) del request.META['SERVER_NAME'] with self.assertRaises(SharingSite.DoesNotExist): SharingSite.find_for_request(request)