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

Unified Diff: sitescripts/extensions/test/test_updateManifests.py

Issue 29354748: Fixes 4464 - Restore get_min_sdk_version() function from sitescripts.extensions.android module that… (Closed) Base URL: https://hg.adblockplus.org/sitescripts
Patch Set: Add a test Created Sept. 23, 2016, 4:26 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/extensions/test/sitescripts.ini.template ('k') | tox.ini » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/extensions/test/test_updateManifests.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/sitescripts/extensions/test/test_updateManifests.py
@@ -0,0 +1,120 @@
+# This file is part of the Adblock Plus web scripts,
+# Copyright (C) 2006-2016 Eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+"""Tests for update manifest generation script."""
+
+import json
+import os
+import subprocess
+
+import pytest
+import py
+
+
+@pytest.fixture()
+def tests_dir():
+ """Directory that contains this tests and the data files it uses."""
+ return py.path.local(__file__).dirpath()
+
+
+@pytest.fixture()
+def oracle(tests_dir):
+ """Function that returns expected content of generated files."""
+ def expected_value_of(what):
+ return tests_dir.join('oracle').join(what).read()
+ return expected_value_of
+
+
+@pytest.fixture()
+def cache_dir(tests_dir):
+ cache_dir = tests_dir.join('.test-cache')
+ cache_dir.ensure_dir()
+ return cache_dir
+
+
+@pytest.fixture()
+def root_dir(tmpdir):
Sebastian Noack 2016/09/23 17:29:25 Do we really need a fixture with that one-liner -
Vasily Kuznetsov 2016/09/27 09:50:24 Done.
+ root_dir = tmpdir.mkdir('root')
+ return root_dir
+
+
+@pytest.fixture()
+def keys_dir(root_dir, tests_dir):
+ keys_dir = root_dir.mkdir('keys')
+ key_filename = 'adblockplussafari.pem'
+ tests_dir.join(key_filename).copy(keys_dir.join(key_filename))
+ return keys_dir
+
+
+def call_hg(cwd, *params):
+ return subprocess.check_call(['hg'] + list(params), cwd=str(cwd))
+
+
+@pytest.fixture()
+def downloads_repo(tests_dir, hg_dir):
+ """Mock of downloads repo with empty files."""
+ downloads_list = tests_dir.join('downloads.list').read().splitlines()
+ downloads_dir = hg_dir.mkdir('downloads')
+ call_hg(downloads_dir, 'init')
Sebastian Noack 2016/09/23 17:29:25 I wonder whether this is worth a helper function.
Vasily Kuznetsov 2016/09/27 09:50:24 So I ended up with quite a few calls to `call_hg`
+ for item in downloads_list:
+ downloads_dir.join(item).write('')
+ call_hg(downloads_dir, 'add', *downloads_list)
+ call_hg(downloads_dir, 'commit', '-m', 'ok')
+
+
+@pytest.fixture()
+def hg_dir(root_dir, cache_dir):
+ """Directory that contains the repositories.
+
+ The script expects repositories of the plugins and a downloads
+ repository to be there.
+ """
+ hg_dir = root_dir.mkdir('hg')
+ for repo in ['adblockplus', 'adblockplusie',
+ 'adblockpluschrome', 'adblockplusandroid']:
+ cached = cache_dir.join(repo)
+ if cached.exists():
+ cached.copy(hg_dir.join(repo))
+ else:
+ url = 'https://hg.adblockplus.org/{}/'.format(repo)
+ call_hg(hg_dir, 'clone', url)
+ hg_dir.join(repo).copy(cached)
+ return hg_dir
+
+
+@pytest.fixture()
+def config_ini(tests_dir, root_dir, hg_dir, keys_dir, downloads_repo):
+ """Sitescripts configuration."""
+ template = tests_dir.join('sitescripts.ini.template').read()
+ conf = template.format(hg_dir=hg_dir, out_dir=root_dir, keys_dir=keys_dir)
+ config_ini = root_dir.join('sitescripts.ini')
+ config_ini.write(conf)
+ return config_ini
+
+
+def test_update_manifests(config_ini, hg_dir, root_dir, oracle):
+ env = dict(os.environ)
+ env['SITESCRIPTS_CONFIG'] = str(config_ini)
+ cmd = ['python', '-m',
+ 'sitescripts.extensions.bin.updateUpdateManifests']
+ subprocess.check_call(cmd, env=env)
+ for filename in ['androidupdates.json', 'androidupdates.xml',
+ 'ieupdate.json', 'update.rdf', 'updates.plist']:
+ got = root_dir.join(filename).read()
+ expect = oracle(filename)
+ if filename.endswith('.json'):
+ got = json.loads(got)
+ expect = json.loads(expect)
+ assert got == expect
« no previous file with comments | « sitescripts/extensions/test/sitescripts.ini.template ('k') | tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld