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

Delta Between Two Patch Sets: tests/test_packagerEdge.py

Issue 29345751: Issue 4028 - Add support for Edge extensions to buildtools (Closed)
Left Patch Set: Address comments on patch set 8 Created Oct. 11, 2016, 3:52 p.m.
Right Patch Set: Address Windows Store issues with blockmap and devbuild display name Created Oct. 14, 2016, 12:07 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/metadata.edge ('k') | tox.ini » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import ConfigParser 5 import ConfigParser
6 import json 6 import json
7 import os 7 import os
8 import shutil 8 import shutil
9 import xml.etree.ElementTree as ET 9 import xml.etree.ElementTree as ET
10 import zipfile 10 import zipfile
11 11
12 import pytest 12 import pytest
13 13
14 from buildtools import packager, packagerEdge 14 from buildtools import packager, packagerEdge
15 15
16 TEST_DIR = os.path.dirname(__file__) 16 TEST_DIR = os.path.dirname(__file__)
17 TEST_METADATA = os.path.join(TEST_DIR, 'metadata.edge') 17 TEST_METADATA = os.path.join(TEST_DIR, 'metadata.edge')
18 CHARS = b''.join(chr(i % 200 + 30) for i in range(500)) 18 CHARS = b''.join(chr(i % 200 + 30) for i in range(500))
19 MESSAGES_EN_US = json.dumps({ 19 MESSAGES_EN_US = json.dumps({
20 'name': 'Adblock Plus', 20 'name': {'message': 'Adblock Plus'},
21 'description': 'Adblock Plus is the most popular ad blocker ever, ' 21 'name_devbuild': {'message': 'devbuild-marker'},
22 'description': {
23 'message': 'Adblock Plus is the most popular ad blocker ever, '
22 'and also supports websites by not blocking ' 24 'and also supports websites by not blocking '
23 'unobstrusive ads by default (configurable).' 25 'unobstrusive ads by default (configurable).'
26 },
24 }) 27 })
25 28
26 29
27 @pytest.fixture 30 @pytest.fixture
28 def metadata(): 31 def metadata():
29 """Loaded metadata config.""" 32 """Loaded metadata config."""
30 conf_parser = ConfigParser.ConfigParser() 33 conf_parser = ConfigParser.ConfigParser()
31 conf_parser.read(TEST_METADATA) 34 conf_parser.read(TEST_METADATA)
32 return conf_parser 35 return conf_parser
33 36
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 'png': 'image/png', 123 'png': 'image/png',
121 'xml': 'application/xml' 124 'xml': 'application/xml'
122 } 125 }
123 assert ctm_dict['overrides'] == { 126 assert ctm_dict['overrides'] == {
124 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', 127 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml',
125 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' 128 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml'
126 } 129 }
127 130
128 131
129 def test_create_appx_manifest(metadata, files): 132 def test_create_appx_manifest(metadata, files):
130 manifest = packagerEdge.create_appx_manifest({'metadata': metadata}, files) 133 manifest = packagerEdge.create_appx_manifest(
134 {'metadata': metadata}, files, release_build=True,
135 )
131 with open(os.path.join(TEST_DIR, 'AppManifest.xml.expect')) as fp: 136 with open(os.path.join(TEST_DIR, 'AppManifest.xml.expect')) as fp:
132 manifest_expect = fp.read() 137 manifest_expect = fp.read()
133 assert manifest.strip() == manifest_expect.strip() 138 assert manifest.strip() == manifest_expect.strip()
134 139
135 140
136 def test_warn_about_inconsistent_id(mocker, metadata, files): 141 def test_create_devbuild_appx_manifest(metadata, files):
137 """Test AppxManifest creation when app_id doesn't match name and author.""" 142 manifest = packagerEdge.create_appx_manifest(
138 metadata.set('general', 'app_id', 'foo.bar') 143 {'metadata': metadata}, files, release_build=False,
139 mocked_stderr = mocker.patch('sys.stderr') 144 )
140 packagerEdge.create_appx_manifest({'metadata': metadata}, files) 145 assert 'devbuild-marker' in manifest
141 assert mocked_stderr.write.called
142 msg = mocked_stderr.write.call_args[0][0]
143 assert msg.startswith('WARNING')
144 146
145 147
146 def test_move_files_to_extension(): 148 def test_move_files_to_extension():
147 files = packager.Files(set(), set()) 149 files = packager.Files(set(), set())
148 files['foo.xml'] = CHARS 150 files['foo.xml'] = CHARS
149 files['foo/bar.xml'] = CHARS 151 files['foo/bar.xml'] = CHARS
150 files['Extension/foo.xml'] = CHARS 152 files['Extension/foo.xml'] = CHARS
151 packagerEdge.move_files_to_extension(files) 153 packagerEdge.move_files_to_extension(files)
152 assert set(files.keys()) == { 154 assert set(files.keys()) == {
153 'Extension/foo.xml', 155 'Extension/foo.xml',
154 'Extension/foo/bar.xml', 156 'Extension/foo/bar.xml',
155 'Extension/Extension/foo.xml' 157 'Extension/Extension/foo.xml'
156 } 158 }
157 159
158 160
159 def test_create_build(tmpdir, srcdir): 161 def test_create_build(tmpdir, srcdir):
160 out_file = str(tmpdir.join('abp.appx')) 162 out_file = str(tmpdir.join('abp.appx'))
161 packagerEdge.createBuild(str(srcdir), outFile=out_file) 163 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True)
162 appx = zipfile.ZipFile(out_file) 164 appx = zipfile.ZipFile(out_file)
163 165
164 names = set(appx.namelist()) 166 names = set(appx.namelist())
165 assert 'AppxManifest.xml' in names 167 assert 'AppxManifest.xml' in names
166 assert 'AppxBlockMap.xml' in names 168 assert 'AppxBlockMap.xml' in names
167 assert '[Content_Types].xml' in names 169 assert '[Content_Types].xml' in names
168 170
171 assert 'devbuild-marker' not in appx.read('AppxManifest.xml')
169 assert appx.read('Assets/logo_44.png') == '44' 172 assert appx.read('Assets/logo_44.png') == '44'
170 assert appx.read('Extension/icons/abp-44.png') == '44' 173 assert appx.read('Extension/icons/abp-44.png') == '44'
174
175
176 def test_create_devbuild(tmpdir, srcdir):
177 out_file = str(tmpdir.join('abp.appx'))
178 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False)
179 appx = zipfile.ZipFile(out_file)
180 assert 'devbuild-marker' in appx.read('AppxManifest.xml')
LEFTRIGHT

Powered by Google App Engine
This is Rietveld