Пример #1
0
    def test_collect_volumes_ssh_auth_socket(self, os_environ_mock: Mock):
        ssh_auth_path = 'DUMMY'
        env = {'SSH_AUTH_SOCK': ssh_auth_path}
        os_environ_mock.__getitem__.side_effect = env.__getitem__
        os_environ_mock.__iter__.side_effect = env.__iter__
        os_environ_mock.__contains__.side_effect = env.__contains__
        cmd = module.Command({})
        expected = OrderedDict({
            # Source code also has to be mounted in:
            ProjectStub.SRC_FOLDER: {
                'bind': CONTAINER_SRC_PATH,
                'mode': 'rw'
            },
            # SSH_AUTH_SOCK:
            ssh_auth_path: {
                'bind': ssh_auth_path,
                'mode': 'rw'
            }
        })

        # The project contains NO services matching the defined roles
        cmd.parent_doc = ProjectStub({}, set_parent_to_self=True)
        actual = cmd.collect_volumes()
        self.assertEqual(expected, actual)
        self.assertIsInstance(actual, OrderedDict)
Пример #2
0
 def setUp(self):
     self.fix_with_volumes = module.Command({
         "additional_volumes": {
             "one": {
                 "host": "~/hometest",
                 "container": "/vol1",
                 "mode": "rw"
             },
             "two": {
                 "host": "./reltest1",
                 "container": "/vol2",
                 "mode": "rw"
             },
             "three": {
                 "host": "reltest2",
                 "container": "/vol3",
                 "mode": "rw"
             },
             "four": {
                 "host": "reltestc",
                 "container": "reltest_container",
                 "mode": "rw"
             },
             "five": {
                 "host": "/absolute_with_ro",
                 "container": "/vol4",
                 "mode": "ro"
             },
             "six": {
                 "host": "/absolute_no_mode",
                 "container": "/vol5"
             }
         },
         "config_from_roles": ["A", "B"]
     })
Пример #3
0
    def test_volume_path(self, meta_folder_mock: Mock, os_makedirs_mock: Mock):
        cmd = module.Command({'$name': 'hello_world'})
        cmd.parent_doc = ProjectStub({}, set_parent_to_self=True)
        expected_path = os.path.join('META', 'cmd_data', 'hello_world')
        self.assertEqual(expected_path, cmd.volume_path())

        meta_folder_mock.assert_called_once_with(ProjectStub.FOLDER)
        os_makedirs_mock.assert_called_once_with(expected_path, exist_ok=True)
Пример #4
0
    def test_collect_environment(self, *args, **kwargs):
        cmd = module.Command({'environment': {'FROM_ENV': 'FROM_ENV'}})
        expected = {
            'ENV': 'VALUE1',
            'FROM_ENV': 'FROM_ENV',
            'COLUMNS': '10',
            'LINES': '20'
        }

        self.assertEqual(expected, cmd.collect_environment())
Пример #5
0
 def test_resolve_alias_something_to_alias(self):
     # hello world command
     hello_world_command = YamlConfigDocumentStub({'hello': 'world'})
     # The command we want to test
     cmd = module.Command({'aliases': 'hello_world'})
     # The parent app of the command we want to test, that contains both commands
     cmd.parent_doc = YamlConfigDocumentStub({
         'commands': {
             'hello_world': hello_world_command,
             'our_test': cmd
         }
     })
     # Make the mocked command's resolve_alias return itself.
     setattr(hello_world_command, 'resolve_alias',
             MagicMock(return_value=hello_world_command))
     # Assert that we get the hello world command
     self.assertEqual(hello_world_command, cmd.resolve_alias())
     # Make sure resolve_alias was actually called on our mocked command
     hello_world_command.resolve_alias.assert_called_once()
Пример #6
0
 def test_header(self):
     cmd = module.Command({})
     self.assertEqual(module.HEADER, cmd.header())
Пример #7
0
 def test_home_path(self):
     cmd = module.Command({})
     self.assertEqual(CONTAINER_HOME_PATH, cmd.home_path())
Пример #8
0
 def test_resolve_alias_nothing_to_alias(self):
     cmd = module.Command({})
     self.assertEqual(cmd, cmd.resolve_alias())
Пример #9
0
 def test_get_project_no_parent(self):
     cmd = module.Command({})
     with self.assertRaises(IndexError):
         cmd.get_project()
Пример #10
0
 def test_get_project(self):
     cmd = module.Command({})
     project = ProjectStub({}, set_parent_to_self=True)
     cmd.parent_doc = project
     self.assertEqual(project, cmd.get_project())