Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: sitescripts/extensions/test/test_updateManifests.py

Issue 29358368: Issue 4540 - Add Platform Specific Branch Support to createNightlies.py (Closed)
Left Patch Set: Created Oct. 20, 2016, 7:51 a.m.
Right Patch Set: Created Oct. 26, 2016, 5:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/extensions/test/test_createNightlies.py ('k') | sitescripts/extensions/utils.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 """Tests for update manifest generation script.""" 16 """Tests for update manifest generation script."""
17 17
18 import os
18 import json 19 import json
19 import os 20 import pytest
20 import subprocess 21 import subprocess
21 import xml.etree.ElementTree as ET 22 import xml.etree.ElementTree as ET
22
23 import pytest
24 import py
25
26
27 @pytest.fixture()
28 def tests_dir():
29 """Directory that contains this tests and the data files it uses."""
30 return py.path.local(__file__).dirpath()
31
32
33 @pytest.fixture()
34 def oracle(tests_dir):
35 """Function that returns expected content of generated files."""
36 def expected_value_of(what):
37 return tests_dir.join('oracle').join(what).read().strip()
38 return expected_value_of
39
40
41 @pytest.fixture()
42 def data_dir(tests_dir):
43 return tests_dir.join('data')
44
45
46 @pytest.fixture()
47 def keys_dir(tmpdir, tests_dir):
48 keys_dir = tmpdir.mkdir('keys')
49 key_filename = 'adblockplussafari.pem'
50 tests_dir.join(key_filename).copy(keys_dir.join(key_filename))
51 return keys_dir
52
53
54 def call_hg(cwd, *params):
55 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd))
56
57
58 REPOS = {
59 'adblockplus': ('metadata.gecko', '2.7.3'),
60 'adblockplusie': ('README.txt', '1.33.7'),
61 'adblockpluschrome': ('metadata.safari', '1.12.3'),
62 'adblockplusandroid': ('AndroidManifest.xml', '1.3')
63 }
64
65
66 @pytest.fixture()
67 def hg_dir(tmpdir, data_dir):
68 """Directory that contains the repository mocks."""
69 hg_dir = tmpdir.mkdir('hg')
70
71 # Mock plugin repositories.
72 for repo, config in REPOS.items():
73 filename, tag = config
74 repo_dir = hg_dir.mkdir(repo)
75 call_hg(repo_dir, 'init')
76 data_dir.join(filename).copy(repo_dir.join(filename))
77 call_hg(repo_dir, 'add', filename)
78 call_hg(repo_dir, 'commit', '-m', '1')
79 call_hg(repo_dir, 'tag', tag)
80
81 # Mock the downloads repository.
82 downloads_list = data_dir.join('downloads.list').read().splitlines()
83 downloads_dir = hg_dir.mkdir('downloads')
84 call_hg(downloads_dir, 'init')
85 for item in downloads_list:
86 downloads_dir.join(item).write('')
87 call_hg(downloads_dir, 'add', *downloads_list)
88 call_hg(downloads_dir, 'commit', '-m', 'ok')
89
90 return hg_dir
91
92
93 @pytest.fixture()
94 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir):
95 """Sitescripts configuration."""
96 template = tests_dir.join('sitescripts.ini.template').read()
97 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir)
98 config_ini = tmpdir.join('sitescripts.ini')
99 config_ini.write(conf)
100 return config_ini
101 23
102 24
103 def rdf2data(rdf): 25 def rdf2data(rdf):
104 """Convert RDF to a more comparable data strcuture.""" 26 """Convert RDF to a more comparable data strcuture."""
105 # We need this to address the RDF item ordering discrepancies. 27 # We need this to address the RDF item ordering discrepancies.
106 def et2data(node): 28 def et2data(node):
107 return { 29 return {
108 'tag': node.tag, 30 'tag': node.tag,
109 'text': node.text, 31 'text': node.text,
110 'attrib': node.attrib, 32 'attrib': node.attrib,
111 'subs': sorted(et2data(sub) for sub in node) 33 'subs': sorted(et2data(sub) for sub in node)
112 } 34 }
113 return et2data(ET.fromstring(rdf)) 35 return et2data(ET.fromstring(rdf))
36
37
38 @pytest.fixture(scope='session')
39 def oracle(tests_dir):
40 """Function that returns expected content of generated files."""
41 def expected_value_of(what):
42 return tests_dir.join('oracle').join(what).read().strip()
43 return expected_value_of
114 44
115 45
116 def test_update_manifests(config_ini, hg_dir, tmpdir, oracle): 46 def test_update_manifests(config_ini, hg_dir, tmpdir, oracle):
117 env = dict(os.environ) 47 env = dict(os.environ)
118 env['SITESCRIPTS_CONFIG'] = str(config_ini) 48 env['SITESCRIPTS_CONFIG'] = str(config_ini)
119 cmd = ['python', '-m', 'sitescripts.extensions.bin.updateUpdateManifests'] 49 cmd = ['python', '-m', 'sitescripts.extensions.bin.updateUpdateManifests']
120 subprocess.check_call(cmd, env=env) 50 subprocess.check_call(cmd, env=env)
121 for filename in ['androidupdates.json', 'androidupdates.xml', 51 for filename in ['androidupdates.json', 'androidupdates.xml',
122 'ieupdate.json', 'update.rdf', 'updates.plist']: 52 'ieupdate.json', 'update.rdf', 'updates.plist']:
123 got = tmpdir.join(filename).read().strip() 53 got = tmpdir.join(filename).read().strip()
124 expect = oracle(filename) 54 expect = oracle(filename)
125 if filename.endswith('.json'): 55 if filename.endswith('.json'):
126 got = json.loads(got) 56 got = json.loads(got)
127 expect = json.loads(expect) 57 expect = json.loads(expect)
128 elif filename.endswith('.rdf'): 58 elif filename.endswith('.rdf'):
129 got = rdf2data(got) 59 got = rdf2data(got)
130 expect = rdf2data(expect) 60 expect = rdf2data(expect)
131 assert got == expect 61 assert got == expect
LEFTRIGHT

Powered by Google App Engine
This is Rietveld