예제 #1
0
def test_test_module(mocker):
    """Unit test
    Given
    - test module command
    - command args
    - command raw response
    When
    (a)
        - mock the parse_date_range.
        - mock the Client's send_request.
    (b) - calling the test module when using OAuth 2.0 authorization.
    Then
    (a)
        - run the test module command using the Client
        Validate the content of the HumanReadable.
    (b)
        Validate that an error is returned, indicating that the `Test` button can't be used when using OAuth 2.0.
    """
    mocker.patch('ServiceNowv2.parse_date_range', return_value=("2019-02-23 08:14:21", 'never mind'))
    client = Client('server_url', 'sc_server_url', 'username', 'password', 'verify', 'fetch_time',
                    'sysparm_query', sysparm_limit=10, timestamp_field='opened_at',
                    ticket_type='incident', get_attachments=False, incident_name='description')
    mocker.patch.object(client, 'send_request', return_value=RESPONSE_FETCH)
    result = module(client)
    assert result[0] == 'ok'

    client = Client('server_url', 'sc_server_url', 'username', 'password', 'verify', 'fetch_time',
                    'sysparm_query', sysparm_limit=10, timestamp_field='opened_at', ticket_type='incident',
                    get_attachments=False, incident_name='description', oauth_params=OAUTH_PARAMS)

    try:
        module(client)
    except Exception as e:
        assert 'Test button cannot be used when using OAuth 2.0' in e.args[0]
예제 #2
0
def test_test_module(mocker):
    """Unit test
    Given
    - test module command
    - command args
    - command raw response
    When
    - mock the parse_date_range.
    - mock the Client's send_request.
    Then
    - run the test module command using the Client
    Validate the content of the HumanReadable.
    """
    mocker.patch('ServiceNowv2.parse_date_range',
                 return_value=("2019-02-23 08:14:21", 'never mind'))
    client = Client('server_url',
                    'sc_server_url',
                    'username',
                    'password',
                    'verify',
                    'fetch_time',
                    'sysparm_query',
                    sysparm_limit=10,
                    timestamp_field='opened_at',
                    ticket_type='incident',
                    get_attachments=False,
                    incident_name='description')
    mocker.patch.object(client, 'send_request', return_value=RESPONSE_FETCH)
    result = module(client)
    assert result[0] == 'ok'