Commit 12b3f447 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

Support tests in python2

textwrap.indent doesn't exist in python2.
parent 4b8e5c41
Pipeline #21471 passed with stage
......@@ -7,7 +7,6 @@
from slapcache import signature
from slapos.libnetworkcache import NetworkcacheClient
from optparse import Values
from textwrap import indent
import slapos.signature, time, difflib, tempfile, unittest, os
def _fake_call(self, *args, **kw):
self.last_call = (args, kw)
......@@ -104,8 +103,7 @@ upgrade = 2014-06-04
"""
SIGNATURE = """
-----BEGIN CERTIFICATE-----
SIGNATURE = """-----BEGIN CERTIFICATE-----
MIIB8DCCAVmgAwIBAgIJAPFf61p8y809MA0GCSqGSIb3DQEBBQUAMBAxDjAMBgNV
BAMMBUNPTVAtMCAXDTE0MDIxNzE2NDgxN1oYDzIxMTQwMTI0MTY0ODE3WjAQMQ4w
DAYDVQQDDAVDT01QLTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAsiqCyuv1
......@@ -176,7 +174,8 @@ class NetworkCacheTestCase(unittest.TestCase):
info, self.configuration_file_path = tempfile.mkstemp()
configuration_content = UPDATE_CFG_DATA + """
signature-certificate-list = %(certificate)s
""" % {'certificate': indent(SIGNATURE, ' ')}
""" % {'certificate': '\n'.join(' ' + l if l.strip() else '\n' for l in SIGNATURE.splitlines())}
print(configuration_content)
open(self.configuration_file_path, 'w').write(configuration_content)
shacache = signature.NetworkCache(self.configuration_file_path)
self.assertEqual(shacache.download_binary_cache_url, 'http://www.shacache.org/shacache')
......@@ -197,7 +196,7 @@ signature-certificate-list = %(certificate)s
info, self.configuration_file_path = tempfile.mkstemp()
configuration_content = UPDATE_CFG_WITH_UPLOAD_DATA + """
signature-certificate-list = %(certificate)s
""" % {'certificate': indent(SIGNATURE, ' ')}
""" % {'certificate': '\n'.join(' ' + l if l.strip() else '\n' for l in SIGNATURE.splitlines())}
open(self.configuration_file_path, 'w').write(configuration_content)
shacache = signature.NetworkCache(self.configuration_file_path)
self.assertEqual(shacache.download_binary_cache_url, 'http://www.shacache.org/shacache')
......@@ -255,11 +254,11 @@ upload-dir-url = https://www.shacache.org/shadir
shadir-cert-file = %(tempfile)s
shadir-key-file = %(tempfile)s
signature-certificate-list =
%(certificate)s
%(certificate)s
""" % {
'tempfile': _fake_signature_path,
'signature_private_key_file': signature_private_key_file,
'certificate': indent(open(signature_certificate_file, 'r').read(), ' ')
'certificate': ''.join(' ' + l if l.strip() else '\n' for l in open(signature_certificate_file, 'r').readlines())
}
open(self.configuration_file_path, 'w').write(configuration_content)
open(_fake_signature_path, 'w').write('# XXX ...')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment