[Freeipa-devel] [PATCH 0059] Make testcert automagically when needed by unit test
Petr Viktorin
pviktori at redhat.com
Fri May 24 12:02:18 UTC 2013
On 05/24/2013 09:57 AM, Tomas Babej wrote:
> On 05/23/2013 07:17 PM, Tomas Babej wrote:
>> Hi,
>>
>> With this patch, there's no need to run make-testcert separately
>> before running make-test. Unit test framework will check whether
>> service.crt file exists, and if not, will generate one if needed.
>>
>> New location of service.crt file is in ~/.ipa directory.
>>
>> Part of https://fedorahosted.org/freeipa/ticket/3621
>>
>> Tomas
Thanks, it works well.
However it would be nice to not repeat this code in every test that
needs the cert:
+servercert = ''
+
+# Create the testing server cert if it does not already exist
+# Returns True if successful, error message if not
+if not os.path.exists(testcert.CERTPATH):
+ servercert_ret = testcert.main()
+
+if os.path.exists(testcert.CERTPATH):
+ fd = open(testcert.CERTPATH, 'r')
+ servercert = fd.readlines()
+ servercert = ''.join(servercert)
+ servercert = x509.strip_header(servercert)
+ fd.close()
+
+
Please put this in testcert.py and just call something like `servercert
= testcert.get_testcert()`.
class test_host(Declarative):
+ def setUp(self):
+ super(Declarative, self).setUp()
+ if servercert == '':
+ raise nose.SkipTest('Testcert generation problem: %s' %
+ servercert_ret)
+
Do we really want to skip the test here? IMO if we cannot generate the
cert, we should fail (`assert servercert`).
--
Petr³
More information about the Freeipa-devel
mailing list