示例#1
0
def test_sync_delete_connector(mock_get, mock_delete):
    """ it should delete connectors present on the API that are not in the list if strict mode is enabled """
    mock_get.return_value.ok = True
    connector = API_CONNECTORS[1]
    mock_get.return_value.json.return_value = [
        x['config']['name'] for x in API_CONNECTORS
    ]
    mock_delete.return_value.ok = True
    sync(url=URL,
         connectors=[LIST_CONNECTORS[0]],
         strict=True,
         wait_for_deployment=False,
         verbose=False)

    mock_get.assert_called_once_with('https://my-kafka-api.app.com/connectors')
    mock_delete.assert_called_with(
        'https://my-kafka-api.app.com/connectors/{}'.format(
            connector['config']['name']))
示例#2
0
def test_sync_create_connectors(mock_get, mock_post, mock_delete):
    """ it should create connectors from list """
    mock_get.return_value.ok = True
    mock_get.return_value.json.return_value = []
    mock_post.return_value.ok = True
    sync(url=URL,
         connectors=LIST_CONNECTORS,
         strict=False,
         wait_for_deployment=False,
         verbose=False)

    mock_get.assert_called_once_with('https://my-kafka-api.app.com/connectors')
    for connector in LIST_CONNECTORS:
        mock_post.assert_any_call('https://my-kafka-api.app.com/connectors',
                                  json={
                                      'config': connector['config'],
                                      'name': connector['config']['name']
                                  })
    mock_delete.assert_not_called()
示例#3
0
def test_parameters_validation():
    """ it should throw an error if no url is provided """
    try:
        sync(url=None, connectors=None)
    except RuntimeError as err:
        assert str(err) == '[-] Missing required parameter: "url"'
示例#4
0
def test_sync_null_connectors(mock_get):
    """ it should avoid calling API if no connectors are provided """

    sync(url=URL, connectors=[])
    sync(url=URL, connectors=None)
    mock_get.assert_not_called()
示例#5
0
from kafkaconnectsync import sync
import json

url = 'https://kafka-connect-api.my-app.io'
connectors = json.loads(open('connectors.json').read())

"""
 ...
 Deploy your app here...
 ...
"""

# Sync connectors
sync(url, connectors, strict=True, wait_for_deployment=True, verbose=True)