/
test_base.py
955 lines (816 loc) · 39 KB
/
test_base.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
import os
from urlparse import parse_qsl, urlparse
from django.conf import settings
from django.http import HttpResponse
from django.test.client import Client, RequestFactory
from django.test.utils import override_settings
from django.utils import simplejson
from funfactory.urlresolvers import reverse
from mock import ANY, call, Mock, patch
from nose.tools import eq_, ok_
from pyquery import PyQuery as pq
from bedrock.firefox import views as fx_views
from bedrock.firefox.firefox_details import FirefoxDetails, MobileDetails
from bedrock.firefox.utils import product_details
from bedrock.mozorg.tests import TestCase
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'test_data')
PROD_DETAILS_DIR = os.path.join(TEST_DATA_DIR, 'product_details_json')
GOOD_PLATS = {'Windows': {}, 'OS X': {}, 'Linux': {}}
with patch.object(settings, 'PROD_DETAILS_DIR', PROD_DETAILS_DIR):
firefox_details = FirefoxDetails()
mobile_details = MobileDetails()
class TestInstallerHelp(TestCase):
def setUp(self):
self.button_mock = Mock()
self.patcher = patch.dict('jingo.env.globals',
download_firefox=self.button_mock)
self.patcher.start()
self.view_name = 'firefox.installer-help'
with self.activate('en-US'):
self.url = reverse(self.view_name)
def tearDown(self):
self.patcher.stop()
def test_buttons_use_lang(self):
"""
The buttons should use the lang from the query parameter.
"""
self.client.get(self.url, {
'installer_lang': 'fr'
})
self.button_mock.assert_has_calls([
call(force_direct=True, force_full_installer=True, locale='fr'),
call('beta', small=ANY, force_direct=True,
force_full_installer=True, icon=ANY, locale='fr'),
call('aurora', small=ANY, force_direct=True,
force_full_installer=True, icon=ANY, locale='fr'),
])
def test_buttons_ignore_non_lang(self):
"""
The buttons should ignore an invalid lang.
"""
self.client.get(self.url, {
'installer_lang': 'not-a-locale'
})
self.button_mock.assert_has_calls([
call(force_direct=True, force_full_installer=True, locale=None),
call('beta', small=ANY, force_direct=True,
force_full_installer=True, icon=ANY, locale=None),
call('aurora', small=ANY, force_direct=True,
force_full_installer=True, icon=ANY, locale=None),
])
def test_invalid_channel_specified(self):
"""
All buttons should show when channel is invalid.
"""
self.client.get(self.url, {
'channel': 'dude',
})
self.button_mock.assert_has_calls([
call(force_direct=True, force_full_installer=True, locale=None),
call('beta', small=ANY, force_direct=True,
force_full_installer=True, icon=ANY, locale=None),
call('aurora', small=ANY, force_direct=True,
force_full_installer=True, icon=ANY, locale=None),
])
def test_one_button_when_channel_specified(self):
"""
There should be only one button when the channel is given.
"""
self.client.get(self.url, {
'channel': 'beta',
})
self.button_mock.assert_called_once_with('beta', force_direct=True,
force_full_installer=True,
locale=None)
@patch.object(fx_views, 'firefox_details', firefox_details)
class TestFirefoxDetails(TestCase):
def test_get_download_url(self):
url = firefox_details.get_download_url('OS X', 'pt-BR', '17.0')
self.assertListEqual(parse_qsl(urlparse(url).query),
[('product', 'firefox-17.0'),
('os', 'osx'),
('lang', 'pt-BR')])
# Linux 64-bit
url = firefox_details.get_download_url('Linux 64', 'en-US', '26.0')
self.assertListEqual(parse_qsl(urlparse(url).query),
[('product', 'firefox-26.0'),
('os', 'linux64'),
('lang', 'en-US')])
@patch.dict(firefox_details.firefox_versions,
FIREFOX_AURORA='28.0a2')
def test_get_download_url_aurora(self):
"""The Aurora version should give us an FTP url."""
url = firefox_details.get_download_url('OS X', 'en-US', '28.0a2')
self.assertIn('ftp.mozilla.org', url)
self.assertIn('latest-mozilla-aurora/firefox-28.0a2.en-US.mac.dmg', url)
@patch.dict(firefox_details.firefox_versions,
FIREFOX_AURORA='28.0a2')
def test_get_download_url_aurora_l10n(self):
"""Aurora non en-US should have a slightly different path."""
url = firefox_details.get_download_url('Linux', 'pt-BR', '28.0a2')
self.assertIn('ftp.mozilla.org', url)
self.assertIn('latest-mozilla-aurora-l10n/firefox-28.0a2.pt-BR.linux-i686.tar.bz2',
url)
@override_settings(FORCE_SSL_DOWNLOAD_VERSIONS=['27.0'])
@override_settings(STUB_INSTALLER_LOCALES={'win': settings.STUB_INSTALLER_ALL})
def get_download_url_ssl(self):
"""
SSL-enabled links should be used for the specific verions, except the
Windows stub installers.
"""
# SSL-enabled links won't be used for 26.0
url = firefox_details.get_download_url('OS X', 'pt-BR', '26.0')
self.assertListEqual(parse_qsl(urlparse(url).query),
[('product', 'firefox-26.0'),
('os', 'osx'),
('lang', 'pt-BR')])
# SSL-enabled links won't be used for 27.0 Windows builds (but SSL
# download is enabled by default for stub installers)
url = firefox_details.get_download_url('Windows', 'pt-BR', '27.0')
self.assertListEqual(parse_qsl(urlparse(url).query),
[('product', 'firefox-27.0'),
('os', 'win'),
('lang', 'pt-BR')])
# SSL-enabled links will be used for 27.0 OS X builds
url = firefox_details.get_download_url('OS X', 'pt-BR', '27.0')
self.assertListEqual(parse_qsl(urlparse(url).query),
[('product', 'firefox-27.0-SSL'),
('os', 'osx'),
('lang', 'pt-BR')])
# SSL-enabled links will be used for 27.0 Linux builds
url = firefox_details.get_download_url('Linux', 'pt-BR', '27.0')
self.assertListEqual(parse_qsl(urlparse(url).query),
[('product', 'firefox-27.0-SSL'),
('os', 'linux'),
('lang', 'pt-BR')])
def test_filter_builds_by_locale_name(self):
# search english
builds = firefox_details.get_filtered_full_builds(
firefox_details.latest_version('release'),
'ujara'
)
eq_(len(builds), 1)
eq_(builds[0]['name_en'], 'Gujarati')
# search native
builds = firefox_details.get_filtered_full_builds(
firefox_details.latest_version('release'),
u'જરા'
)
eq_(len(builds), 1)
eq_(builds[0]['name_en'], 'Gujarati')
# with a space
builds = firefox_details.get_filtered_full_builds(
firefox_details.latest_version('release'),
'british english'
)
eq_(len(builds), 1)
eq_(builds[0]['name_en'], 'English (British)')
# with a comma
builds = firefox_details.get_filtered_full_builds(
firefox_details.latest_version('release'),
u'French, Français'
)
eq_(len(builds), 1)
eq_(builds[0]['name_en'], 'French')
def test_linux64_build(self):
builds = firefox_details.get_filtered_full_builds(
firefox_details.latest_version('release')
)
url = builds[0]['platforms']['Linux 64']['download_url']
eq_(parse_qsl(urlparse(url).query)[1], ('os', 'linux64'))
@patch.dict(firefox_details.firefox_versions,
LATEST_FIREFOX_VERSION='25.0.2')
def test_esr_major_versions(self):
"""ESR versions should be dynamic based on latest"""
eq_(firefox_details.esr_major_versions, [24])
@patch.dict(firefox_details.firefox_versions,
LATEST_FIREFOX_VERSION='Phoenix')
def test_esr_major_versions_no_latest(self):
"""ESR versions should not blow up if current version is broken."""
eq_(firefox_details.esr_major_versions, [])
@patch.dict(firefox_details.firefox_versions,
LATEST_FIREFOX_VERSION='18.0.1')
def test_latest_major_version(self):
"""latest_major_version should return an int of the major version."""
eq_(firefox_details.latest_major_version('release'), 18)
@patch.dict(firefox_details.firefox_versions,
LATEST_FIREFOX_VERSION='Phoenix')
def test_latest_major_version_no_int(self):
"""latest_major_version should return 0 when no int."""
eq_(firefox_details.latest_major_version('release'), 0)
@patch.object(fx_views, 'mobile_details', mobile_details)
class TestMobileDetails(TestCase):
@patch.dict(mobile_details.mobile_details,
version='22.0.1')
def test_latest_release_version(self):
"""latest_version should return the latest release version."""
eq_(mobile_details.latest_version('release'), '22.0.1')
@patch.dict(mobile_details.mobile_details,
beta_version='23.0')
def test_latest_beta_version(self):
"""latest_version should return the latest beta version."""
eq_(mobile_details.latest_version('beta'), '23.0')
@patch.object(fx_views, 'firefox_details', firefox_details)
class TestFirefoxAll(TestCase):
def setUp(self):
with self.activate('en-US'):
self.url = reverse('firefox.all')
def test_no_search_results(self):
"""
Tables should be gone and not-found message should be shown when there
are no search results.
"""
resp = self.client.get(self.url + '?q=DOES_NOT_EXIST')
doc = pq(resp.content)
ok_(not doc('table.build-table'))
ok_(not doc('.not-found.hide'))
def test_no_search_query(self):
"""
When not searching all builds should show.
"""
resp = self.client.get(self.url)
doc = pq(resp.content)
eq_(len(doc('.build-table')), 2)
eq_(len(doc('.not-found.hide')), 2)
release = firefox_details.latest_version('release')
num_builds = len(firefox_details.get_filtered_full_builds(release))
num_builds += len(firefox_details.get_filtered_test_builds(release))
eq_(len(doc('tr[data-search]')), num_builds)
class TestFirefoxPartners(TestCase):
@patch('bedrock.firefox.views.settings.DEBUG', True)
def test_js_bundle_files_debug_true(self):
"""
When DEBUG is on the bundle should return the individual files
with the MEDIA_URL.
"""
bundle = 'partners_desktop'
files = settings.MINIFY_BUNDLES['js'][bundle]
files = [settings.MEDIA_URL + f for f in files]
self.assertEqual(files,
json.loads(fx_views.get_js_bundle_files(bundle)))
@patch('bedrock.firefox.views.settings.DEBUG', False)
def test_js_bundle_files_debug_false(self):
"""
When DEBUG is off the bundle should return a single minified filename.
"""
bundle = 'partners_desktop'
filename = '%sjs/%s-min.js?build=' % (settings.MEDIA_URL, bundle)
bundle_file = json.loads(fx_views.get_js_bundle_files(bundle))
self.assertEqual(len(bundle_file), 1)
self.assertTrue(bundle_file[0].startswith(filename))
@patch('bedrock.mozorg.views.requests.post')
def test_sf_form_proxy_error_response(self, post_patch):
"""An error response from SF should be returned."""
new_mock = Mock()
new_mock.status_code = 400
post_patch.return_value = new_mock
with self.activate('en-US'):
url = reverse('mozorg.partnerships')
resp = self.client.post(url, {
'first_name': 'The',
'last_name': 'Dude',
'company': 'Urban Achievers',
'email': 'thedude@mozilla.com',
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 400)
# decode JSON response
resp_data = simplejson.loads(resp.content)
self.assertEqual(resp_data['msg'], 'bad_request')
self.assertTrue(post_patch.called)
@patch('bedrock.mozorg.views.requests.post')
def test_sf_form_proxy_invalid_form(self, post_patch):
"""A form error should result in a 400 response."""
with self.activate('en-US'):
url = reverse('mozorg.partnerships')
resp = self.client.post(url, {
'first_name': 'Dude' * 20,
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 400)
# decode JSON response
resp_data = simplejson.loads(resp.content)
self.assertEqual(resp_data['msg'], 'Form invalid')
self.assertFalse(post_patch.called)
@patch('bedrock.mozorg.views.requests.post')
def test_sf_form_proxy(self, post_patch):
new_mock = Mock()
new_mock.status_code = 200
post_patch.return_value = new_mock
with self.activate('en-US'):
url = reverse('mozorg.partnerships')
resp = self.client.post(url, {
'first_name': 'The',
'last_name': 'Dude',
'title': 'Abider of things',
'company': 'Urban Achievers',
'email': 'thedude@mozilla.com',
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 200)
# decode JSON response
resp_data = simplejson.loads(resp.content)
self.assertEqual(resp_data['msg'], 'ok')
post_patch.assert_called_once_with(ANY, {
'first_name': u'The',
'last_name': u'Dude',
'description': u'',
'retURL': 'http://www.mozilla.org/en-US/about/'
'partnerships?success=1',
'title': u'Abider of things',
'URL': u'',
'company': u'Urban Achievers',
'oid': '00DU0000000IrgO',
'phone': u'',
'street': u'',
'zip': u'',
'city': u'',
'state': u'',
'country': u'',
'mobile': u'',
'00NU0000002pDJr': [],
'email': u'thedude@mozilla.com',
'lead_source': 'www.mozilla.org/about/partnerships/',
})
def test_sf_form_csrf_status(self):
"""Test that CSRF checks return 200 with token and 403 without."""
csrf_client = Client(enforce_csrf_checks=True)
response = csrf_client.get(reverse('firefox.partners.index'))
post_url = reverse('mozorg.partnerships')
response = csrf_client.post(post_url, {
'first_name': "Partner",
'csrfmiddlewaretoken': response.cookies['csrftoken'].value,
})
self.assertEqual(response.status_code, 200)
response = csrf_client.post(post_url, {'first_name': "Partner"})
self.assertEqual(response.status_code, 403)
none_mock = Mock()
none_mock.return_value = None
@patch.object(fx_views.WhatsnewView, 'redirect_to', none_mock)
@patch('bedrock.firefox.views.l10n_utils.render', return_value=HttpResponse())
class TestWhatsNew(TestCase):
def setUp(self):
self.view = fx_views.WhatsnewView.as_view()
self.rf = RequestFactory(HTTP_USER_AGENT='Firefox')
@override_settings(DEV=True)
def test_can_post(self, render_mock):
"""Home page must accept post for newsletter signup."""
req = self.rf.post('/en-US/firefox/whatsnew/')
self.view(req)
# would return 405 before calling render otherwise
render_mock.assert_called_once_with(req, ['firefox/whatsnew.html'], ANY)
@patch.object(fx_views.WhatsnewView, 'fxos_locales', ['de'])
@override_settings(DEV=True)
def test_fxos_locales(self, render_mock):
"""Should use a different template for fxos locales."""
req = self.rf.get('/de/firefox/whatsnew/')
req.locale = 'de'
self.view(req)
template = render_mock.call_args[0][1]
ctx = render_mock.call_args[0][2]
ok_('locales_with_video' not in ctx)
eq_(template, ['firefox/whatsnew-fxos.html'])
@override_settings(DEV=True)
def test_fx_nightly_29(self, render_mock):
"""Should use special nightly template for 29.0a1."""
req = self.rf.get('/en-US/firefox/whatsnew/')
self.view(req, fx_version='29.0a1')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/whatsnew-nightly-29.html'])
@override_settings(DEV=True)
def test_fx_australis_29(self, render_mock):
"""Should use australis template for 29.0."""
req = self.rf.get('/en-US/firefox/whatsnew/')
self.view(req, fx_version='29.0')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/australis/whatsnew-no-tour.html'])
@override_settings(DEV=True)
def test_fx_australis_29_0_1(self, render_mock):
"""Should use australis template for 29.0.1"""
req = self.rf.get('/en-US/firefox/whatsnew/')
self.view(req, fx_version='29.0.1')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/australis/whatsnew-no-tour.html'])
@override_settings(DEV=True)
def test_fx_30(self, render_mock):
"""Should use australis template for 30.0."""
req = self.rf.get('/en-US/firefox/whatsnew/')
self.view(req, fx_version='30.0')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/australis/whatsnew-no-tour.html'])
@override_settings(DEV=True)
def test_fx_31(self, render_mock):
"""Should use australis template for 31.0."""
req = self.rf.get('/en-US/firefox/whatsnew/')
self.view(req, fx_version='31.0')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/australis/whatsnew-no-tour.html'])
@override_settings(DEV=True)
def test_rv_prefix(self, render_mock):
"""Prefixed oldversion shouldn't impact version sniffing."""
req = self.rf.get('/en-US/firefox/whatsnew/?oldversion=rv:10.0')
self.view(req, fx_version='30.0')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/australis/whatsnew-tour.html'])
@override_settings(DEV=False)
def test_fx_australis_secure_redirect(self, render_mock):
"""Should redirect to https: for 29.0."""
url = '/en-US/firefox/whatsnew/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=False):
resp = self.view(req, fx_version='29.0')
eq_(resp['location'], 'https://testserver' + url)
@override_settings(DEV=True)
def test_fx_australis_secure_redirect_not_dev(self, render_mock):
"""Should not redirect to https: in DEV mode."""
url = '/en-US/firefox/whatsnew/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=False):
resp = self.view(req, fx_version='29.0')
eq_(resp.status_code, 200)
@override_settings(DEV=True)
def test_fx_australis_secure_redirect_secure(self, render_mock):
"""Should not redirect to https: when already secure."""
url = '/en-US/firefox/whatsnew/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=True):
resp = self.view(req, fx_version='29.0')
eq_(resp.status_code, 200)
@patch.object(fx_views.TourView, 'redirect_to', none_mock)
@patch('bedrock.firefox.views.l10n_utils.render', return_value=HttpResponse())
class TestTourView(TestCase):
def setUp(self):
self.view = fx_views.TourView.as_view()
self.rf = RequestFactory(HTTP_USER_AGENT='Firefox')
@override_settings(DEV=True)
def test_fx_tour_template(self, render_mock):
"""Should use firstrun tour template"""
req = self.rf.get('/en-US/firefox/tour/')
self.view(req, fx_version='29.0')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/australis/firstrun-tour.html'])
@override_settings(DEV=False)
def test_fx_australis_secure_redirect(self, render_mock):
"""Should redirect to https"""
url = '/en-US/firefox/tour/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=False):
resp = self.view(req, fx_version='29.0')
eq_(resp['location'], 'https://testserver' + url)
@override_settings(DEV=True)
def test_fx_australis_secure_redirect_not_dev(self, render_mock):
"""Should not redirect to https: in DEV mode."""
url = '/en-US/firefox/tour/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=False):
resp = self.view(req, fx_version='29.0')
eq_(resp.status_code, 200)
@override_settings(DEV=True)
def test_fx_australis_secure_redirect_secure(self, render_mock):
"""Should not redirect to https: when already secure."""
url = '/en-US/firefox/tour/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=True):
resp = self.view(req, fx_version='29.0')
eq_(resp.status_code, 200)
@patch.object(fx_views.FirstrunView, 'redirect_to', none_mock)
@patch('bedrock.firefox.views.l10n_utils.render', return_value=HttpResponse())
class TestFirstRun(TestCase):
def setUp(self):
self.view = fx_views.FirstrunView.as_view()
self.rf = RequestFactory()
@override_settings(DEV=True)
def test_can_post(self, render_mock):
"""Home page must accept post for newsletter signup."""
req = self.rf.post('/en-US/firefox/firstrun/')
self.view(req)
# would return 405 before calling render otherwise
render_mock.assert_called_once_with(req,
['firefox/australis/firstrun-tour.html'], ANY)
@override_settings(DEV=True)
def test_fx_australis_29(self, render_mock):
"""Should use firstrun tour template"""
req = self.rf.get('/en-US/firefox/firstrun/')
self.view(req, fx_version='29.0')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/australis/firstrun-tour.html'])
@override_settings(DEV=False)
def test_fx_australis_secure_redirect(self, render_mock):
"""Should redirect to https:"""
url = '/en-US/firefox/firstrun/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=False):
resp = self.view(req, fx_version='29.0')
eq_(resp['location'], 'https://testserver' + url)
@override_settings(DEV=True)
def test_fx_australis_secure_redirect_not_dev(self, render_mock):
"""Should not redirect to https: in DEV mode."""
url = '/en-US/firefox/firstrun/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=False):
resp = self.view(req, fx_version='29.0')
eq_(resp.status_code, 200)
@override_settings(DEV=True)
def test_fx_australis_secure_redirect_secure(self, render_mock):
"""Should not redirect to https: when already secure."""
url = '/en-US/firefox/firstrun/'
req = self.rf.get(url)
with patch.object(req, 'is_secure', return_value=True):
resp = self.view(req, fx_version='29.0')
eq_(resp.status_code, 200)
@patch.object(fx_views, 'firefox_details', firefox_details)
class FxVersionRedirectsMixin(object):
@override_settings(DEV=True) # avoid https redirects
def assert_ua_redirects_to(self, ua, url_name, status_code=301):
response = self.client.get(self.url, HTTP_USER_AGENT=ua)
eq_(response.status_code, status_code)
eq_(response['Vary'], 'User-Agent')
eq_(response['Location'],
'http://testserver%s' % reverse(url_name))
# An additional redirect test with a query string
query = '?ref=getfirefox'
response = self.client.get(self.url + query, HTTP_USER_AGENT=ua)
eq_(response.status_code, status_code)
eq_(response['Vary'], 'User-Agent')
eq_(response['Location'],
'http://testserver%s' % reverse(url_name) + query)
def test_non_firefox(self):
"""
Any non-Firefox user agents should be permanently redirected to
/firefox/new/.
"""
user_agent = 'random'
self.assert_ua_redirects_to(user_agent, 'firefox.new')
def test_bad_firefox(self):
"""
Any user agents with malformed Firefox UA strings should be permanently
redirected to /firefox/new/.
"""
user_agent = 'Mozilla/5.0 (SaferSurf) Firefox 1.5'
self.assert_ua_redirects_to(user_agent, 'firefox.new')
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='14.0')
def test_old_firefox(self):
"""
Any older versions of Firefox should be permanently redirected to
/firefox/new/.
"""
user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) '
'Gecko/20100101 Firefox/13.0')
self.assert_ua_redirects_to(user_agent, 'firefox.new')
@override_settings(DEV=True)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='13.0.5')
@patch('bedrock.mozorg.helpers.download_buttons.latest_version',
return_value=('13.0.5', GOOD_PLATS))
def test_current_minor_version_firefox(self, latest_mock):
"""
Should show current even if behind by a patch version
"""
user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) '
'Gecko/20100101 Firefox/13.0')
response = self.client.get(self.url, HTTP_USER_AGENT=user_agent)
eq_(response.status_code, 200)
eq_(response['Vary'], 'User-Agent')
@override_settings(DEV=True)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='25.0')
@patch('bedrock.mozorg.helpers.download_buttons.latest_version',
return_value=('25.0', GOOD_PLATS))
def test_esr_firefox(self, latest_mock):
"""
Currently released ESR firefoxen should not redirect. At present
that is 24.0.x.
"""
user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) '
'Gecko/20100101 Firefox/24.0')
response = self.client.get(self.url, HTTP_USER_AGENT=user_agent)
eq_(response.status_code, 200)
eq_(response['Vary'], 'User-Agent')
@override_settings(DEV=True)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='16.0')
@patch('bedrock.mozorg.helpers.download_buttons.latest_version',
return_value=('16.0', GOOD_PLATS))
def test_current_firefox(self, latest_mock):
"""
Currently released firefoxen should not redirect.
"""
user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) '
'Gecko/20100101 Firefox/16.0')
response = self.client.get(self.url, HTTP_USER_AGENT=user_agent)
eq_(response.status_code, 200)
eq_(response['Vary'], 'User-Agent')
@override_settings(DEV=True)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='16.0')
@patch('bedrock.mozorg.helpers.download_buttons.latest_version',
return_value=('16.0', GOOD_PLATS))
def test_future_firefox(self, latest_mock):
"""
Pre-release firefoxen should not redirect.
"""
user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:18.0) '
'Gecko/20100101 Firefox/18.0')
response = self.client.get(self.url, HTTP_USER_AGENT=user_agent)
eq_(response.status_code, 200)
eq_(response['Vary'], 'User-Agent')
class TestWhatsnewRedirect(FxVersionRedirectsMixin, TestCase):
def setUp(self):
self.user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:29.0) '
'Gecko/20100101 Firefox/29.0')
self.expected = 'data-has-tour="True"'
self.url = reverse('firefox.whatsnew', args=['29.0'])
@override_settings(DEV=True)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='16.0')
def test_whatsnew_tour(self):
"""
Hitting /firefox/29.0/whatsnew/?f=30 with en-US locale should render
firefox/australis/whatsnew-no-tour.html. Hitting en-US locale with
f=31 should render firefox/australis/whatsnew-tour.html. Any other
f value or locale should not show the tour.
"""
# en-US with funnelcake id 30 should not give a tour
response = self.client.get(self.url + '?f=30', HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
# en-US with funnelcake id 30 plus oldversion should not get a tour
response = self.client.get(self.url + '?f=30&oldversion=28.0',
HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
# en-US with funnelcake id 31 should give a tour
response = self.client.get(self.url + '?f=31', HTTP_USER_AGENT=self.user_agent)
self.assertIn(self.expected, response.content)
# en-US with improper funnelcake id should not give a tour
response = self.client.get(self.url + '?f=0', HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
# en-US with no funnelcake id should not give a tour
response = self.client.get(self.url, HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
with self.activate('de'):
self.url = reverse('firefox.whatsnew', args=['29.0'])
# de with funnelcake id 31 should not get a tour
response = self.client.get(self.url + '?f=31', HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
@override_settings(DEV=True)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='16.0')
def test_whatsnew_tour_oldversion(self):
"""Should not show tour if upgrading from 29.0 onwards."""
# sanity check that it should show for other values of "oldversion"
response = self.client.get(self.url + '?oldversion=28.0', HTTP_USER_AGENT=self.user_agent)
self.assertIn(self.expected, response.content)
response = self.client.get(self.url + '?oldversion=27.0.1', HTTP_USER_AGENT=self.user_agent)
self.assertIn(self.expected, response.content)
response = self.client.get(self.url + '?oldversion=4.0', HTTP_USER_AGENT=self.user_agent)
self.assertIn(self.expected, response.content)
response = self.client.get(self.url + '?oldversion=rv:10.0', HTTP_USER_AGENT=self.user_agent)
self.assertIn(self.expected, response.content)
response = self.client.get(self.url + '?oldversion=29.0', HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
response = self.client.get(self.url + '?oldversion=29.0.1', HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
response = self.client.get(self.url + '?oldversion=30.0', HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
response = self.client.get(self.url + '?oldversion=31.0', HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
# if there's no oldversion parameter, show no tour
response = self.client.get(self.url, HTTP_USER_AGENT=self.user_agent)
self.assertNotIn(self.expected, response.content)
class TestFirstrunRedirect(FxVersionRedirectsMixin, TestCase):
def setUp(self):
with self.activate('en-US'):
self.url = reverse('firefox.firstrun', args=['13.0'])
@override_settings(DEV=True)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='16.0')
def test_firstrun_tour(self):
"""
Hitting /firefox/29.0/firstrun/?f=30 with en-US locale should render
firefox/australis/firstrun-no-tour.html. Hitting en-US locale with
f=31 should render firefox/australis/firstrun-tour.html. Any other
f value or locale should render firstrun-tour.html.
"""
user_agent = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:29.0) '
'Gecko/20100101 Firefox/29.0')
expected = 'data-has-tour="True"'
self.url = reverse('firefox.firstrun', args=['29.0'])
# en-US with funnelcake id 30 should not give a tour
response = self.client.get(self.url + '?f=30', HTTP_USER_AGENT=user_agent)
self.assertNotIn(expected, response.content)
# en-US with funnelcake id 31 should give a tour
response = self.client.get(self.url + '?f=31', HTTP_USER_AGENT=user_agent)
self.assertIn(expected, response.content)
# en-US with improper funnelcake id should still give a tour
response = self.client.get(self.url + '?f=0', HTTP_USER_AGENT=user_agent)
self.assertIn(expected, response.content)
# en-US with no funnelcake id should still give a tour
response = self.client.get(self.url, HTTP_USER_AGENT=user_agent)
self.assertIn(expected, response.content)
with self.activate('de'):
self.url = reverse('firefox.firstrun', args=['29.0'])
# de with proper funnelcake id should still get a tour
response = self.client.get(self.url + '?f=30', HTTP_USER_AGENT=user_agent)
self.assertIn(expected, response.content)
# de with no funnelcake id should still get a tour
response = self.client.get(self.url, HTTP_USER_AGENT=user_agent)
self.assertIn(expected, response.content)
@patch.object(fx_views, 'firefox_details', firefox_details)
class TestReleaseNotesIndex(TestCase):
def test_relnotes_index(self):
with self.activate('en-US'):
response = self.client.get(reverse('firefox.releases.index'))
doc = pq(response.content)
eq_(len(doc('a[href="0.1.html"]')), 1)
eq_(len(doc('a[href="0.10.html"]')), 1)
eq_(len(doc('a[href="1.0.html"]')), 1)
eq_(len(doc('a[href="1.0.8.html"]')), 1)
eq_(len(doc('a[href="1.5.html"]')), 1)
eq_(len(doc('a[href="1.5.0.12.html"]')), 1)
eq_(len(doc('a[href="../2.0/releasenotes/"]')), 1)
eq_(len(doc('a[href="../2.0.0.20/releasenotes/"]')), 1)
eq_(len(doc('a[href="../3.6/releasenotes/"]')), 1)
eq_(len(doc('a[href="../3.6.28/releasenotes/"]')), 1)
eq_(len(doc('a[href="../17.0/releasenotes/"]')), 1)
eq_(len(doc('a[href="../17.0.11/releasenotes/"]')), 1)
eq_(len(doc('a[href="../24.0/releasenotes/"]')), 1)
eq_(len(doc('a[href="../24.1.0/releasenotes/"]')), 1)
eq_(len(doc('a[href="../24.1.1/releasenotes/"]')), 1)
eq_(len(doc('a[href="../25.0/releasenotes/"]')), 1)
eq_(len(doc('a[href="../25.0.1/releasenotes/"]')), 1)
@patch.object(fx_views, 'firefox_details', firefox_details)
@patch.object(fx_views, 'mobile_details', mobile_details)
class TestNotesRedirects(TestCase):
def _test(self, url_from, url_to):
with self.activate('en-US'):
url = '/en-US' + url_from
response = self.client.get(url)
eq_(response.status_code, 302)
eq_(response['Location'], 'http://testserver/en-US' + url_to)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='22.0')
def test_desktop_release_version(self):
self._test('/firefox/notes/',
'/firefox/22.0/releasenotes/')
self._test('/firefox/latest/releasenotes/',
'/firefox/22.0/releasenotes/')
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_DEVEL_VERSION='23.0b1')
def test_desktop_beta_version(self):
self._test('/firefox/beta/notes/',
'/firefox/23.0beta/releasenotes/')
@patch.dict(product_details.firefox_versions,
FIREFOX_AURORA='24.0a2')
def test_desktop_aurora_version(self):
self._test('/firefox/aurora/notes/',
'/firefox/24.0a2/auroranotes/')
@patch.dict(product_details.firefox_versions,
FIREFOX_ESR='24.2.0esr')
def test_desktop_esr_version(self):
self._test('/firefox/organizations/notes/',
'/firefox/24.2.0/releasenotes/')
@patch.dict(product_details.mobile_details,
version='22.0')
def test_mobile_release_version(self):
self._test('/mobile/notes/',
'/mobile/22.0/releasenotes/')
@patch.dict(product_details.mobile_details,
beta_version='23.0b1')
def test_mobile_beta_version(self):
self._test('/mobile/beta/notes/',
'/mobile/23.0beta/releasenotes/')
@patch.dict(product_details.mobile_details,
alpha_version='24.0a2')
def test_mobile_aurora_version(self):
self._test('/mobile/aurora/notes/',
'/mobile/24.0a2/auroranotes/')
@patch.object(fx_views, 'firefox_details', firefox_details)
class TestSysreqRedirect(TestCase):
def _test(self, url_from, url_to):
with self.activate('en-US'):
url = '/en-US' + url_from
response = self.client.get(url)
eq_(response.status_code, 302)
eq_(response['Location'], 'http://testserver/en-US' + url_to)
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_VERSION='22.0')
def test_desktop_release_version(self):
self._test('/firefox/system-requirements/',
'/firefox/22.0/system-requirements/')
@patch.dict(product_details.firefox_versions,
LATEST_FIREFOX_DEVEL_VERSION='23.0b1')
def test_desktop_beta_version(self):
self._test('/firefox/beta/system-requirements/',
'/firefox/23.0beta/system-requirements/')
@patch.dict(product_details.firefox_versions,
FIREFOX_AURORA='24.0a2')
def test_desktop_aurora_version(self):
self._test('/firefox/aurora/system-requirements/',
'/firefox/24.0a2/system-requirements/')
@patch.dict(product_details.firefox_versions,
FIREFOX_ESR='24.2.0esr')
def test_desktop_esr_version(self):
self._test('/firefox/organizations/system-requirements/',
'/firefox/24.0/system-requirements/')