Exemplo n.º 1
0
    def testBadPort(self, default_user, port):
        out_server, out_name, out_port = SessionsControl._parse_conn(
            'localhost:%s' % port, default_user)

        assert out_server == 'localhost:%s' % port
        assert out_name == default_user
        assert not out_port
Exemplo n.º 2
0
    def testEmptyString(self, default_user):
        out_server, out_name, out_port = SessionsControl._parse_conn(
            '', default_user)

        assert not out_server
        assert out_name == default_user
        assert not out_port
Exemplo n.º 3
0
    def testBadPort(self, default_user, port):
        out_server, out_name, out_port = SessionsControl._parse_conn(
            'localhost:%s' % port, default_user)

        assert out_server == 'localhost:%s' % port
        assert out_name == default_user
        assert not out_port
Exemplo n.º 4
0
    def testEmptyString(self, default_user):
        out_server, out_name, out_port = SessionsControl._parse_conn(
            '', default_user)

        assert not out_server
        assert out_name == default_user
        assert not out_port
Exemplo n.º 5
0
 def testConnectionString(self, default_user, user_prefix, server,
                          port_suffix):
     in_server = '%s%s%s' % (user_prefix, server, port_suffix)
     out_server, out_name, out_port = SessionsControl._parse_conn(
         in_server, default_user)
     assert out_server == server
     if user_prefix:
         assert out_name == user_prefix[:-1]
     else:
         assert out_name == default_user
     if port_suffix:
         assert out_port == port_suffix[1:]
     else:
         assert not out_port
Exemplo n.º 6
0
 def testConnectionString(self, default_user, user_prefix, server,
                          port_suffix):
     in_server = '%s%s%s' % (user_prefix, server, port_suffix)
     out_server, out_name, out_port = SessionsControl._parse_conn(
         in_server, default_user)
     assert out_server == server
     if user_prefix:
         assert out_name == user_prefix[:-1]
     else:
         assert out_name == default_user
     if port_suffix:
         assert out_port == port_suffix[1:]
     else:
         assert not out_port
Exemplo n.º 7
0
class TestSessions(object):
    def setup_method(self, method):
        self.cli = CLI()
        self.cli.register("sessions", SessionsControl, "TEST")
        self.args = ["sessions"]

    def testHelp(self):
        self.args += ["-h"]
        self.cli.invoke(self.args, strict=True)

    @pytest.mark.parametrize("subcommand", SessionsControl().get_subcommands())
    def testSubcommandHelp(self, subcommand):
        self.args += [subcommand, "-h"]
        self.cli.invoke(self.args, strict=True)

    def testDefaultSessionsDir(self):
        from omero.util import get_user_dir
        from path import path

        # Default store sessions dir is under user dir
        store = self.cli.controls['sessions'].store(None)
        assert store.dir == path(get_user_dir()) / 'omero' / 'sessions'

    @pytest.mark.parametrize('environment', ({
        'OMERO_USERDIR': None,
        'OMERO_SESSION_DIR': None,
        'OMERO_SESSIONDIR': None
    }, {
        'OMERO_USERDIR': None,
        'OMERO_SESSION_DIR': 'session_dir',
        'OMERO_SESSIONDIR': None
    }, {
        'OMERO_USERDIR': None,
        'OMERO_SESSION_DIR': None,
        'OMERO_SESSIONDIR': 'sessiondir'
    }, {
        'OMERO_USERDIR': 'userdir',
        'OMERO_SESSION_DIR': None,
        'OMERO_SESSIONDIR': None
    }, {
        'OMERO_USERDIR': None,
        'OMERO_SESSION_DIR': 'session_dir',
        'OMERO_SESSIONDIR': 'sessiondir'
    }, {
        'OMERO_USERDIR': 'userdir',
        'OMERO_SESSION_DIR': 'session_dir',
        'OMERO_SESSIONDIR': None
    }, {
        'OMERO_USERDIR': 'userdir',
        'OMERO_SESSION_DIR': None,
        'OMERO_SESSIONDIR': 'sessiondir'
    }, {
        'OMERO_USERDIR': 'userdir',
        'OMERO_SESSION_DIR': 'session_dir',
        'OMERO_SESSIONDIR': 'sessiondir'
    }))
    @pytest.mark.parametrize('session_args', [None, 'session_dir'])
    def testCustomSessionsDir(self, tmpdir, monkeypatch, environment,
                              session_args):
        from argparse import Namespace
        from omero.util import get_user_dir
        from path import path

        for var in environment.keys():
            if environment[var]:
                monkeypatch.setenv(var, tmpdir / environment.get(var))
            else:
                monkeypatch.delenv(var, raising=False)

        # args.session_dir sets the sessions dir
        args = Namespace()
        if session_args:
            setattr(args, session_args, tmpdir / session_args)

        if environment.get('OMERO_SESSION_DIR') or session_args:
            pytest.deprecated_call(self.cli.controls['sessions'].store, args)

        store = self.cli.controls['sessions'].store(args)
        # By order of precedence
        if environment.get('OMERO_SESSIONDIR'):
            sdir = path(tmpdir) / environment.get('OMERO_SESSIONDIR')
        elif environment.get('OMERO_SESSION_DIR'):
            sdir = (path(tmpdir) / environment.get('OMERO_SESSION_DIR') /
                    'omero' / 'sessions')
        elif session_args:
            sdir = path(getattr(args, session_args)) / 'omero' / 'sessions'
        elif environment.get('OMERO_USERDIR'):
            sdir = path(tmpdir) / environment.get('OMERO_USERDIR') / 'sessions'
        else:
            sdir = path(get_user_dir()) / 'omero' / 'sessions'
        assert store.dir == sdir