def test_modify_resolver_object_fwd_name_servers_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture(
            'sslo_resolver_modify_fwd_name_servers_generated.json')
        set_module_args(
            dict(fwd_name_servers=[
                '10.1.20.1', '10.1.20.2', 'fd66:2735:1533:46c1:68c8:0:0:7110',
                'fd66:2735:1533:46c1:68c8:0:0:7111'
            ],
                 dump_json=True))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
            required_one_of=self.spec.required_one_of)
        mm = ModuleManager(module=module)

        exists = dict(
            code=200,
            contents=load_fixture('load_sslo_resolver_fwd_server.json'))
        # Override methods to force specific logic in the module to happen
        mm.client.get = Mock(side_effect=[exists, exists])

        results = mm.exec_module()

        assert results['changed'] is False
        assert results['json'] == expected
    def test_create_resolver_object_fwd_zones_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture(
            'sslo_resolver_create_fwd_zones_generated.json')
        set_module_args(
            dict(fwd_zones=[
                dict(zone='foobar', servers=['192.168.1.1', '192.168.1.2']),
                dict(zone='.',
                     servers=[
                         'fd66:2735:1533:46c1:68c8:0:0:7113', '8.8.8.8',
                         '8.8.4.4'
                     ])
            ],
                 dump_json=True))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
            required_one_of=self.spec.required_one_of)
        mm = ModuleManager(module=module)

        # Override methods to force specific logic in the module to happen
        mm.exists = Mock(return_value=False)

        results = mm.exec_module()

        assert results['changed'] is False
        assert results['json'] == expected
    def test_modify_resolver_object_fwd_zones(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = [{
            'zone': 'foobar',
            'nameServerIps': ['192.168.1.1', '192.168.1.2']
        }, {
            'zone':
            '.',
            'nameServerIps':
            ['fd66:2735:1533:46c1:68c8:0:0:7113', '8.8.8.8', '8.8.4.4']
        }]
        set_module_args(
            dict(fwd_zones=[
                dict(zone='foobar', servers=['192.168.1.1', '192.168.1.2']),
                dict(zone='.',
                     servers=[
                         'fd66:2735:1533:46c1:68c8:0:0:7113', '8.8.8.8',
                         '8.8.4.4'
                     ])
            ], ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
            required_one_of=self.spec.required_one_of)
        mm = ModuleManager(module=module)

        # Override methods to force specific logic in the module to happen
        exists = dict(code=200,
                      contents=load_fixture('load_sslo_resolver_zones.json'))
        done = dict(code=200,
                    contents=load_fixture(
                        'reply_sslo_resolver_modify_fwd_zones_done.json'))
        mm.client.post = Mock(return_value=dict(
            code=202,
            contents=load_fixture(
                'reply_sslo_resolver_modify_fwd_zones_start.json')))
        mm.client.get = Mock(side_effect=[exists, exists, done])

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['fwd_zones'] == expected
        assert mm.client.get.call_count == 3
        assert mm.client.post.call_count == 1
    def test_create_resolver_object_fwd_name_servers(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = [
            '10.1.20.1', '10.1.20.2', 'fd66:2735:1533:46c1:68c8:0:0:7110',
            'fd66:2735:1533:46c1:68c8:0:0:7111'
        ]
        set_module_args(
            dict(fwd_name_servers=[
                '10.1.20.1', '10.1.20.2', 'fd66:2735:1533:46c1:68c8:0:0:7110',
                'fd66:2735:1533:46c1:68c8:0:0:7111'
            ], ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
            required_one_of=self.spec.required_one_of)
        mm = ModuleManager(module=module)

        # Override methods to force specific logic in the module to happen
        mm.exists = Mock(return_value=False)
        mm.client.post = Mock(return_value=dict(
            code=202,
            contents=load_fixture(
                'reply_sslo_resolver_create_fwd_servers_start.json')))
        mm.client.get = Mock(return_value=dict(
            code=200,
            contents=load_fixture(
                'reply_sslo_resolver_create_fwd_servers_done.json')))

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['fwd_name_servers'] == expected
        assert results['ip_family'] == 'both'
        assert mm.client.get.call_count == 1
        assert mm.client.post.call_count == 1