Ticket #17320: remove_whitespace_from_domain.diff

File remove_whitespace_from_domain.diff, 1.7 KB (added by Jason Novinger, 13 years ago)
  • django/contrib/sites/tests.py

     
    5454        site = get_current_site(request)
    5555        self.assertTrue(isinstance(site, RequestSite))
    5656        self.assertEqual(site.name, u"example.com")
     57
     58    def test_no_whitespace_in_domain(self):
     59        # Test that all whitespace is removed from domain before being saved
     60        incorrect = '  example . com  '
     61        correct = 'example.com'
     62
     63        new_site = Site.objects.create(domain=incorrect, name="An example site with whitespace in the domain")
     64        site_from_db = Site.objects.get(pk=new_site.pk)
     65
     66        # Test that domain whitespace has been removed on create() insert
     67        self.assertEqual(site_from_db.domain, correct)
     68
     69        site_from_db.domain = incorrect
     70        site_from_db.save()
     71        another_site_from_db = Site.objects.get(pk=site_from_db.pk)
     72
     73        # Test that domain whitespace has been removed on save() update
     74        self.assertEqual(another_site_from_db.domain, correct)
  • django/contrib/sites/models.py

     
    4848        return self.domain
    4949
    5050    def save(self, *args, **kwargs):
     51        # Domains with spaces cause problems when generating links.
     52        self.domain = self.domain.replace(' ', '')
    5153        super(Site, self).save(*args, **kwargs)
    5254        # Cached information will likely be incorrect now.
    5355        if self.id in SITE_CACHE:
Back to Top