| LEFT | RIGHT | 
|---|
| (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 os | 
| 19 import json | 19 import json | 
| 20 import pytest | 20 import pytest | 
| 21 import subprocess | 21 import subprocess | 
| 22 import xml.etree.ElementTree as ET |  | 
| 23 |  | 
| 24 |  | 
| 25 def rdf2data(rdf): |  | 
| 26     """Convert RDF to a more comparable data strcuture.""" |  | 
| 27     # We need this to address the RDF item ordering discrepancies. |  | 
| 28     def et2data(node): |  | 
| 29         return { |  | 
| 30             'tag': node.tag, |  | 
| 31             'text': node.text, |  | 
| 32             'attrib': node.attrib, |  | 
| 33             'subs': sorted(et2data(sub) for sub in node) |  | 
| 34         } |  | 
| 35     return et2data(ET.fromstring(rdf)) |  | 
| 36 | 22 | 
| 37 | 23 | 
| 38 @pytest.fixture(scope='session') | 24 @pytest.fixture(scope='session') | 
| 39 def oracle(tests_dir): | 25 def oracle(tests_dir): | 
| 40     """Function that returns expected content of generated files.""" | 26     """Function that returns expected content of generated files.""" | 
| 41     def expected_value_of(what): | 27     def expected_value_of(what): | 
| 42         return tests_dir.join('oracle').join(what).read().strip() | 28         return tests_dir.join('oracle').join(what).read().strip() | 
| 43     return expected_value_of | 29     return expected_value_of | 
| 44 | 30 | 
| 45 | 31 | 
| 46 def test_update_manifests(config_ini, hg_dir, tmpdir, oracle): | 32 def test_update_manifests(config_ini, hg_dir, tmpdir, oracle): | 
| 47     env = dict(os.environ) | 33     env = dict(os.environ) | 
| 48     env['SITESCRIPTS_CONFIG'] = str(config_ini) | 34     env['SITESCRIPTS_CONFIG'] = str(config_ini) | 
| 49     cmd = ['python', '-m', 'sitescripts.extensions.bin.updateUpdateManifests'] | 35     cmd = ['python', '-m', 'sitescripts.extensions.bin.updateUpdateManifests'] | 
| 50     subprocess.check_call(cmd, env=env) | 36     subprocess.check_call(cmd, env=env) | 
| 51     for filename in ['androidupdates.json', 'androidupdates.xml', | 37     for filename in ['androidupdates.json', 'androidupdates.xml', | 
| 52                      'ieupdate.json', 'update.rdf', 'updates.plist']: | 38                      'ieupdate.json', 'updates.json', 'updates.plist']: | 
| 53         got = tmpdir.join(filename).read().strip() | 39         got = tmpdir.join(filename).read().strip() | 
| 54         expect = oracle(filename) | 40         expect = oracle(filename) | 
| 55         if filename.endswith('.json'): | 41         if filename.endswith('.json'): | 
| 56             got = json.loads(got) | 42             got = json.loads(got) | 
| 57             expect = json.loads(expect) | 43             expect = json.loads(expect) | 
| 58         elif filename.endswith('.rdf'): |  | 
| 59             got = rdf2data(got) |  | 
| 60             expect = rdf2data(expect) |  | 
| 61         assert got == expect | 44         assert got == expect | 
| LEFT | RIGHT | 
|---|