def test_config(self): compute = docker.Compute() self.assertEqual(compute.config(MockJustService()), 'out') self.assertEqual(('--wrap', 'Just-docker-compose', '-f', 'file1', 'config'), self.just_args) self.assertEqual({'stdout': docker.PIPE, 'env': {'BAR': 'FOO'}}, self.just_kwargs)
def test_just_simple(self): default_justfile = os.path.join(os.environ['TERRA_TERRA_DIR'], 'Justfile') # Create a compute compute = docker.Compute() # Call just, and get the args calculated, retrieved via mock args, kwargs = compute.just("foo bar") self.assertEqual(args, (('bash', 'just', 'foo bar'),)) self.assertEqual(set(kwargs.keys()), {'executable', 'env'}) self.assertEqual(kwargs['env']['JUSTFILE'], default_justfile)
def test_config_non_existing_service(self): compute = docker.Compute() service = TestDockerMap.Service() with warnings.catch_warnings(): warnings.simplefilter('ignore') # Use the default name, foo, which doesn't even exist volume_map = compute.configuration_map(service) # Should be empty self.assertEqual(volume_map, [])
def test_config_with_custom_files(self): compute = docker.Compute() self.assertEqual(compute.config_service(MockJustService(), ['file15.yml', 'file2.yaml']), 'out') self.assertEqual(('--wrap', 'Just-docker-compose', '-f', 'file1', '-f', 'file15.yml', '-f', 'file2.yaml', 'config'), self.just_args) self.assertEqual({'stdout': docker.PIPE, 'env': {'BAR': 'FOO'}}, self.just_kwargs)
def test_config_test_service_nt(self): compute = docker.Compute() service = TestDockerMap.Service() service.compose_service_name = "test" volume_map = compute.configuration_map(service) ans = [('/tmp', '/bar'), ('/opt/projects/terra/terra_dsm/external/terra', '/terra'), ('/tmp/.X11-unix', '/tmp/.X11-unix'), ('/opt/projects/terra/terra_dsm/external/terra/external/vsi_common', '/vsi')] self.assertEqual(volume_map, ans)
def setUp(self): # This will resets the _connection to an uninitialized state self.patches.append( mock.patch.object(terra.compute.utils.ComputeHandler, '_connection', mock.PropertyMock(return_value=docker.Compute()))) # Configure for docker self.config.compute = {'arch': 'docker'} # patches.append(mock.patch.dict(base.services, clear=True)) super().setUp()
def test_config_with_multiple_compose_files(self): compute = docker.Compute() service = MockJustService() service.compose_files = service.compose_files + ['file15.yml', 'file2.yaml'] self.assertEqual(compute.config_service(service), 'out') self.assertEqual(('--wrap', 'Just-docker-compose', '-f', 'file1', '-f', 'file15.yml', '-f', 'file2.yaml', 'config'), self.just_args) self.assertEqual({'stdout': docker.PIPE, 'justfile': None, 'env': {'BAR': 'FOO'}}, self.just_kwargs)
def test_service_simple(self): # Must not be a decorator, because at decorator time (before setUp is run), # settings._wrapped is still None. Mock the version from setUpModule so I # change the values without affecting any other test with mock.patch.dict(settings._wrapped, {}): compute = docker.Compute() compute.configuration_map(SomeService()) # Test setting for translation settings.foo_dir = "/foo" settings.bar_dir = "/not_foo" service = SomeService() # Simple case self.common(compute, service)
def test_run(self): compute = docker.Compute() self.return_value = 0 # This part of the test looks fragile compute.run(MockJustService()) # Run a docker service self.assertEqual(('--wrap', 'Just-docker-compose', '-f', 'file1', 'run', 'launch', 'ls'), self.just_args) self.assertEqual({'env': {'BAR': 'FOO'}}, self.just_kwargs) # Test a non-zero return value self.return_value = 1 with self.assertRaises(base.ServiceRunFailed): compute.run(MockJustService())
def setUp(self): # Use settings self.patches.append(mock.patch.object(settings, '_wrapped', None)) # This will resets the _connection to an uninitialized state self.patches.append( mock.patch.object(terra.compute.utils.ComputeHandler, '_connection', mock.PropertyMock(return_value=docker.Compute()))) # patches.append(mock.patch.dict(base.services, clear=True)) super().setUp() # Configure for docker settings.configure({ 'compute': {'arch': 'docker'}, 'processing_dir': self.temp_dir.name, 'test_dir': '/opt/projects/terra/terra_dsm/external/terra/foo'})
def test_service_other_dir_methods(self): compute = docker.Compute() compute.configuration_map(SomeService()) # Test setting for translation settings.foo_dir = "/foo" settings.bar_dir = "/not_foo" # Run same tests with a TERRA_VOLUME externally set service = SomeService() service.add_volume('/test1', '/test2', 'z') service.env['TERRA_VOLUME_1'] = "/Foo:/Bar" self.common(compute, service) # Make sure this is still set correctly self.assertEqual(service.env['TERRA_VOLUME_1'], "/Foo:/Bar") self.assertIn('/test1:/test2:z', (v for k, v in service.env.items() if k.startswith('TERRA_VOLUME_')), 'Added volume failed to be bound')