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)
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)
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, [])