def test_generate_token_exception(self):
        mock_requests = patch('globomap_api_client.auth.requests').start()

        mock_requests.post = MagicMock(side_effect=Exception())

        with self.assertRaises(exceptions.ApiError):
            Auth('http://localhost', 'test', '123')
Exemple #2
0
    def test_generate_token_unauthorized(self):
        mock_requests = patch('globomap_api_client.auth.Session').start()

        response_mock = MagicMock(return_value={'message': 'Error'})
        mock_requests.return_value.request.return_value = MagicMock(
            json=response_mock, status_code=401)

        with self.assertRaises(exceptions.Unauthorized):
            Auth('http://localhost', 'test', '123')
    def test_generate_token_error(self):
        mock_requests = patch('globomap_api_client.auth.requests').start()

        response_mock = MagicMock(return_value={'message': 'Error'})
        mock_requests.post.return_value = MagicMock(
            json=response_mock, status_code=500)

        with self.assertRaises(exceptions.ApiError):
            Auth('http://localhost', 'test', '123')
Exemple #4
0
    def test_generate_token(self):
        mock_requests = patch('globomap_api_client.auth.Session').start()
        token_data = {
            'token': 'token123',
            'expires_at': '2018-04-12T05:51:58.144271Z',
        }
        response_mock = MagicMock(return_value=token_data)
        mock_requests.return_value.request.return_value = MagicMock(
            json=response_mock, status_code=200)
        Auth('http://localhost', 'test', '123')

        data = {'username': '******', 'password': '******'}
        headers = {'Content-Type': 'application/json'}
        mock_requests.return_value.request.assert_called_once_with(
            'POST',
            'http://localhost/v2/auth/',
            data=json.dumps(data),
            headers=headers,
            verify=1)
import os
from globomap_api_client.auth import Auth
from globomap_api_client.collection import Collection
from globomap_api_client.edge import Edge
from globomap_api_client.graph import Graph
from globomap_api_client.query import Query

GMAP_API_PORT = os.getenv('GMAP_API_PORT', '7002')

auth_inst = Auth(api_url='http://localhost:{}'.format(GMAP_API_PORT),
                 username='******',
                 password='******')
coll = Collection(auth=auth_inst)
edge = Edge(auth=auth_inst)
graph = Graph(auth=auth_inst)
query = Query(auth=auth_inst)
coll.post({
    'name': 'vip',
    'alias': 'vip',
    'icon': 'icon',
})
coll.post({
    'name': 'vm',
    'alias': 'vm',
    'icon': 'icon',
})
coll.post({
    'name': 'network',
    'alias': 'network',
    'icon': 'icon',
})