Skip to content
Snippets Groups Projects
openbis_command_test.py 1.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • yvesn's avatar
    yvesn committed
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    
    #   Copyright ETH 2018 - 2023 Zürich, Scientific IT Services
    # 
    #   Licensed under the Apache License, Version 2.0 (the "License");
    #   you may not use this file except in compliance with the License.
    #   You may obtain a copy of the License at
    # 
    #        http://www.apache.org/licenses/LICENSE-2.0
    #   
    #   Unless required by applicable law or agreed to in writing, software
    #   distributed under the License is distributed on an "AS IS" BASIS,
    #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #   See the License for the specific language governing permissions and
    #   limitations under the License.
    #
    
    
    yvesn's avatar
    yvesn committed
    import getpass
    from unittest.mock import Mock, MagicMock, ANY
    
    from .openbis_command import OpenbisCommand
    from .. import data_mgmt
    
    
    def test_prepare_run(monkeypatch):
        # given
    
    yvesn's avatar
    yvesn committed
        dm = data_mgmt.DataMgmt(openbis=Mock(), git_config={
            'data_path': '',
            'metadata_path': '',
            'invocation_path': ''
        })
    
    yvesn's avatar
    yvesn committed
        openbis_command = OpenbisCommand(dm)
    
    yvesn's avatar
    yvesn committed
        define_config(openbis_command)
    
    yvesn's avatar
    yvesn committed
        monkeypatch.setattr(getpass, 'getpass', lambda s: 'password')
        dm.openbis.is_session_active.return_value = False
        # when
        openbis_command.prepare_run()
        # then
        dm.openbis.is_session_active.assert_called()
    
    yvesn's avatar
    yvesn committed
        dm.openbis.login.assert_called_with('watney', 'password', save_token=True)
    
    yvesn's avatar
    yvesn committed
    
    
    def define_config(openbis_command):
        openbis_command.config_dict = {
    
    yvesn's avatar
    yvesn committed
            'config': {
                'user': 'watney'
            }
    
    yvesn's avatar
    yvesn committed
        }