Пример #1
0
    def test_cluster_tag_create_yaml(self):
        env_id = 45
        tag_name = 'fake_tag'
        params = {
            "owner_type": "clusters",
            "owner_id": env_id,
            "tag_name": tag_name
        }
        args = 'tag create -e {} -n {} -f yaml -d /tmp'.format(
            env_id, tag_name)
        test_data = fake_tag.get_fake_tag(tag_name)
        expected_path = '/tmp/clusters_{}/fake_tag.yaml'.format(env_id)

        m_open = mock.mock_open(read_data=yaml.safe_dump(test_data))
        with mock.patch('fuelclient.commands.tag.open', m_open, create=True):
            self.exec_command(args)

        m_open.assert_called_once_with(expected_path, 'r')
        self.m_get_client.assert_called_once_with('tag', mock.ANY)
        self.m_client.create.assert_called_once_with(test_data, **params)
Пример #2
0
    def test_release_tag_create_json(self):
        release_id = 45
        tag_name = 'fake_tag'
        params = {
            "owner_type": "releases",
            "owner_id": release_id,
            "tag_name": tag_name
        }
        args = 'tag create -r {} -n {} -f json -d /tmp'.format(
            release_id, tag_name)
        test_data = fake_tag.get_fake_tag(tag_name)
        expected_path = '/tmp/releases_{}/fake_tag.json'.format(release_id)

        m_open = mock.mock_open(read_data=json.dumps(test_data))
        with mock.patch('fuelclient.commands.tag.open', m_open, create=True):
            self.exec_command(args)

        m_open.assert_called_once_with(expected_path, 'r')
        self.m_get_client.assert_called_once_with('tag', mock.ANY)
        self.m_client.create.assert_called_once_with(test_data, **params)
Пример #3
0
    def test_cluster_tag_download_json(self, m_dump):
        env_id = 45
        tag_name = 'fake_tag'
        test_data = fake_tag.get_fake_tag(fake_tag)
        args = 'tag download -e {} -n {} -f json -d /tmp'.format(
            env_id, tag_name)
        expected_path = '/tmp/clusters_{id}/{name}.json'.format(id=env_id,
                                                                name=tag_name)

        self.m_client.get_tag.return_value = test_data

        m_open = mock.mock_open()
        with mock.patch('fuelclient.commands.tag.open', m_open, create=True):
            self.exec_command(args)

        m_open.assert_called_once_with(expected_path, 'w')
        m_dump.assert_called_once_with(test_data, mock.ANY, indent=4)
        self.m_get_client.assert_called_once_with('tag', mock.ANY)
        self.m_client.get_tag.assert_called_once_with('clusters', env_id,
                                                      tag_name)
Пример #4
0
    def test_release_tag_download_yaml(self, m_safe_dump):
        release_id = 45
        tag_name = 'fake_tag'
        test_data = fake_tag.get_fake_tag(fake_tag)
        args = 'tag download -r {} -n {} -f yaml -d /tmp'.format(
            release_id, tag_name)
        expected_path = '/tmp/releases_{id}/{name}.yaml'.format(id=release_id,
                                                                name=tag_name)

        self.m_client.get_tag.return_value = test_data

        m_open = mock.mock_open()
        with mock.patch('fuelclient.commands.tag.open', m_open, create=True):
            self.exec_command(args)

        m_open.assert_called_once_with(expected_path, 'w')
        m_safe_dump.assert_called_once_with(test_data,
                                            mock.ANY,
                                            default_flow_style=False)
        self.m_get_client.assert_called_once_with('tag', mock.ANY)
        self.m_client.get_tag.assert_called_once_with('releases', release_id,
                                                      tag_name)