def test_cluster_role_create_yaml(self): env_id = 45 role_name = 'fake_role' params = { "owner_type": "clusters", "owner_id": env_id, "role_name": role_name } args = 'role create -e {} -n {} -f yaml -d /tmp'.format( env_id, role_name) test_data = fake_role.get_fake_role(role_name) expected_path = '/tmp/clusters_{}/fake_role.yaml'.format(env_id) m_open = mock.mock_open(read_data=yaml.safe_dump(test_data)) with mock.patch('fuelclient.commands.role.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('role', mock.ANY) self.m_client.create.assert_called_once_with(test_data, **params)
def test_release_role_create_json(self): release_id = 45 role_name = 'fake_role' params = { "owner_type": "releases", "owner_id": release_id, "role_name": role_name } args = 'role create -r {} -n {} -f json -d /tmp'.format( release_id, role_name) test_data = fake_role.get_fake_role(role_name) expected_path = '/tmp/releases_{}/fake_role.json'.format(release_id) m_open = mock.mock_open(read_data=json.dumps(test_data)) with mock.patch('fuelclient.commands.role.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('role', mock.ANY) self.m_client.create.assert_called_once_with(test_data, **params)
def test_cluster_role_download_json(self, m_dump): env_id = 45 role_name = 'fake_role' test_data = fake_role.get_fake_role(fake_role) args = 'role download -e {} -n {} -f json -d /tmp'.format( env_id, role_name) expected_path = '/tmp/clusters_{id}/{name}.json'.format(id=env_id, name=role_name) self.m_client.get_one.return_value = test_data m_open = mock.mock_open() with mock.patch('fuelclient.commands.role.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('role', mock.ANY) self.m_client.get_one.assert_called_once_with('clusters', env_id, role_name)
def test_release_role_download_yaml(self, m_safe_dump): release_id = 45 role_name = 'fake_role' test_data = fake_role.get_fake_role(fake_role) args = 'role download -r {} -n {} -f yaml -d /tmp'.format( release_id, role_name) expected_path = '/tmp/releases_{id}/{name}.yaml'.format(id=release_id, name=role_name) self.m_client.get_one.return_value = test_data m_open = mock.mock_open() with mock.patch('fuelclient.commands.role.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('role', mock.ANY) self.m_client.get_one.assert_called_once_with('releases', release_id, role_name)