예제 #1
0
def test_deployment_controller():

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    eb = flexmock()

    def configure(binder):
        binder.bind(txredisapi.Connection, redis)
        binder.bind(EventBus, eb)

    with inject_services(configure):
        controller = DeploymentController()

        with pytest.raises(DeploymentDoesNotExist):
            yield controller.get('foo')

        eb.should_receive('fire_event').with_args(
            'new-deployment',
            public_app=None,
            apps=[],
            name='foo',
            public_domain='foo.bar').once()
        eb.should_receive('fire_event').with_args(
            'new-deployment',
            public_app=None,
            apps=[],
            name='boo',
            public_domain='other.path').once()

        r = yield controller.create('foo', 'foo.bar')
        assert isinstance(r, Deployment)
        assert r.public_domain == 'foo.bar'
        assert r.name == 'foo'

        r = yield controller.get('foo')
        assert r.public_domain == 'foo.bar'
        assert r.name == 'foo'

        r = yield controller.create('boo', 'other.path')
        assert isinstance(r, Deployment)
        assert r.public_domain == 'other.path'
        assert r.name == 'boo'

        r = yield controller.list()

        assert isinstance(r, list)
        assert len(r) == 2
        for app in r:
            assert isinstance(app, Deployment)

        eb.should_receive('fire_event').with_args('remove-deployment',
                                                  name='foo').once()
        yield controller.remove('foo')

        with pytest.raises(DeploymentDoesNotExist):
            yield controller.get('foo')
예제 #2
0
def test_deployment_controller_publish_app():

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    eb = flexmock()

    def configure(binder):
        binder.bind(txredisapi.Connection, redis)
        binder.bind(EventBus, eb)

    with inject_services(configure):
        controller = DeploymentController()

        eb.should_receive('fire_event').times(3)
        yield controller.create('foo', None)

        r = yield controller.get('foo')
        assert r.public_app is None

        yield controller.publish_app('foo', 'bar')

        r = yield controller.get('foo')
        assert r.public_app == 'bar.foo'

        yield controller.unpublish_app('foo')

        r = yield controller.get('foo')
        assert r.public_app is None
예제 #3
0
def test_deployment_controller_publish_app():

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    eb = flexmock()

    def configure(binder):
        binder.bind(txredisapi.Connection, redis)
        binder.bind(EventBus, eb)

    with inject_services(configure):
        controller = DeploymentController()

        eb.should_receive('fire_event').times(3)
        yield controller.create('foo', None)

        r = yield controller.get('foo')
        assert r.public_app is None

        yield controller.publish_app('foo', 'bar')

        r = yield controller.get('foo')
        assert r.public_app == 'bar.foo'

        yield controller.unpublish_app('foo')

        r = yield controller.get('foo')
        assert r.public_app is None
예제 #4
0
def test_deployment_controller_new_app():

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    eb = flexmock()
    ac = flexmock()

    def configure(binder):
        binder.bind(txredisapi.Connection, redis)
        binder.bind(EventBus, eb)
        binder.bind(ApplicationController, ac)

    with inject_services(configure):
        controller = DeploymentController()

        eb.should_receive('fire_event').once()
        yield controller.create('foo', 'foo.bar')

        r = yield controller.get('foo')
        assert r.apps == []

        ac.should_receive('create').with_args('bar.foo', {'path': 'some/path'}, skip_validation=True).once()
        yield controller.new_app('foo', 'bar', {'path': 'some/path'}, skip_validation=True, skip_events=True)

        r = yield controller.get('foo')
        assert r.apps == ['bar.foo']

        yield controller.remove_app('foo', 'bar')

        r = yield controller.get('foo')
        assert r.apps == []
예제 #5
0
def test_deployment_controller():

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    eb = flexmock()

    def configure(binder):
        binder.bind(txredisapi.Connection, redis)
        binder.bind(EventBus, eb)

    with inject_services(configure):
        controller = DeploymentController()

        with pytest.raises(DeploymentDoesNotExist):
            yield controller.get('foo')

        eb.should_receive('fire_event').with_args('new-deployment', public_app=None, apps=[], name='foo', public_domain='foo.bar').once()
        eb.should_receive('fire_event').with_args('new-deployment', public_app=None, apps=[], name='boo', public_domain='other.path').once()

        r = yield controller.create('foo', 'foo.bar')
        assert isinstance(r, Deployment)
        assert r.public_domain == 'foo.bar'
        assert r.name == 'foo'

        r = yield controller.get('foo')
        assert r.public_domain == 'foo.bar'
        assert r.name == 'foo'

        r = yield controller.create('boo', 'other.path')
        assert isinstance(r, Deployment)
        assert r.public_domain == 'other.path'
        assert r.name == 'boo'

        r = yield controller.list()

        assert isinstance(r, list)
        assert len(r) == 2
        for app in r:
            assert isinstance(app, Deployment)

        eb.should_receive('fire_event').with_args('remove-deployment', name='foo').once()
        yield controller.remove('foo')

        with pytest.raises(DeploymentDoesNotExist):
            yield controller.get('foo')
예제 #6
0
def test_deployment_controller_new_app():

    redis = yield txredisapi.Connection(dbid=2)
    yield redis.flushdb()

    eb = flexmock()
    ac = flexmock()

    def configure(binder):
        binder.bind(txredisapi.Connection, redis)
        binder.bind(EventBus, eb)
        binder.bind(ApplicationController, ac)

    with inject_services(configure):
        controller = DeploymentController()

        eb.should_receive('fire_event').once()
        yield controller.create('foo', 'foo.bar')

        r = yield controller.get('foo')
        assert r.apps == []

        ac.should_receive('create').with_args('bar.foo', {
            'path': 'some/path'
        },
                                              skip_validation=True).once()
        yield controller.new_app('foo',
                                 'bar', {'path': 'some/path'},
                                 skip_validation=True,
                                 skip_events=True)

        r = yield controller.get('foo')
        assert r.apps == ['bar.foo']

        yield controller.remove_app('foo', 'bar')

        r = yield controller.get('foo')
        assert r.apps == []