Exemplo n.º 1
0
def test_run(mock_sync, mock_ever, mock_azure):
    """
    Should call Synchronizer with proper arguments
    """
    conf = SyncRunner.load_config('./config/sampleConfig.json')
    # Create mocks
    azure = MagicMock()
    azure.setup = MagicMock()
    mock_azure.Azure.return_value = azure
    everbridge = MagicMock()
    mock_ever.Everbridge.return_value = everbridge
    sync = MagicMock()
    sync.run_with_map = MagicMock()
    mock_sync.Synchronizer.return_value = sync
    # Call SyncRuunner#run
    runner = SyncRunner('./config/sampleConfig.json')
    runner.run()
    # Test if each function is called properly
    mock_azure.Azure.assert_called_with(conf['clientId'],
                                  conf['clientSecret'],
                                  conf['adTenant'])
    mock_ever.Everbridge.assert_called_with(conf['everbridgeOrg'],
                                 conf['everbridgeUsername'],
                                 conf['everbridgePassword'])
    mock_sync.Synchronizer.assert_called_with(azure, everbridge)
    sync.run_with_map.assert_called_with(conf['adGroupId'], conf["adMemberId"], conf["parentGroup"])
def main():
    """
    Main Function
    """
    args = get_argparser().parse_args()
    if exists(args.configfile):
        runner = SyncRunner(args.configfile)
        runner.run()
    else:
        print('Config File Not Found: ' + args.configfile)
Exemplo n.º 3
0
def test_check_config():
    """
    Should not raise Exception
    """
    conf = {
        'clientId':'cid',
        'clientSecret':'secret',
        'everbridgeUsername':'******',
        'everbridgePassword':'******',
        'everbridgeOrg':'12345',
        'adTenant':'98765',
        'adGroupId':['group1', 'group2'],
        'logFileName':'test.log',
        'logLevel':'DEBUG'
    }
    try:
        SyncRunner.check_config(conf)
    # pylint: disable=broad-except
    except Exception:
        pytest.fail('SyncRunner.check_config raised an Exception')
Exemplo n.º 4
0
def test_load_config():
    """
    Should return config object
    """
    conf = SyncRunner.load_config('./config/sampleConfig.json')
    exp = {
        'clientId':'Azure AD Client ID',
        'clientSecret':'Azure AD Client Secret',
        'everbridgeUsername':'******',
        'everbridgePassword':'******',
        'everbridgeOrg':'EverBridge Org',
        'adTenant':'Azure AD Tenant',
        'parentGroup': 'Parent Group',
        'adMemberId':['Azure AD Member ID1', 'Azure AD Member ID2'],
        'adGroupId':['Azure AD Group ID1', 'Azure AD Group ID2'],
        'logFileName':'test.log',
        'logLevel':'DEBUG'
    }
    assert conf == exp
Exemplo n.º 5
0
def test_check_config_with_errors():
    """
    Should raise Exception when required param is missing
    """
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientSecret':'secret',
            'everbridgeUsername':'******',
            'everbridgePassword':'******',
            'everbridgeOrg':'12345',
            'adTenant':'98765',
            'adGroupId':['group1', 'group2']
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'everbridgeUsername':'******',
            'everbridgePassword':'******',
            'everbridgeOrg':'12345',
            'adTenant':'98765',
            'adGroupId':['group1', 'group2']
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'clientSecret':'secret',
            'everbridgePassword':'******',
            'everbridgeOrg':'12345',
            'adTenant':'98765',
            'adGroupId':['group1', 'group2']
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'clientSecret':'secret',
            'everbridgeUsername':'******',
            'everbridgeOrg':'12345',
            'adTenant':'98765',
            'adGroupId':['group1', 'group2']
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'clientSecret':'secret',
            'everbridgeUsername':'******',
            'everbridgePassword':'******',
            'adTenant':'98765',
            'adGroupId':['group1', 'group2']
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'clientSecret':'secret',
            'everbridgeUsername':'******',
            'everbridgePassword':'******',
            'everbridgeOrg':'12345',
            'adGroupId':['group1', 'group2']
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'clientSecret':'secret',
            'everbridgeUsername':'******',
            'everbridgePassword':'******',
            'everbridgeOrg':'12345',
            'adTenant':'98765'
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'clientSecret':'secret',
            'everbridgeUsername':'******',
            'everbridgePassword':'******',
            'everbridgeOrg':'12345',
            'adTenant':'98765',
            'adGroupId':'group1'
        })
    with pytest.raises(SyncRunnerException):
        SyncRunner.check_config({
            'clientId':'cid',
            'clientSecret':'secret',
            'everbridgeUsername':'******',
            'everbridgePassword':'******',
            'everbridgeOrg':'12345',
            'adTenant':'98765',
            'adGroupId':['group1', 'group2'],
            'logLevel':'XXXXX'
        })
Exemplo n.º 6
0
def test_load_config_with_nonexistent_file():
    """
    Should return config object
    """
    with pytest.raises(SyncRunnerException):
        SyncRunner.load_config('NOTEXIST.json')