Exemple #1
0
def test_post_tenant_forbidden_exception(requests_mock):
    post_data = {
        'fvTenFailFailant': {
            'attributes': {
                'descr': '',
                'dn': 'uni/tn-test',
                'status': 'modified,created'
            }
        }
    }
    requests_mock.post(
        f'https://{__BASE_URL}/api/aaaLogin.json',
        json={'imdata': [{
            'aaaLogin': {
                'attributes': {
                    'token': 'tokenxyz'
                }
            }
        }]})
    requests_mock.post(
        f'https://{__BASE_URL}/api/mo.json',
        json={'imdata': [{
            'error': {
                'attributes': {
                    'text': 'tokenxyz'
                }
            }
        }]},
        status_code=403)
    aci = ACI(apicIp=__BASE_URL, apicUser='******', apicPasword='unkown')
    aci.login()
    with pytest.raises(RequestException):
        aci.postJson(post_data)
Exemple #2
0
def test_post_tenant_bad_request(requests_mock):
    post_data = {
        'fvTenFailFailant': {
            'attributes': {
                'descr': '',
                'dn': 'uni/tn-test',
                'status': 'modified,created'
            }
        }
    }
    requests_mock.post(
        f'https://{__BASE_URL}/api/aaaLogin.json',
        json={'imdata': [{
            'aaaLogin': {
                'attributes': {
                    'token': 'tokenxyz'
                }
            }
        }]})
    requests_mock.post(
        f'https://{__BASE_URL}/api/mo.json',
        json={'imdata': [{
            'error': {
                'attributes': {
                    'text': 'tokenxyz'
                }
            }
        }]},
        status_code=400)
    aci = ACI(apicIp=__BASE_URL, apicUser='******', apicPasword='unkown')
    aci.login()
    resp = aci.postJson(post_data)
    assert resp.startswith('400: ')
Exemple #3
0
def test_post_tenant_ok(requests_mock):
    post_data = {
        'fvTenant': {
            'attributes': {
                'descr': '',
                'dn': 'uni/tn-test',
                'status': 'modified,created'
            }
        }
    }
    requests_mock.post(
        f'https://{__BASE_URL}/api/aaaLogin.json',
        json={'imdata': [{
            'aaaLogin': {
                'attributes': {
                    'token': 'tokenxyz'
                }
            }
        }]})
    requests_mock.post(f'https://{__BASE_URL}/api/mo.json',
                       json={'imdata': post_data})
    aci = ACI(apicIp=__BASE_URL, apicUser='******', apicPasword='unkown')
    aci.login()
    resp = aci.postJson(post_data)
    assert resp == 200