Esempio n. 1
0
def test_list_applications(monkeypatch):
    context = Context({'region': 'caprica', 'vpc': 'myvpc'})

    security_group = MagicMock()
    security_group.tags = {
        'Manifest':
        yaml.dump({
            'application_name': 'myapp',
            'team_name': 'MyTeam',
            'exposed_ports': [123]
        })
    }

    context.get_applications = lambda: [Application('myapp', security_group)]
    context_constructor = lambda x, y: context

    monkeypatch.setattr('aws_minion.cli.Context', context_constructor)

    runner = CliRunner()

    with runner.isolated_filesystem():
        context.write_config('config.yaml')

        result = runner.invoke(
            cli, ['-p', 'default', '--config-file', 'config.yaml', 'app'],
            catch_exceptions=False)

    lines = result.output.splitlines()
    assert lines[1].split() == ['myapp', 'MyTeam', '[123]']
Esempio n. 2
0
def test_get_applications(monkeypatch):
    conn = MagicMock(name='conn')
    sg1 = MagicMock(name='invalid sg')
    sg2 = MagicMock(name='valid sg')
    sg2.name = 'app-myapp'
    sg2.tags = {'Manifest': 'a: b'}
    sg2.vpc_id = 'myvpc'
    sg3 = MagicMock(name='another invalid sg')
    sg3.name = 'app-myapp-db'
    sg3.vpc_id = 'myvpc'
    conn.get_all_security_groups.return_value = [sg1, sg2, sg3]
    monkeypatch.setattr('boto.ec2.connect_to_region', MagicMock(name='connect_to_region', return_value=conn))
    ctx = Context({'region': 'someregion', 'domain': 'apps.example.com', 'vpc': 'myvpc'})
    apps = ctx.get_applications()
    assert len(apps) == 1

    app = ctx.get_application('myapp')
    assert app == apps[0]
Esempio n. 3
0
def test_list_applications(monkeypatch):
    context = Context({'region': 'caprica', 'vpc': 'myvpc'})

    security_group = MagicMock()
    security_group.tags = {'Manifest': yaml.dump({'application_name': 'myapp', 'team_name': 'MyTeam', 'exposed_ports': [123]})}

    context.get_applications = lambda: [Application('myapp', security_group)]
    context_constructor = lambda x, y: context

    monkeypatch.setattr('aws_minion.cli.Context', context_constructor)

    runner = CliRunner()

    with runner.isolated_filesystem():
        context.write_config('config.yaml')

        result = runner.invoke(cli, ['-p', 'default', '--config-file', 'config.yaml', 'app'], catch_exceptions=False)

    lines = result.output.splitlines()
    assert lines[1].split() == ['myapp', 'MyTeam', '[123]']
Esempio n. 4
0
def test_get_applications(monkeypatch):
    conn = MagicMock(name='conn')
    sg1 = MagicMock(name='invalid sg')
    sg2 = MagicMock(name='valid sg')
    sg2.name = 'app-myapp'
    sg2.tags = {'Manifest': 'a: b'}
    sg2.vpc_id = 'myvpc'
    sg3 = MagicMock(name='another invalid sg')
    sg3.name = 'app-myapp-db'
    sg3.vpc_id = 'myvpc'
    conn.get_all_security_groups.return_value = [sg1, sg2, sg3]
    monkeypatch.setattr('boto.ec2.connect_to_region',
                        MagicMock(name='connect_to_region', return_value=conn))
    ctx = Context({
        'region': 'someregion',
        'domain': 'apps.example.com',
        'vpc': 'myvpc'
    })
    apps = ctx.get_applications()
    assert len(apps) == 1

    app = ctx.get_application('myapp')
    assert app == apps[0]