def setUp(self): super(RebuildRSREnvTest, self).setUp() self.virtualenv_installer_config = RSRVirtualEnvInstallerConfig.create_with(CIDeploymentHostConfig.for_test(), User.CURRENT) self.mock_virtualenv_deployment_host = self.mox.CreateMock(VirtualEnvDeploymentHost) self.rebuild_virtualenv_task = StubbedRebuildRSREnv(self.mock_virtualenv_deployment_host)
def test_can_create_deployment_host_config_for_test_host(self): """fab.tests.config.rsr.ci_deployment_host_config_test Can create CI deployment host config for test host""" expected_test_host_config = DeploymentHostConfig.create_with( HostAlias.TEST, RepositoryBranch.DEVELOP, 'rsrdb_develop') self.assertEqual(expected_test_host_config, CIDeploymentHostConfig.for_test())
def test_can_configure_linux_host_with_given_host_config_specification(self): """fab.tests.tasks.environment.linux_host_base_task_test Can configure Linux host with the given host configuration specification""" host_config_spec = HostConfigSpecification().create_preconfigured_with(HostAlias.TEST) self.mock_config_loader.parse(host_config_spec).AndReturn(CIDeploymentHostConfig.for_test()) self.mox.ReplayAll() self.assertIsInstance(self.linux_host_base_task._configure_linux_host_with(host_config_spec), LinuxHost)
def setUp(self): super(TaskRunnerTest, self).setUp() self.mock_config_loader = self.mox.CreateMock(DeploymentConfigLoader) self.mock_process_runner = self.mox.CreateMock(ProcessRunner) self.user_credentials = UserCredentials.default() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.task_runner = TaskRunner(self.user_credentials, self.mock_config_loader, self.mock_process_runner)
def setUp(self): super(RSRAppDeployerTest, self).setUp() self.mock_deployment_host = self.mox.CreateMock(DeploymentHost) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.deployment_config = RSRDeploymentConfig.create_with(CIDeploymentHostConfig.for_test(), "rupaul") self.mock_deployment_host.feedback = self.mock_feedback self.app_deployer = RSRAppDeployer(self.deployment_config, self.mock_deployment_host)
def setUp(self): super(DatabaseHostTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.database_credentials = TemplateLoader.load_database_credentials() self.database_config = RSRDatabaseConfig(self.database_credentials, self.deployment_host_config) self.mock_settings_verifier = self.mox.CreateMock(RSRSettingsVerifier) self.mock_database_admin = self.mox.CreateMock(DatabaseAdmin) self.database_host = DatabaseHost(self.mock_settings_verifier, self.database_config, self.mock_database_admin)
def setUp(self): super(RebuildRSREnvTest, self).setUp() self.virtualenv_installer_config = RSRVirtualEnvInstallerConfig.create_with( CIDeploymentHostConfig.for_test(), User.CURRENT) self.mock_virtualenv_deployment_host = self.mox.CreateMock( VirtualEnvDeploymentHost) self.rebuild_virtualenv_task = StubbedRebuildRSREnv( self.mock_virtualenv_deployment_host)
def setUp(self): super(RSRSettingsVerifierTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.deployment_config = RSRDeploymentConfig.create_with(self.deployment_host_config) self.mock_settings_reader = self.mox.CreateMock(DjangoSettingsReader) self.mock_host_file_system = self.mox.CreateMock(FileSystem) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.settings_verifier = RSRSettingsVerifier(self.deployment_host_config, self.deployment_config, self.mock_settings_reader, self.mock_host_file_system, self.mock_feedback)
def test_can_parse_preconfigured_test_host_config_from_given_task_parameters( self): """fab.tests.config.loader.deployment_config_loader_test Can parse preconfigured test host configuration from given task parameters""" self.mox.ReplayAll() self.assertEqual( CIDeploymentHostConfig.for_test(), self.config_loader.parse( self._preconfigured_config_spec_for(HostAlias.TEST)))
def test_can_create_instance(self): """fab.tests.database.mysql.database_admin_test Can create a DatabaseAdmin instance""" deployment_host_config = CIDeploymentHostConfig.for_test() database_credentials = TemplateLoader.load_database_credentials() mock_host_controller = self.mox.CreateMock(RemoteHostController) mock_host_controller.feedback = self.mock_feedback self.mox.ReplayAll() self.assertIsInstance(DatabaseAdmin.create_with(database_credentials, deployment_host_config, mock_host_controller), DatabaseAdmin)
def setUp(self): super(RSRDataPopulatorConfigTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.deployment_config = RSRDeploymentConfig.create_with(self.deployment_host_config) self.codebase_config = RSRCodebaseConfig("some_repo_branch") self.expected_rsr_deployment_home = self.deployment_config.rsr_deployment_home self.data_populator_config = RSRDataPopulatorConfig(self.deployment_config, self.deployment_host_config.host_paths, self.codebase_config)
def setUp(self): super(RSRDataPopulatorConfigTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.deployment_config = RSRDeploymentConfig.create_with( self.deployment_host_config) self.codebase_config = RSRCodebaseConfig("some_repo_branch") self.expected_rsr_deployment_home = self.deployment_config.rsr_deployment_home self.data_populator_config = RSRDataPopulatorConfig( self.deployment_config, self.deployment_host_config.host_paths, self.codebase_config)
def setUp(self): super(RSRDeploymentConfigTest, self).setUp() self.deployment_user = '******' self.deployment_host_config = CIDeploymentHostConfig.for_test() self.deployment_host_paths = self.deployment_host_config.host_paths self.codebase_config = RSRCodebaseConfig(self.deployment_host_config.repository_branch) self.expected_rsr_dir_name = 'rsr_%s' % self.codebase_config.repo_branch_without_type self.expected_rsr_deployment_home = os.path.join(self.deployment_host_paths.repo_checkout_home, self.expected_rsr_dir_name) self.expected_current_virtualenv_path = os.path.join(self.deployment_host_paths.virtualenvs_home, 'current') self.deployment_config = RSRDeploymentConfig(self.deployment_host_paths, self.deployment_user, self.codebase_config)
def setUp(self): super(PipInstallerTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.installation_paths = SystemPackageInstallationPaths(self.deployment_host_config.host_paths) self.mock_file_system = self.mox.CreateMock(FileSystem) self.mock_internet = self.mox.CreateMock(Internet) self.mock_host_controller = self.mox.CreateMock(RemoteHostController) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_host_controller.feedback = self.mock_feedback self.pip_installer = PipInstaller(self.installation_paths, self.mock_file_system, self.mock_internet, self.mock_host_controller)
def setUp(self): super(RSRSettingsVerifierTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.deployment_config = RSRDeploymentConfig.create_with( self.deployment_host_config) self.mock_settings_reader = self.mox.CreateMock(DjangoSettingsReader) self.mock_host_file_system = self.mox.CreateMock(FileSystem) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.settings_verifier = RSRSettingsVerifier( self.deployment_host_config, self.deployment_config, self.mock_settings_reader, self.mock_host_file_system, self.mock_feedback)
def setUp(self): super(RSRVirtualEnvInstallerConfigTest, self).setUp() self.deployment_user = "******" self.deployment_host_config = CIDeploymentHostConfig.for_test() self.codebase_config = RSRCodebaseConfig(self.deployment_host_config.repository_branch) self.expected_virtualenvs_home = self.deployment_host_config.host_paths.virtualenvs_home self.expected_rsr_env_name = "rsr_%s" % self.codebase_config.repo_branch_without_type self.virtualenv_installer_config = RSRVirtualEnvInstallerConfig(self.deployment_host_config.host_paths, self.codebase_config, self.deployment_user)
def setUp(self): super(RSRVirtualEnvInstallerConfigTest, self).setUp() self.deployment_user = "******" self.deployment_host_config = CIDeploymentHostConfig.for_test() self.codebase_config = RSRCodebaseConfig( self.deployment_host_config.repository_branch) self.expected_virtualenvs_home = self.deployment_host_config.host_paths.virtualenvs_home self.expected_rsr_env_name = "rsr_%s" % self.codebase_config.repo_branch_without_type self.virtualenv_installer_config = RSRVirtualEnvInstallerConfig( self.deployment_host_config.host_paths, self.codebase_config, self.deployment_user)
def test_can_configure_linux_host_with_given_host_config_specification( self): """fab.tests.tasks.environment.linux_host_base_task_test Can configure Linux host with the given host configuration specification""" host_config_spec = HostConfigSpecification().create_preconfigured_with( HostAlias.TEST) self.mock_config_loader.parse(host_config_spec).AndReturn( CIDeploymentHostConfig.for_test()) self.mox.ReplayAll() self.assertIsInstance( self.linux_host_base_task._configure_linux_host_with( host_config_spec), LinuxHost)
def test_can_create_instance(self): """fab.tests.database.mysql.database_admin_test Can create a DatabaseAdmin instance""" deployment_host_config = CIDeploymentHostConfig.for_test() database_credentials = TemplateLoader.load_database_credentials() mock_host_controller = self.mox.CreateMock(RemoteHostController) mock_host_controller.feedback = self.mock_feedback self.mox.ReplayAll() self.assertIsInstance( DatabaseAdmin.create_with(database_credentials, deployment_host_config, mock_host_controller), DatabaseAdmin)
def test_will_raise_not_implemented_error_if_no_database_actions_defined(self): """fab.tests.tasks.database.rsr_database_task_test Will raise NotImplementedError if no database actions have been defined""" mock_config_loader = self.mox.CreateMock(DeploymentConfigLoader) mock_database_host = self.mox.CreateMock(DatabaseHost) host_config_spec = HostConfigSpecification().create_preconfigured_with(HostAlias.TEST) mock_config_loader.parse(host_config_spec).AndReturn(CIDeploymentHostConfig.for_test()) self.mox.ReplayAll() database_task = StubbedRSRDatabaseTask(mock_config_loader, mock_database_host) with self.assertRaises(NotImplementedError) as raised: database_task.run(HostControllerMode.REMOTE, host_config_spec) self.assertEqual('No database actions defined', raised.exception.message)
def setUp(self): super(PipInstallerTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.installation_paths = SystemPackageInstallationPaths( self.deployment_host_config.host_paths) self.mock_file_system = self.mox.CreateMock(FileSystem) self.mock_internet = self.mox.CreateMock(Internet) self.mock_host_controller = self.mox.CreateMock(RemoteHostController) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_host_controller.feedback = self.mock_feedback self.pip_installer = PipInstaller(self.installation_paths, self.mock_file_system, self.mock_internet, self.mock_host_controller)
def setUp(self): super(VirtualEnvInstallerTest, self).setUp() self.mock_host_controller = self.mox.CreateMock(RemoteHostController) self.mock_file_system = self.mox.CreateMock(FileSystem) self.mock_permissions = self.mox.CreateMock(AkvoPermissions) self.mock_internet = self.mox.CreateMock(Internet) self.mock_virtualenv = self.mox.CreateMock(VirtualEnv) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_time_stamp_formatter = self.mox.CreateMock(TimeStampFormatter) self.virtualenv_installer_config = RSRVirtualEnvInstallerConfig.create_with(CIDeploymentHostConfig.for_test(), "deployment_user") self.pip_requirements_url = "http://some/path/to/pip_requirements.txt" self.mock_host_controller.feedback = self.mock_feedback self.virtualenv_installer = VirtualEnvInstaller(self.virtualenv_installer_config, self.mock_host_controller, self.mock_file_system, self.mock_permissions, self.mock_internet, self.mock_virtualenv, self.mock_time_stamp_formatter)
def setUp(self): super(RSRDataPopulatorTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.data_populator_config = RSRDataPopulatorConfig.create_with(self.deployment_host_config) self.mock_data_host_file_system = self.mox.CreateMock(FileSystem) self.mock_local_file_system = self.mox.CreateMock(FileSystem) self.mock_django_admin = self.mox.CreateMock(DjangoAdmin) self.mock_data_handler = self.mox.CreateMock(DataHandler) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_last_migration_file = self.mox.CreateMock(file) self.latest_data_archive_name = 'rsr_data_20111112.sql.zip' self.expected_data_archive_file_path = os.path.join(self.data_populator_config.data_archives_home, self.latest_data_archive_name) self.expected_data_extract_file_path = self.expected_data_archive_file_path.rstrip('.zip') self.data_populator = StubbedRSRDataPopulator(self.data_populator_config, self.mock_data_host_file_system, self.mock_local_file_system, self.mock_django_admin, self.mock_data_handler, self.mock_feedback, self.mock_last_migration_file)
def setUp(self): super(RSRDeploymentConfigTest, self).setUp() self.deployment_user = '******' self.deployment_host_config = CIDeploymentHostConfig.for_test() self.deployment_host_paths = self.deployment_host_config.host_paths self.codebase_config = RSRCodebaseConfig( self.deployment_host_config.repository_branch) self.expected_rsr_dir_name = 'rsr_%s' % self.codebase_config.repo_branch_without_type self.expected_rsr_deployment_home = os.path.join( self.deployment_host_paths.repo_checkout_home, self.expected_rsr_dir_name) self.expected_current_virtualenv_path = os.path.join( self.deployment_host_paths.virtualenvs_home, 'current') self.deployment_config = RSRDeploymentConfig( self.deployment_host_paths, self.deployment_user, self.codebase_config)
def setUp(self): super(SystemPythonPackageInstallerTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.codebase_config = RSRCodebaseConfig(self.deployment_host_config.repository_branch) self.installation_paths = SystemPackageInstallationPaths(self.deployment_host_config.host_paths) self.mock_pip_installer = self.mox.CreateMock(PipInstaller) self.mock_file_system = self.mox.CreateMock(FileSystem) self.mock_permissions = self.mox.CreateMock(AkvoPermissions) self.mock_internet = self.mox.CreateMock(Internet) self.mock_host_controller = self.mox.CreateMock(RemoteHostController) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_host_controller.feedback = self.mock_feedback self.package_installer = SystemPythonPackageInstaller(self.deployment_host_config.host_paths, self.codebase_config, self.installation_paths, self.mock_pip_installer, self.mock_file_system, self.mock_permissions, self.mock_internet, self.mock_host_controller)
def test_will_raise_not_implemented_error_if_no_database_actions_defined( self): """fab.tests.tasks.database.rsr_database_task_test Will raise NotImplementedError if no database actions have been defined""" mock_config_loader = self.mox.CreateMock(DeploymentConfigLoader) mock_database_host = self.mox.CreateMock(DatabaseHost) host_config_spec = HostConfigSpecification().create_preconfigured_with( HostAlias.TEST) mock_config_loader.parse(host_config_spec).AndReturn( CIDeploymentHostConfig.for_test()) self.mox.ReplayAll() database_task = StubbedRSRDatabaseTask(mock_config_loader, mock_database_host) with self.assertRaises(NotImplementedError) as raised: database_task.run(HostControllerMode.REMOTE, host_config_spec) self.assertEqual('No database actions defined', raised.exception.message)
def setUp(self): super(VirtualEnvDeploymentHostTest, self).setUp() self.mock_file_system = self.mox.CreateMock(FileSystem) self.mock_user_verifier = self.mox.CreateMock(DeploymentUserVerifier) self.mock_permissions = self.mox.CreateMock(AkvoPermissions) self.mock_virtualenv_installer = self.mox.CreateMock(VirtualEnvInstaller) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.deployment_user = "******" deployment_host_config = CIDeploymentHostConfig.for_test() self.virtualenv_installer_config = RSRVirtualEnvInstallerConfig.create_with(deployment_host_config, self.deployment_user) # we don't have any additional expections on the Internet dependency (since this is already # tested in the DeploymentHost base class) so we set this to None for now self.virtualenv_deployment_host = VirtualEnvDeploymentHost(self.virtualenv_installer_config, self.mock_file_system, self.mock_user_verifier, self.mock_permissions, None, self.mock_virtualenv_installer, self.mock_feedback)
def setUp(self): super(SystemPythonPackageInstallerTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.codebase_config = RSRCodebaseConfig( self.deployment_host_config.repository_branch) self.installation_paths = SystemPackageInstallationPaths( self.deployment_host_config.host_paths) self.mock_pip_installer = self.mox.CreateMock(PipInstaller) self.mock_file_system = self.mox.CreateMock(FileSystem) self.mock_permissions = self.mox.CreateMock(AkvoPermissions) self.mock_internet = self.mox.CreateMock(Internet) self.mock_host_controller = self.mox.CreateMock(RemoteHostController) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_host_controller.feedback = self.mock_feedback self.package_installer = SystemPythonPackageInstaller( self.deployment_host_config.host_paths, self.codebase_config, self.installation_paths, self.mock_pip_installer, self.mock_file_system, self.mock_permissions, self.mock_internet, self.mock_host_controller)
def setUp(self): super(VirtualEnvInstallerTest, self).setUp() self.mock_host_controller = self.mox.CreateMock(RemoteHostController) self.mock_file_system = self.mox.CreateMock(FileSystem) self.mock_permissions = self.mox.CreateMock(AkvoPermissions) self.mock_internet = self.mox.CreateMock(Internet) self.mock_virtualenv = self.mox.CreateMock(VirtualEnv) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_time_stamp_formatter = self.mox.CreateMock( TimeStampFormatter) self.virtualenv_installer_config = RSRVirtualEnvInstallerConfig.create_with( CIDeploymentHostConfig.for_test(), "deployment_user") self.pip_requirements_url = "http://some/path/to/pip_requirements.txt" self.mock_host_controller.feedback = self.mock_feedback self.virtualenv_installer = VirtualEnvInstaller( self.virtualenv_installer_config, self.mock_host_controller, self.mock_file_system, self.mock_permissions, self.mock_internet, self.mock_virtualenv, self.mock_time_stamp_formatter)
class DeploymentConfigLoader(object): preconfigured_hosts = { HostAlias.TEST: CIDeploymentHostConfig.for_test(), HostAlias.TEST2: CIDeploymentHostConfig.for_test2(), HostAlias.DATA: DataHostConfig() } def __init__(self, feedback=ExecutionFeedback()): self.feedback = feedback def parse(self, config_specification): if self._invalid_host_config_format(config_specification): self.feedback.abort('Invalid host configuration specification: %s -- expected config_type:some;config;values' % config_specification) config_spec_parts = config_specification.split(':') return self._parse_config_spec(ConfigType(config_spec_parts[0]), config_spec_parts[-1].split(';')) def _invalid_host_config_format(self, config_specification): return config_specification.find(':') < 0 def _parse_config_spec(self, config_type, config_parameters): if config_type.is_preconfigured(): host_alias = config_parameters[0] if host_alias not in self.preconfigured_hosts: self.feedback.abort('No preconfigured values for host alias: %s' % host_alias) return self.preconfigured_hosts[host_alias] elif config_type.is_standard(): return DeploymentHostConfig.create_with(config_parameters[0], config_parameters[1], config_parameters[2]) elif config_type.is_custom(): return self._custom_config_from(config_parameters[0]) else: self.feedback.abort('Cannot parse host configuration from: %s:%s' % (config_type, ''.join(config_parameters))) def _custom_config_from(self, custom_config_module_path): import imp imp.load_source('custom_config', custom_config_module_path) from custom_config import CustomDeploymentHostConfig return CustomDeploymentHostConfig.create()
def setUp(self): super(RSRDataPopulatorTest, self).setUp() self.deployment_host_config = CIDeploymentHostConfig.for_test() self.data_populator_config = RSRDataPopulatorConfig.create_with( self.deployment_host_config) self.mock_data_host_file_system = self.mox.CreateMock(FileSystem) self.mock_local_file_system = self.mox.CreateMock(FileSystem) self.mock_django_admin = self.mox.CreateMock(DjangoAdmin) self.mock_data_handler = self.mox.CreateMock(DataHandler) self.mock_feedback = self.mox.CreateMock(ExecutionFeedback) self.mock_last_migration_file = self.mox.CreateMock(file) self.latest_data_archive_name = 'rsr_data_20111112.sql.zip' self.expected_data_archive_file_path = os.path.join( self.data_populator_config.data_archives_home, self.latest_data_archive_name) self.expected_data_extract_file_path = self.expected_data_archive_file_path.rstrip( '.zip') self.data_populator = StubbedRSRDataPopulator( self.data_populator_config, self.mock_data_host_file_system, self.mock_local_file_system, self.mock_django_admin, self.mock_data_handler, self.mock_feedback, self.mock_last_migration_file)
def test_can_create_a_linuxhost_instance(self): """fab.tests.host.linux_host_test Can create a LinuxHost instance""" self.assertIsInstance(LinuxHost.create_with(CIDeploymentHostConfig.for_test()), LinuxHost)
def _can_configure_app_deployer_with(self, host_controller_mode): self.assertIsInstance( DeployRSRApp()._configure_app_deployer_using( host_controller_mode, CIDeploymentHostConfig.for_test()), RSRAppDeployer)
def _can_configure_app_deployer_with(self, host_controller_mode): self.assertIsInstance(DeployRSRApp()._configure_app_deployer_using(host_controller_mode, CIDeploymentHostConfig.for_test()), RSRAppDeployer)
def test_can_create_deployment_host_config_for_test_host(self): """fab.tests.config.rsr.ci_deployment_host_config_test Can create CI deployment host config for test host""" expected_test_host_config = DeploymentHostConfig.create_with(HostAlias.TEST, RepositoryBranch.DEVELOP, 'rsrdb_develop') self.assertEqual(expected_test_host_config, CIDeploymentHostConfig.for_test())
def setUp(self): super(SystemPackageInstallationPathsTest, self).setUp() self.deployment_host_paths = CIDeploymentHostConfig.for_test().host_paths self.installation_paths = SystemPackageInstallationPaths(self.deployment_host_paths)
def test_can_create_a_linuxhost_instance(self): """fab.tests.host.linux_host_test Can create a LinuxHost instance""" self.assertIsInstance( LinuxHost.create_with(CIDeploymentHostConfig.for_test()), LinuxHost)
def test_can_parse_preconfigured_test_host_config_from_given_task_parameters(self): """fab.tests.config.loader.deployment_config_loader_test Can parse preconfigured test host configuration from given task parameters""" self.mox.ReplayAll() self.assertEqual(CIDeploymentHostConfig.for_test(), self.config_loader.parse(self._preconfigured_config_spec_for(HostAlias.TEST)))