~bac/charmworld/bundle-redirect

« back to all changes in this revision

Viewing changes to charmworld/views/tests/test_misc.py

  • Committer: Brad Crittenden
  • Date: 2015-02-18 13:41:14 UTC
  • mfrom: (520.2.2 trunk)
  • Revision ID: bac@canonical.com-20150218134114-jx604y1brpyq4a0e
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
import os
5
 
import re
6
5
import unittest
7
6
 
8
7
from mock import patch
74
73
        else:
75
74
            self.fail('Cache-Control header not found.')
76
75
 
77
 
    def test_main_template_scheme(self):
78
 
        """Image and stylesheet URLs respect the WSGI scheme."""
79
 
        src_pattern = re.compile('src="([a-z]+)://')
80
 
        css_pattern = re.compile('href="([a-z]+)://.*\.css.*"')
81
 
        # Https enabled.
82
 
        response = self.app.get(
83
 
            '/', extra_environ={'wsgi.url_scheme': 'https'})
84
 
        https_count = 0
85
 
        for match in src_pattern.finditer(response.ubody):
86
 
            https_count += 1
87
 
            self.assertEqual('https', match.group(1))
88
 
        for match in css_pattern.finditer(response.ubody):
89
 
            https_count += 1
90
 
            self.assertEqual('https', match.group(1))
91
 
        self.assertTrue(https_count >= 2)
92
 
        # Http default.
93
 
        response = self.app.get('/')
94
 
        http_count = 0
95
 
        for match in src_pattern.finditer(response.ubody):
96
 
            http_count += 1
97
 
            self.assertEqual('http', match.group(1))
98
 
        for match in css_pattern.finditer(response.ubody):
99
 
            http_count += 1
100
 
            self.assertEqual('http', match.group(1))
101
 
        self.assertTrue(https_count == http_count)
102
 
 
103
76
 
104
77
class HeartbeatWebTestCase(WebTestBase):
105
78