Esempio n. 1
0
def test_module_args(mock_module,
                     mock_route_check):
    """
    prefix_check - test module arguments
    """
    prefix_check.main()
    mock_module.assert_called_with(
        argument_spec={
          'prefix': {'required': True, 'type': 'str'},
          'timeout': {'type': 'int', 'default': 5},
        })
def test_module_args(mock_module, mock_route_check):
    """
    prefix_check - test module arguments
    """
    prefix_check.main()
    mock_module.assert_called_with(
        argument_spec={
            'prefix': {
                'required': True,
                'type': 'str'
            },
            'timeout': {
                'type': 'int',
                'default': 5
            },
        })
def test_main_exit_functionality_failure(mock_module, mock_loop_route_check):
    """
    prefix_check - test_main_exit_functionality - failure
    """
    instance = mock_module.return_value

    # What happens when the check_if_route_exists returns False
    # that is route is not found
    mock_loop_route_check.return_value = False

    prefix_check.main()

    # AnsibleModule.exit_json should be activated
    assert_equals(instance.exit_json.call_count, 0)

    # AnsibleModule.fail_json should be called
    instance.fail_json.assert_called_with(
        msg='Route not Found. Check Routing Configuration')
Esempio n. 4
0
def test_main_exit_functionality_failure(mock_module,
                     mock_loop_route_check):
    """
    prefix_check - test_main_exit_functionality - failure
    """
    instance = mock_module.return_value

    # What happens when the check_if_route_exists returns False
    # that is route is not found
    mock_loop_route_check.return_value = False

    prefix_check.main()

    # AnsibleModule.exit_json should be activated
    assert_equals(instance.exit_json.call_count, 0)

    # AnsibleModule.fail_json should be called
    instance.fail_json.assert_called_with(
        msg='Route not Found. Check Routing Configuration')
def test_main_exit_functionality_success(mock_module, mock_route_check):
    """
    prefix_check - test_main_exit_functionality - success
    """

    # This creates a instance of the AnsibleModule mock.
    instance = mock_module.return_value

    # What happens the route is found. Check that correct
    # exit function is called
    mock_route_check.return_value = True

    prefix_check.main()

    # AnsibleModule.exit_json should be called
    # "changed" var should be false
    instance.exit_json.assert_called_with(msg='Route Found', changed=False)

    # AnsibleModule.fail_json should not be called
    assert_equals(instance.fail_json.call_count, 0)
Esempio n. 6
0
def test_main_exit_functionality_success(mock_module,
                     mock_route_check):
    """
    prefix_check - test_main_exit_functionality - success
    """

    # This creates a instance of the AnsibleModule mock.
    instance = mock_module.return_value

    # What happens the route is found. Check that correct
    # exit function is called
    mock_route_check.return_value = True

    prefix_check.main()

    # AnsibleModule.exit_json should be called
    # "changed" var should be false
    instance.exit_json.assert_called_with(
            msg='Route Found', changed=False)

    # AnsibleModule.fail_json should not be called
    assert_equals(instance.fail_json.call_count, 0)