def test_update_expired_cert(self, *args):
        set_module_args(dict(
            days_valid=60,
            provider=dict(
                server='localhost',
                password='******',
                user='******',
                transport='cli',
                server_port=22
            )
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            required_if=self.spec.required_if
        )

        mm = ModuleManager(module=module)
        mm.expired = Mock(return_value=True)
        mm.update_certificate = Mock(return_value=True)
        mm.restart_daemon = Mock(return_value=True)
        mm.copy_files_to_trusted = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['days_valid'] == 60
    def test_create_new_cert(self):
        set_module_args(dict(
            key_size=2048,
            cert_name='foo.crt',
            key_name='foo.key',
            days_valid=60,
            new_cert='yes',
            issuer=dict(
                country='US',
                state='WA',
                locality='Seattle',
                organization='F5',
                division='IT',
                common_name='foo.bar.local',
                email='*****@*****.**'
            ),
            provider=dict(
                server='localhost',
                password='******',
                user='******',
                transport='cli',
                server_port=22
            )
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            required_if=self.spec.required_if
        )

        mm = ModuleManager(module=module)
        mm.expired = Mock(return_value=True)
        mm.generate_cert_key = Mock(return_value=True)
        mm.restart_daemon = Mock(return_value=True)
        mm.configure_new_cert = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['days_valid'] == 60
        assert results['cert_name'] == 'foo.crt'
        assert results['key_name'] == 'foo.key'
        assert results['issuer'] == dict(
            country='US',
            state='WA',
            locality='Seattle',
            organization='F5',
            division='IT',
            common_name='foo.bar.local',
            email='*****@*****.**'
        )