示例#1
0
    def test_apply_filter_no_list(self, mock_info, mock_definition,
                                  mock_attr_element,
                                  mock_attr_element_coroutine):
        """Test that selected objects passed as strings are assigned properly when filter is applied."""

        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_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

        cube = Cube(connection=self.connection, cube_id=self.cube_id)
        cube.apply_filters(attributes=self.__selected_attr[0],
                           metrics=self.__selected_metrs[0],
                           attr_elements=self.__selected_elem[0])

        self.assertEqual(cube.selected_attributes, self.__selected_attr)
        self.assertEqual(cube.selected_metrics, self.__selected_metrs)
        self.assertEqual(cube.selected_attr_elements,
                         [self.__selected_elem[0]])
示例#2
0
    def test_apply_filters_for_incorrect_assignments(
            self, mock_info, mock_definition, mock_attr_element,
            mock_attr_element_coroutine):
        """Test that incorrectly assigned selected objects are assigned properly when filter is applied."""

        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_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

        cube = Cube(connection=self.connection, cube_id=self.cube_id)
        # attributes assigned selected_metrs, metrics assigned selected_elem and attr_elements assigned selected_attr
        cube.apply_filters(attributes=self.__selected_metrs,
                           metrics=self.__selected_elem,
                           attr_elements=self.__selected_attr)

        self.assertEqual(cube.selected_attributes, self.__selected_attr)
        self.assertEqual(cube.selected_metrics, self.__selected_metrs)
        self.assertEqual(cube.selected_attr_elements, self.__selected_elem)
示例#3
0
    def test_clear_filters(self, mock_info, mock_definition, mock_attr_element,
                           mock_attr_element_coroutine):
        """Test that selected objects are assigned with empty lists when filter is cleared."""

        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_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

        cube = Cube(connection=self.connection, cube_id=self.cube_id)
        cube.apply_filters(self.__selected_attr, self.__selected_metrs,
                           self.__selected_elem)

        self.assertEqual(cube.selected_attributes, self.__selected_attr)
        self.assertEqual(cube.selected_metrics, self.__selected_metrs)
        self.assertEqual(cube.selected_attr_elements, self.__selected_elem)

        cube.clear_filters()

        self.assertIsNone(cube.selected_attributes)
        self.assertIsNone(cube.selected_metrics)
        self.assertIsNone(cube.selected_attr_elements)
示例#4
0
    def test_apply_filters(self, mock_info, mock_definition,
                           mock_attr_element):
        """Test that selected objects are assigned properly when filter is applied."""

        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

        cube = Cube(connection=self.connection, cube_id=self.cube_id)
        cube.apply_filters(self.__selected_attr, self.__selected_metrs,
                           self.__selected_elem)

        self.assertTrue(mock_attr_element.called)
        self.assertEqual(cube.selected_attributes, self.__selected_attr)
        self.assertEqual(cube.selected_metrics, self.__selected_metrs)
        self.assertEqual(cube.selected_attr_elements, self.__selected_elem)

        cube.clear_filters()
        cube.apply_filters(attributes=[], metrics=[])
        self.assertEqual(cube.attr_elements, [{
            'attribute_name':
            'Name',
            'attribute_id':
            '089FC10C11E9CA4D39700080EF15B5B9',
            'elements': [{
                'id': '089FC10C11E9CA4D39700080EF15B5B9:jack',
                'formValues': ['jack']
            }, {
                'id': '089FC10C11E9CA4D39700080EF15B5B9:krish',
                'formValues': ['krish']
            }, {
                'id': '089FC10C11E9CA4D39700080EF15B5B9:nick',
                'formValues': ['nick']
            }, {
                'id': '089FC10C11E9CA4D39700080EF15B5B9:Tom',
                'formValues': ['Tom']
            }]
        }])
        self.assertEqual(cube.selected_attributes, None)
        self.assertEqual(cube.selected_metrics, None)
示例#5
0
    def test_apply_filters(self, mock_info, mock_definition,
                           mock_attr_element):
        """Test that selected objects are assigned properly when filter is applied."""

        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

        cube = Cube(connection=self.connection, cube_id=self.cube_id)
        cube.apply_filters(self.__selected_attr, self.__selected_metrs,
                           self.__selected_elem)

        self.assertEqual(cube.selected_attributes, self.__selected_attr)
        self.assertEqual(cube.selected_metrics, self.__selected_metrs)
        self.assertEqual(cube.selected_attr_elements, self.__selected_elem)

        cube.clear_filters()
        cube.apply_filters(attributes=[], metrics=[])
        self.assertEqual(cube.selected_attributes, [])
        self.assertEqual(cube.selected_metrics, [])
示例#6
0
# get report based on its id and store it in data frame
my_report = Report(connection=connection, report_id=report_id, parallel=False)
my_report_df = my_report.to_dataframe

# get list of ids of metrics, attributes or attribue elements available within Cube or Report
my_cube.metrics
my_cube.attributes
my_cube.attr_elements

# by default all elements are shown in the data frame. To choose elements you have to pass proper IDs
# to function 'apply_filters()' which is available for Cube and Report
my_cube.apply_filters(attributes=[
    "A598372E11E9910D1CBF0080EFD54D63", "A59855D811E9910D1CC50080EFD54D63"
],
                      metrics=["B4054F5411E9910D672E0080EFC5AE5B"],
                      attr_elements=[
                          "A598372E11E9910D1CBF0080EFD54D63:Los Angeles",
                          "A598372E11E9910D1CBF0080EFD54D63:Seattle"
                      ])
# check selected elements which will be placed into a dataframe
my_cube.selected_attributes
my_cube.selected_metrics
my_cube.selected_attr_elements

my_cube_applied_filters_df = my_cube.to_dataframe

# to exclude specific attribue elements, pass the `operator="NotIn"` to `apply_filters()` method
my_cube.apply_filters(attributes=[
    "A598372E11E9910D1CBF0080EFD54D63", "A59855D811E9910D1CC50080EFD54D63"
],
                      metrics=["B4054F5411E9910D672E0080EFC5AE5B"],