Source code for schrodinger.test.ld_mock_modules
import os.path
from schrodinger.application.livedesign import login
from schrodinger.test import mock_ld_client
from schrodinger.test import mock_ld_models
FAKE_HOST = mock_ld_client.FAKE_HOST
[docs]class MockLogin:
"""
A mock of the `applications.livedesign.login` module for use in testing.
"""
HOST = login.HOST
USERNAME = login.USERNAME
CLIENT = login.CLIENT
MODELS = login.MODELS
VERSION_NUMBER = login.VERSION_NUMBER
COMPATIBILITY_MODE = login.COMPATIBILITY_MODE
LD_MODE = login.LD_MODE
LDCLIENT_PATH = login.LDCLIENT_PATH
API_PATH = login.API_PATH
GLOBAL_PROJECT_ID = login.GLOBAL_PROJECT_ID
LD_VERSION_CORP_ID_MATCHING = login.LD_VERSION_CORP_ID_MATCHING
LD_VERSION_MULTIPLE_IDS = login.LD_VERSION_MULTIPLE_IDS
LD_VERSION_REAL_VIRTUAL = login.LD_VERSION_REAL_VIRTUAL
LD_VERSION_NEW_EXPORT = login.LD_VERSION_NEW_EXPORT
LD_VERSION_NEW_IMPORT = login.LD_VERSION_NEW_IMPORT
LD_VERSION_POSE_NAMES = login.LD_VERSION_POSE_NAMES
LD_VERSION_COMPATIBILITY_MODE = login.LD_VERSION_COMPATIBILITY_MODE
LD_VERSION_3D_PROTOCOL = login.LD_VERSION_3D_PROTOCOL
VERSION_MISMATCH_MSG = login.VERSION_MISMATCH_MSG
INVALID_CREDENTIALS_MSG = login.INVALID_CREDENTIALS_MSG
INVALID_TOKEN_MSG = login.INVALID_TOKEN_MSG
IMPORT_ERROR_MSG = login.IMPORT_ERROR_MSG
CONTACT_SUPPORT_MSG = login.CONTACT_SUPPORT_MSG
NO_CONNECTION_MSG = login.NO_CONNECTION_MSG
Version = login.Version
[docs] def __init__(self, host=FAKE_HOST):
super().__init__()
self.LDMode = login.LDMode
self._SESSION_HOST = host
# By default, select a username that is not an admin
self._SESSION_USERNAME = 'selena'
self._SESSION_PWD = 'a_fake_password'
self.ld_client = mock_ld_client.MockLDClient(
username=self._SESSION_USERNAME,
version_string='8.6.3-SNAPSHOT',
host=self._SESSION_HOST)
[docs] def get_ld_client_and_models(self):
"""
Return the stored `ldclient.client.LDClient` and `ldclient.models`
mocks.
Providing the same `LDClient` instance every time allows modifications
to the "server state" (actually stored on the `LDClient` mock) made in
unit tests to be reflected in the modules in which `login` has been
patched out with `MockLogin`.
"""
return '', self.ld_client, mock_ld_models
[docs] def get_LD_version(self, ld_client=None):
"""
:param ld_client: a mock of the `client.LDClient` class, with a
properly-behaving `about()` method defined (optional)
:type ld_client: mock.Mock
:return: the version of the supplied LD client instance
:rtype: login.Version
"""
return login.get_LD_version(ld_client=ld_client)
[docs] def get_LD_mode(self, ld_client):
"""
:param ld_client: a mock of the `client.LDClient` class, with a
`mode` attribute defined
:type ld_client: mock.Mock
:return: the LD mode of supplied LD client instance; expect to be a
string representations of one of the values of `login.LDMode`
:rtype: str
"""
return ld_client.mode
[docs] def required_login_info_set(self):
return True
[docs] def get_host(self):
"""
:return: the LiveDesign host server for this session
:rtype: str
"""
return self._SESSION_HOST
[docs] def get_username(self):
"""
:return: the LiveDesign user name for this session
:rtype: str
"""
return self._SESSION_USERNAME
[docs] def get_credentials(self):
"""
:return: the username and password for this session, if available
:rtype: tuple(str, str) or tuple(None, None)
"""
return self._SESSION_USERNAME, self._SESSION_PWD
[docs] def download_ld_client(self,
url: str,
tmp_dir: str,
tar_filename: str,
glob_path: str,
timeout: int = None) -> str:
"""
Mock implementation of `login.download_ld_client()`.
:return: the path to the downloaded client directory
"""
return os.path.join('fake', 'path', 'to', 'ldclient-V.E.R.S.')