Exemplo n.º 1
0
def test_get_many_monitors(mocker):
    mock_response = {
        'results': (Monitor(id='abc', name='test', type='assets'),
                    Monitor(id='bde', name='test2', type='assets')),
        'totalResults':
        2
    }

    expected_response = (Monitor(id='abc', name='test', type='assets'),
                         Monitor(id='bde', name='test2', type='assets'))

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'current',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current, '_get', return_value=mock_response)

    # run test
    GsMonitorsApi.get_monitors()
    GsSession.current._get.assert_called_with('/monitors?limit=100',
                                              cls=Monitor)
    GsMonitorsApi.get_monitors(monitor_id='abc')
    GsSession.current._get.assert_called_with('/monitors?id=abc&limit=100',
                                              cls=Monitor)
    GsMonitorsApi.get_monitors(owner_id='aedf')
    GsSession.current._get.assert_called_with(
        '/monitors?ownerId=aedf&limit=100', cls=Monitor)
    GsMonitorsApi.get_monitors(name='name')
    GsSession.current._get.assert_called_with('/monitors?name=name&limit=100',
                                              cls=Monitor)
    GsMonitorsApi.get_monitors(folder_name='folderName')
    GsSession.current._get.assert_called_with(
        '/monitors?folderName=folderName&limit=100', cls=Monitor)
    GsMonitorsApi.get_monitors(monitor_type='type')
    GsSession.current._get.assert_called_with('/monitors?type=type&limit=100',
                                              cls=Monitor)
    response = GsMonitorsApi.get_monitors(name='name', owner_id='ia', limit=10)
    GsSession.current._get.assert_called_with(
        '/monitors?ownerId=ia&name=name&limit=10', cls=Monitor)
    assert response == expected_response
Exemplo n.º 2
0
def test_get_monitor(mocker):
    monitor_id = 'abc'
    mock_response = Monitor(id=monitor_id, name='test', type='assets')

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'current',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current, '_get', return_value=mock_response)

    # run test
    response = GsMonitorsApi.get_monitor(monitor_id)
    GsSession.current._get.assert_called_with(
        '/monitors/{id}'.format(id=monitor_id), cls=Monitor)
    assert response == mock_response
Exemplo n.º 3
0
def test_create_monitor(mocker):
    monitor_id = 'abc'

    monitor = Monitor(id=monitor_id, name='test', type='assets')

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'current',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current, '_post', return_value=monitor)

    # run test
    response = GsMonitorsApi.create_monitor(monitor)
    GsSession.current._post.assert_called_with(
        '/monitors',
        monitor,
        request_headers={'Content-Type': 'application/json;charset=utf-8'},
        cls=Monitor)
    assert response == monitor