def test_change_add_one_check_mode(self):
        open_url = OpenUrlProxy([
            OpenUrlCall('POST', 200).expect_content_predicate(
                validate_wsdl_call([
                    expect_authentication('foo', 'bar'),
                    expect_value([
                        lxmletree.QName('https://ns1.hosttech.eu/public/api',
                                        'getZone').text, 'sZoneName'
                    ], 'example.com', ('http://www.w3.org/2001/XMLSchema',
                                       'string')),
                ])).result_str(DEFAULT_ZONE_RESULT),
        ])
        with patch(
                'ansible_collections.felixfontein.hosttech_dns.plugins.module_utils.wsdl.open_url',
                open_url):
            with pytest.raises(AnsibleExitJson) as e:
                set_module_args({
                    'hosttech_username': '******',
                    'hosttech_password': '******',
                    'state': 'present',
                    'zone': 'example.com',
                    'record': 'example.com',
                    'type': 'CAA',
                    'ttl': 3600,
                    'value': [
                        'test',
                    ],
                    '_ansible_check_mode': True,
                    '_ansible_remote_tmp': '/tmp/tmp',
                    '_ansible_keep_remote_files': True,
                })
                hosttech_dns_record.main()

        print(e.value.args[0])
        assert e.value.args[0]['changed'] is True
    def test_change_modify_list_fail(self):
        open_url = OpenUrlProxy([
            OpenUrlCall('POST', 200).expect_content_predicate(
                validate_wsdl_call([
                    expect_authentication('foo', 'bar'),
                    expect_value([
                        lxmletree.QName('https://ns1.hosttech.eu/public/api',
                                        'getZone').text, 'sZoneName'
                    ], 'example.com', ('http://www.w3.org/2001/XMLSchema',
                                       'string')),
                ])).result_str(DEFAULT_ZONE_RESULT),
        ])
        with patch(
                'ansible_collections.felixfontein.hosttech_dns.plugins.module_utils.wsdl.open_url',
                open_url):
            with pytest.raises(AnsibleFailJson) as e:
                set_module_args({
                    'hosttech_username':
                    '******',
                    'hosttech_password':
                    '******',
                    'state':
                    'present',
                    'zone':
                    'example.com',
                    'record':
                    'example.com',
                    'type':
                    'NS',
                    'ttl':
                    10800,
                    'value': [
                        'ns1.hostserv.eu',
                        'ns4.hostserv.eu',
                    ],
                    '_ansible_remote_tmp':
                    '/tmp/tmp',
                    '_ansible_keep_remote_files':
                    True,
                })
                hosttech_dns_record.main()

        print(e.value.args[0])
        assert e.value.args[0]['failed'] is True
        assert e.value.args[0][
            'msg'] == "Record already exists with different value. Set 'overwrite' to replace it"
    def test_change_modify_list(self):
        del_entry = (130, 42, 'NS', '', 'ns3.hostserv.eu', 10800, None, None)
        update_entry = (131, 42, 'NS', '', 'ns4.hostserv.eu', 10800, None,
                        None)
        open_url = OpenUrlProxy([
            OpenUrlCall('POST', 200).expect_content_predicate(
                validate_wsdl_call([
                    expect_authentication('foo', 'bar'),
                    expect_value([
                        lxmletree.QName('https://ns1.hosttech.eu/public/api',
                                        'getZone').text, 'sZoneName'
                    ], 'example.com', ('http://www.w3.org/2001/XMLSchema',
                                       'string')),
                ])).result_str(DEFAULT_ZONE_RESULT),
            OpenUrlCall('POST', 200).expect_content_predicate(
                validate_wsdl_call([
                    expect_authentication('foo', 'bar'),
                    validate_del_request(del_entry),
                ])).result_str(create_del_result(True)),
            OpenUrlCall('POST', 200).expect_content_predicate(
                validate_wsdl_call([
                    expect_authentication('foo', 'bar'),
                    validate_update_request(update_entry),
                ])).result_str(create_update_result(update_entry)),
        ])
        with patch(
                'ansible_collections.felixfontein.hosttech_dns.plugins.module_utils.wsdl.open_url',
                open_url):
            with pytest.raises(AnsibleExitJson) as e:
                set_module_args({
                    'hosttech_username':
                    '******',
                    'hosttech_password':
                    '******',
                    'state':
                    'present',
                    'zone':
                    'example.com',
                    'record':
                    'example.com',
                    'type':
                    'NS',
                    'ttl':
                    10800,
                    'value': [
                        'ns1.hostserv.eu',
                        'ns4.hostserv.eu',
                    ],
                    'overwrite':
                    True,
                    '_ansible_diff':
                    True,
                    '_ansible_remote_tmp':
                    '/tmp/tmp',
                    '_ansible_keep_remote_files':
                    True,
                })
                hosttech_dns_record.main()

        print(e.value.args[0])
        assert e.value.args[0]['changed'] is True
        assert 'diff' in e.value.args[0]
        assert 'before' in e.value.args[0]['diff']
        assert 'after' in e.value.args[0]['diff']
        assert e.value.args[0]['diff']['before'] == {
            'record': 'example.com',
            'type': 'NS',
            'ttl': 10800,
            'value': ['ns1.hostserv.eu', 'ns2.hostserv.eu', 'ns3.hostserv.eu'],
        }
        assert e.value.args[0]['diff']['after'] == {
            'record': 'example.com',
            'type': 'NS',
            'ttl': 10800,
            'value': ['ns1.hostserv.eu', 'ns4.hostserv.eu'],
        }