|
12 | 12 | import string
|
13 | 13 | import subprocess
|
14 | 14 | import sys
|
| 15 | +import time |
15 | 16 | import unittest
|
16 | 17 | import yaml
|
17 | 18 | import zipfile
|
@@ -1369,15 +1370,66 @@ def test_get_apk_icon_when_src_is_none(self):
|
1369 | 1370 | def test_strip_and_copy_image(self):
|
1370 | 1371 | in_file = basedir / 'metadata/info.guardianproject.urzip/en-US/images/icon.png'
|
1371 | 1372 | out_file = os.path.join(self.testdir, 'icon.png')
|
1372 |
| - fdroidserver.update._strip_and_copy_image(in_file, out_file) |
| 1373 | + with self.assertLogs(level=logging.DEBUG): |
| 1374 | + fdroidserver.update._strip_and_copy_image(in_file, out_file) |
1373 | 1375 | self.assertTrue(os.path.exists(out_file))
|
1374 | 1376 |
|
1375 | 1377 | def test_strip_and_copy_image_bad_filename(self):
|
1376 | 1378 | in_file = basedir / 'corrupt-featureGraphic.png'
|
1377 | 1379 | out_file = os.path.join(self.testdir, 'corrupt-featureGraphic.png')
|
1378 |
| - fdroidserver.update._strip_and_copy_image(in_file, out_file) |
| 1380 | + with self.assertLogs(level=logging.DEBUG): |
| 1381 | + fdroidserver.update._strip_and_copy_image(in_file, out_file) |
1379 | 1382 | self.assertFalse(os.path.exists(out_file))
|
1380 | 1383 |
|
| 1384 | + def test_strip_and_copy_image_unchanged(self): |
| 1385 | + in_file = basedir / 'metadata/info.guardianproject.urzip/en-US/images/icon.png' |
| 1386 | + out_file = os.path.join(self.testdir, 'icon.png') |
| 1387 | + shutil.copy2(in_file, out_file) |
| 1388 | + ctime = os.path.getctime(out_file) |
| 1389 | + delta = 0.01 |
| 1390 | + time.sleep(delta) # ensure reliable failure if file isn't preserved |
| 1391 | + with self.assertLogs(level=logging.DEBUG): # suppress log output |
| 1392 | + fdroidserver.update._strip_and_copy_image(in_file, out_file) |
| 1393 | + self.assertAlmostEqual(ctime, os.path.getctime(out_file), delta=delta) |
| 1394 | + |
| 1395 | + def test_strip_and_copy_image_in_file_ctime_changed(self): |
| 1396 | + out_file = os.path.join(self.testdir, 'icon.png') |
| 1397 | + with open(out_file, 'w') as fp: |
| 1398 | + fp.write('to be replaced') |
| 1399 | + size = os.path.getsize(out_file) |
| 1400 | + delta = 0.01 |
| 1401 | + time.sleep(delta) # ensure reliable failure when testing ctime |
| 1402 | + src_file = basedir / 'metadata/info.guardianproject.urzip/en-US/images/icon.png' |
| 1403 | + in_file = os.path.join(self.testdir, 'in-icon.png') |
| 1404 | + shutil.copy(src_file, in_file) |
| 1405 | + time.sleep(delta) # ensure reliable failure when testing ctime |
| 1406 | + with self.assertLogs(level=logging.DEBUG): # suppress log output |
| 1407 | + fdroidserver.update._strip_and_copy_image(in_file, out_file) |
| 1408 | + self.assertNotEqual(size, os.path.getsize(out_file)) |
| 1409 | + self.assertNotAlmostEqual( |
| 1410 | + os.path.getctime(in_file), os.path.getctime(out_file), delta=delta |
| 1411 | + ) |
| 1412 | + # _strip_and_copy_image syncs mtime from in_file to out_file |
| 1413 | + self.assertAlmostEqual( |
| 1414 | + os.path.getmtime(in_file), os.path.getmtime(out_file), delta=delta |
| 1415 | + ) |
| 1416 | + |
| 1417 | + def test_strip_and_copy_image_in_file_mtime_changed(self): |
| 1418 | + in_file = basedir / 'metadata/info.guardianproject.urzip/en-US/images/icon.png' |
| 1419 | + out_file = os.path.join(self.testdir, 'icon.png') |
| 1420 | + shutil.copy(in_file, out_file) |
| 1421 | + os.utime(out_file, (12345, 12345)) # set atime/mtime to something old |
| 1422 | + with self.assertLogs(level=logging.DEBUG): # suppress log output |
| 1423 | + fdroidserver.update._strip_and_copy_image(in_file, out_file) |
| 1424 | + delta = 0.01 |
| 1425 | + self.assertNotAlmostEqual( |
| 1426 | + os.path.getctime(in_file), os.path.getctime(out_file), delta=delta |
| 1427 | + ) |
| 1428 | + # _strip_and_copy_image syncs mtime from in_file to out_file |
| 1429 | + self.assertAlmostEqual( |
| 1430 | + os.path.getmtime(in_file), os.path.getmtime(out_file), delta=delta |
| 1431 | + ) |
| 1432 | + |
1381 | 1433 | def test_create_metadata_from_template_empty_keys(self):
|
1382 | 1434 | apk = {'packageName': 'rocks.janicerand'}
|
1383 | 1435 | with mkdtemp() as tmpdir, TmpCwd(tmpdir):
|
|
0 commit comments