コード例 #1
0
    def test_to_dataframe_multi_data_frame_true(self, mock_ds_definition,
                                                mock_info, mock_definition,
                                                mock_attr_element,
                                                mock_instance,
                                                mock_instance_id):
        mock_ds_definition.return_value = Mock(ok=True)
        mock_ds_definition.return_value.json.return_value = self.__ds_definition
        mock_info.return_value = Mock(ok=True)
        mock_info.return_value.json.return_value = self.__info
        mock_definition.return_value = Mock(ok=True)
        mock_definition.return_value.json.return_value = self.__definition
        mock_attr_element.return_value = Mock(ok=True, headers=self.__headers)
        mock_attr_element.return_value.json.return_value = self.__attr_elements
        mock_instance.return_value = Mock(ok=True)
        mock_instance.return_value.json.return_value = self.__instance
        mock_instance_id.return_value = Mock(ok=True)
        mock_instance_id.return_value.json.return_value = self.__instance_id

        cube = Cube(connection=self.connection, cube_id=self.cube_id)
        dfs = cube.to_dataframe(limit=2, multi_df=True)

        self.assertTrue(mock_instance.called)
        self.assertTrue(mock_instance_id.called)
        self.assertIsInstance(dfs, list)
        self.assertIsInstance(cube.dataframe, pandas.core.frame.DataFrame)
        self.assertTrue(cube.dataframe.equals(self.__dataframe))
        for i, df in enumerate(dfs):
            colnames = self.__ds_definition['result']['definition'][
                'availableObjects']['tables'][i]['columns']
            self.assertIsInstance(df, pandas.core.frame.DataFrame)
            self.assertTrue(df.equals(self.__dataframe[colnames]))
コード例 #2
0
    def test_to_dataframe(self, mock_info, mock_definition, mock_attr_element,
                          mock_instance, mock_instance_id):
        """Test that data is retrieved and parsed properly when to_dataframe() is called.
        Result should be saved to Cube.dataframe property.
        """

        mock_info.return_value = Mock(ok=True)
        mock_info.return_value.json.return_value = self.__info
        mock_definition.return_value = Mock(ok=True)
        mock_definition.return_value.json.return_value = self.__definition
        mock_attr_element.return_value = Mock(ok=True, headers=self.__headers)
        mock_attr_element.return_value.json.return_value = self.__attr_elements
        mock_instance.return_value = Mock(ok=True)
        mock_instance.return_value.json.return_value = self.__instance
        mock_instance_id.return_value = Mock(ok=True)
        mock_instance_id.return_value.json.return_value = self.__instance_id

        cube = Cube(connection=self.connection, cube_id=self.cube_id)
        df = cube.to_dataframe(limit=2)

        self.assertTrue(mock_instance.called)
        self.assertTrue(mock_instance_id.called)
        self.assertIsInstance(df, pandas.core.frame.DataFrame)
        self.assertIsInstance(cube.dataframe, pandas.core.frame.DataFrame)
        self.assertTrue(df.equals(self.__dataframe))