Esempio n. 1
0
def test_authentication_errors():
    """Check if full call with authentication works."""
    with pytest.raises(AsgardAuthenticationError):
        asgard = Asgard(URL)
        asgard.instance.show(instance_id='i21bcfec8')

    with pytest.raises(AsgardAuthenticationError):
        asgard = Asgard(URL, username='******')
        asgard.instance.show(instance_id='i21bcfec8')
Esempio n. 2
0
def test_builtin_errors():
    """Check that builtin errors trigger with bad formats."""
    with pytest.raises(TypeError):
        asgard = Asgard(URL,  # pylint: disable=E1123
                        username=USERNAME,
                        password=ENC_PASSWD,
                        data={'bad': 'param'})
        asgard.instance.show(instance_id='i21bcfec8')

    with pytest.raises(AttributeError):
        asgard = Asgard(URL, username=USERNAME, password=ENC_PASSWD)
        asgard.list()
Esempio n. 3
0
def test_dir():
    """Test Asgard.__dir__ contains all attributes and dynamic endpoints."""
    asgard = Asgard('sdkfj')
    logging.debug('dir:\n%s', pformat(dir(asgard)))

    for word in [
            'api_version', 'asg', 'data', 'elb', 'headers', 'instance',
            'mapping_table', 'username', 'url'
    ]:
        assert word in dir(asgard)
Esempio n. 4
0
def test_url_formatter():
    """Check the URL formatter when combining the base URL with endpoint."""
    test_asgard = Asgard('http://test.com', ec2_region='test_region')

    test_url = test_asgard.format_url(  # pylint: disable=W0212
        '/region/list.json', {'test': 'this'})
    logging.debug(test_url)

    assert test_url == 'http://test.com/test_region/region/list.json'

    test_url = test_asgard.format_url(  # pylint: disable=W0212
        MAPPING_TABLE['application']['list']['instances']['path'], {'app_id':
                                                                    'THIS'})

    assert test_url == 'http://test.com/test_region/instance/list/THIS.json'

    with pytest.raises(KeyError):
        test_url = test_asgard.format_url(  # pylint: disable=W0212
            MAPPING_TABLE['application']['list']['instances']['path'],
            {'something': 'ELSE'})
Esempio n. 5
0
def test_url_formatter():
    """Check the URL formatter when combining the base URL with endpoint."""
    test_asgard = Asgard('http://test.com', ec2_region='test_region')

    test_url = test_asgard.format_url(  # pylint: disable=W0212
        '/region/list.json', {'test': 'this'})
    logging.debug(test_url)

    assert test_url == 'http://test.com/test_region/region/list.json'

    test_url = test_asgard.format_url(  # pylint: disable=W0212
        MAPPING_TABLE['application']['list']['instances']['path'],
        {'app_id': 'THIS'})

    assert test_url == 'http://test.com/test_region/instance/list/THIS.json'

    with pytest.raises(KeyError):
        test_url = test_asgard.format_url(  # pylint: disable=W0212
            MAPPING_TABLE['application']['list']['instances']['path'],
            {'something': 'ELSE'})
Esempio n. 6
0
def test_builtin_errors():
    """Check that builtin errors trigger with bad formats."""
    with pytest.raises(TypeError):
        asgard = Asgard(
            URL,  # pylint: disable=E1123
            username=USERNAME,
            password=ENC_PASSWD,
            data={'bad': 'param'})
        asgard.instance.show(instance_id='i21bcfec8')

    with pytest.raises(AttributeError):
        asgard = Asgard(URL, username=USERNAME, password=ENC_PASSWD)
        asgard.list()
Esempio n. 7
0
def test_success():
    """Make sure that basic good call works."""
    asgard = Asgard(URL, username=USERNAME, password=ENC_PASSWD)
    response = asgard.regions.list()
    assert 'us-east-1' in [region['code'] for region in response]
Esempio n. 8
0
def test_asgard_error():
    """Make sure AsgardError triggers appropriately."""
    with pytest.raises(AsgardError):
        asgard = Asgard(URL, username=USERNAME, password=ENC_PASSWD)
        asgard.instance.show(instance_id='sjdlkjf')
Esempio n. 9
0
from pprint import pformat

import pytest
from pyasgard.endpoints import MAPPING_TABLE
from pyasgard.exceptions import (AsgardAuthenticationError, AsgardError,
                                 AsgardReturnedError)
from pyasgard.pyasgard import Asgard

try:
    from config import URL, ENC_PASSWD, USERNAME  # pylint: disable=C0411
except ImportError:
    ENC_PASSWD = 'dGVzdHBhc3N3ZA=='
    URL = 'http://asgard.demo.com'
    USERNAME = '******'

ASGARD = Asgard(URL, username=USERNAME, password=ENC_PASSWD)


def test_dir():
    """Test Asgard.__dir__ contains all attributes and dynamic endpoints."""
    asgard = Asgard('sdkfj')
    logging.debug('dir:\n%s', pformat(dir(asgard)))

    for word in [
            'api_version', 'asg', 'data', 'elb', 'headers', 'instance',
            'mapping_table', 'username', 'url'
    ]:
        assert word in dir(asgard)


def test_url_formatter():