[Freeipa-devel] [PATCH 0059] Make testcert automagically when needed by unit test

Tomas Babej tbabej at redhat.com
Mon May 27 14:07:48 UTC 2013


On 05/24/2013 02:02 PM, Petr Viktorin wrote:
> 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`).
>
Thank you for the comments.

Updated patch attached.

Tomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: freeipa-tbabej-0059-3-Make-testcert-automagically-when-needed-by-unit-test.patch
Type: text/x-patch
Size: 9554 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20130527/adff0c52/attachment.bin>


More information about the Freeipa-devel mailing list