Esempio n. 1
0
    def test_to_dataframe(self, mock_definition, mock_attr_element_coroutine,
                          mock_attr_element, mock_instance,
                          mock_instance_id_coroutine, mock_instance_id):
        """Test that data is retrieved and parsed properly when to_dataframe() is called.
        Result should be saved to Report.dataframe property.
        """

        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_attr_element_coroutine.return_value = Mock()
        mock_attr_element_coroutine.return_value.result.return_value = Mock(
            ok=True, headers=self.__headers)
        mock_attr_element_coroutine.return_value.result.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
        mock_instance_id_coroutine.return_value = Mock()
        mock_instance_id_coroutine.return_value.result.return_value = Mock(
            ok=True, headers=self.__headers)
        mock_instance_id_coroutine.return_value.result.return_value.json.return_value = self.instance_id

        report = Report(connection=self.connection, report_id=self.report_id)
        df = report.to_dataframe(limit=3)

        self.assertTrue(mock_instance.called)
        self.assertTrue(mock_instance_id_coroutine.called)
        self.assertIsInstance(df, pandas.core.frame.DataFrame)
        self.assertIsInstance(report.dataframe, pandas.core.frame.DataFrame)
        self.assertEqual(df.IQ.sum(), 29349845.567647062)
        self.assertEqual(df.salary.sum(), 4145784.7926787906)
Esempio n. 2
0
    def test_subtotals(self, mock_definition, mock_instance):
        """Test that subtotals are correctly turned off from requests"""

        mock_definition.return_value = Mock(ok=True)
        mock_definition.return_value.json.return_value = self.sub_def
        mock_instance.return_value = Mock(ok=True)
        mock_instance.return_value.json.return_value = self.sub_inst_off

        report = Report(connection=self.connection2,
                        report_id="7405D8DE11EA482779D20080EF152878")
        df = report.to_dataframe()
        self.assertTupleEqual(df.shape, (26, 7))

        mock_instance.return_value.json.return_value = self.sub_inst_on

        report_with_subtotals = Report(
            connection=self.connection,
            report_id="7405D8DE11EA482779D20080EF152878")
        df_ws = report_with_subtotals.to_dataframe()
        self.assertTupleEqual(df_ws.shape, (35, 7))
        self.assertFalse(df.equals(df_ws))
Esempio n. 3
0
    def test_to_dataframe(self, 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 Report.dataframe property.
        """

        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

        report = Report(connection=self.connection, report_id=self.report_id)
        df = report.to_dataframe(limit=2)

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