Exemple #1
0
def test_app_controller():

    def timeout():
        print('Can not connect to redis!')
        reactor.stop()

    redis = yield txtimeout(txredisapi.Connection(dbid=2), 2, timeout)
    yield redis.flushdb()


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

    with inject_services(configure):
        controller = ApplicationController()

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

        r = yield controller.create('foo', {'path': 'some/path'}, skip_validation=True)
        assert isinstance(r, Application)
        assert r.name == 'foo'
        assert r.config['path'] == 'some/path'

        r = yield controller.get('foo')
        assert isinstance(r, Application)
        assert r.name == 'foo'
        assert r.config['path'] == 'some/path'

        r = yield controller.create('boo', {'path': 'other/path'}, skip_validation=True)
        assert isinstance(r, Application)
        assert r.name == 'boo'
        assert r.config['path'] == 'other/path'

        mockapp = flexmock()
        flexmock(Application).new_instances(mockapp)
        mockapp.should_receive('load').with_args(need_details=True).and_return(defer.succeed({'foo': 'bar'}))

        r = yield controller.list()

        assert isinstance(r, list)
        assert len(r) == 2
        for app in r:
            assert app == {'foo': 'bar'}

        yield controller.remove('foo')

        with pytest.raises(AppDoesNotExist):
            yield controller.get('foo')
Exemple #2
0
def test_internal_containers():

    ac = ApplicationController()

    ac.mark_internal('123')

    assert ac.is_internal('123')

    assert ac.is_internal('124') is False
    assert ac.is_internal(None) is False