allura
修订版 | 74cae90557ab9516a9ef677f0b18d89faea60f51 (tree) |
---|---|
时间 | 2012-05-04 02:22:13 |
作者 | Jenny Steele <jsteele@geek...> |
Commiter | Yaroslav Luzin |
[#4113] Neighborhood and project GA tracking now checks to make sure feature is enabled for the neighborhood
@@ -38,9 +38,11 @@ | ||
38 | 38 | {% if value.support_page == '_url' %} checked{% endif %}> |
39 | 39 | <label for="support_page_url_cb">URL: </label> |
40 | 40 | <input type="text" name="support_page_url" value="{{value.support_page_url}}" style="width: 70%"> |
41 | + {% if value.neighborhood.features['google_analytics'] %} | |
41 | 42 | {{ widget.display_label(widget.fields.tracking_id) }} |
42 | 43 | <br> |
43 | 44 | {{widget.display_field(widget.fields.tracking_id) }} |
45 | + {% endif %} | |
44 | 46 | </div> |
45 | 47 | <div class="grid-9"> |
46 | 48 |
@@ -42,11 +42,13 @@ | ||
42 | 42 | {% if account -%} |
43 | 43 | _add_tracking('sfnt', '{{account}}'); |
44 | 44 | {%- endif %} |
45 | - {% if project and project.neighborhood.tracking_id -%} | |
46 | - _add_tracking('nbhd', '{{project.neighborhood.tracking_id}}'); | |
47 | - {%- endif %} | |
48 | - {% if project and project.tracking_id -%} | |
49 | - _add_tracking('proj', '{{project.tracking_id}}'); | |
45 | + {% if project and project.neighborhood.features['google_analytics'] -%} | |
46 | + {% if project.neighborhood.tracking_id -%} | |
47 | + _add_tracking('nbhd', '{{project.neighborhood.tracking_id}}'); | |
48 | + {%- endif %} | |
49 | + {% if project.tracking_id -%} | |
50 | + _add_tracking('proj', '{{project.tracking_id}}'); | |
51 | + {%- endif %} | |
50 | 52 | {%- endif %} |
51 | 53 | |
52 | 54 | (function() { |
@@ -24,8 +24,10 @@ | ||
24 | 24 | {{widget.display_field(widget.fields.icon)}} |
25 | 25 | </div> |
26 | 26 | {% endif %} |
27 | + {% if value.features and value.features['google_analytics'] %} | |
27 | 28 | <label class="grid-4">Analytics Tracking ID</label> |
28 | 29 | <div class="grid-14">{{widget.display_field(widget.fields.tracking_id)}}</div> |
30 | + {% endif %} | |
29 | 31 | <label class="grid-4"> </label> |
30 | 32 | <div class="grid-14"><input type="submit" value="Save"/></div> |
31 | 33 | </form> |
@@ -48,6 +48,8 @@ class TestNeighborhood(TestController): | ||
48 | 48 | r = self.app.get('/adobe/_admin/', extra_environ=dict(username='root')) |
49 | 49 | r = self.app.get('/adobe/_admin/overview', extra_environ=dict(username='root')) |
50 | 50 | r = self.app.get('/adobe/_admin/accolades', extra_environ=dict(username='root')) |
51 | + neighborhood = M.Neighborhood.query.get(name='Adobe') | |
52 | + neighborhood.features['google_analytics'] = True | |
51 | 53 | r = self.app.post('/adobe/_admin/update', |
52 | 54 | params=dict(name='Mozq1', css='', homepage='# MozQ1!', tracking_id='U-123456'), |
53 | 55 | extra_environ=dict(username='root')) |
@@ -112,6 +114,34 @@ class TestNeighborhood(TestController): | ||
112 | 114 | image = Image.open(StringIO(r.body)) |
113 | 115 | assert image.size == (48,48) |
114 | 116 | |
117 | + def test_google_analytics(self): | |
118 | + # analytics allowed | |
119 | + neighborhood = M.Neighborhood.query.get(name='Adobe') | |
120 | + neighborhood.features['google_analytics'] = True | |
121 | + r = self.app.get('/adobe/_admin/overview', extra_environ=dict(username='root')) | |
122 | + assert 'Analytics Tracking ID' in r | |
123 | + r = self.app.get('/adobe/adobe-1/admin/overview', extra_environ=dict(username='root')) | |
124 | + assert 'Analytics Tracking ID' in r | |
125 | + r = self.app.post('/adobe/_admin/update', | |
126 | + params=dict(name='Adobe', css='', homepage='# MozQ1', tracking_id='U-123456'), | |
127 | + extra_environ=dict(username='root')) | |
128 | + r = self.app.post('/adobe/adobe-1/admin/update', | |
129 | + params=dict(tracking_id='U-654321'), | |
130 | + extra_environ=dict(username='root')) | |
131 | + r = self.app.get('/adobe/adobe-1/admin/overview', extra_environ=dict(username='root')) | |
132 | + assert "_add_tracking('nbhd', 'U-123456');" in r | |
133 | + assert "_add_tracking('proj', 'U-654321');" in r | |
134 | + # analytics not allowed | |
135 | + neighborhood = M.Neighborhood.query.get(name='Adobe') | |
136 | + neighborhood.features['google_analytics'] = False | |
137 | + r = self.app.get('/adobe/_admin/overview', extra_environ=dict(username='root')) | |
138 | + assert 'Analytics Tracking ID' not in r | |
139 | + r = self.app.get('/adobe/adobe-1/admin/overview', extra_environ=dict(username='root')) | |
140 | + assert 'Analytics Tracking ID' not in r | |
141 | + r = self.app.get('/adobe/adobe-1/admin/overview', extra_environ=dict(username='root')) | |
142 | + assert "_add_tracking('nbhd', 'U-123456');" not in r | |
143 | + assert "_add_tracking('proj', 'U-654321');" not in r | |
144 | + | |
115 | 145 | def test_custom_css(self): |
116 | 146 | test_css = '.test{color:red;}' |
117 | 147 | custom_css = 'Custom CSS' |