def test_export(self): column1 = aa.Column(id="Lat", variable_name=REPORTING_AIRPORT_LATITUDE, column_header="Latitude") column2 = aa.Column( id="Long", variable_name=REPORTING_AIRPORT_LONGITUDE, column_header="Longitude", ) clause = SelectorClause( "Flight Route", ORIGIN_DESTINATION_CODE, ["MALAGA", "LAS PALMAS"], session=session, )._to_model() rule = aa.Rule(clause) query = aa.Query(aa.Selection(rule=rule, table_name="Flight Route")) export = aa.Export( base_query=query, resolve_table_name="Flight Route", maximum_number_of_rows_to_browse=10, return_browse_rows=True, columns=[column1, column2], ) export_api = aa.ExportsApi(session.api_client) result = export_api.exports_perform_export_synchronously( session.data_view, session.system, export=export) test_row = result.rows[0].descriptions self.assertEqual(test_row, " 36.674900\t -4.499110")
def test__get_cube( self, patch__create_dimensions, patch__create_measures, patch_aa_cubes_api, fake_cube, selection, expected_selection, ): fake_cube.selection = selection patch__create_dimensions.return_value = [ "a", "list", "of", "dimensions" ] patch__create_measures.return_value = ["some", "measures"] fake_cubes_calculate_cube_sync = Mock(return_value="your_cube_result") patch_aa_cubes_api.return_value = Mock( cubes_calculate_cube_synchronously=fake_cubes_calculate_cube_sync) expected_cube = aa.Cube( base_query=aa.Query(selection=expected_selection), resolve_table_name="Purchases", storage="Full", dimensions=["a", "list", "of", "dimensions"], measures=["some", "measures"], ) cube_result = fake_cube._get_cube() assert cube_result == "your_cube_result" patch_aa_cubes_api.assert_called_once_with("my_api_client") fake_cubes_calculate_cube_sync.assert_called_once_with( "acme_inc", "retail", cube=expected_cube)
def _get_export(self): export = aa.Export( base_query=aa.Query(selection=self.selection._to_model_selection( ) if self.selection is not None else aa.Selection( table_name=self.table.name)), resolve_table_name=self.table.name, maximum_number_of_rows_to_browse=self.max_rows, return_browse_rows=True, columns=self._create_columns(), ) exports_controller = aa.ExportsApi(self.session.api_client) export_result = exports_controller.exports_perform_export_synchronously( self.session.data_view, self.session.system, export=export) return export_result
def _get_cube(self): cube = aa.Cube( base_query=aa.Query(selection=self.selection._to_model_selection( ) if self.selection is not None else aa.Selection( table_name=self.table.name)), resolve_table_name=self.table.name, storage="Full", dimensions=self._create_dimensions(), measures=self._create_measures(), ) cubes_controller = aa.CubesApi(self.session.api_client) cube_result = cubes_controller.cubes_calculate_cube_synchronously( self.session.data_view, self.session.system, cube=cube) return cube_result
def test__get_export(self, patch__create_columns, patch_aa_exports_api, fake_datagrid): patch__create_columns.return_value = ["a", "list", "of", "columns"] fake_exports_perform_export_sync = Mock( return_value="your_export_result") patch_aa_exports_api.return_value = Mock( exports_perform_export_synchronously= fake_exports_perform_export_sync) expected_export = aa.Export( base_query=aa.Query(selection="selection_model"), resolve_table_name="Customers", maximum_number_of_rows_to_browse=1234, return_browse_rows=True, columns=["a", "list", "of", "columns"], ) export_result = fake_datagrid._get_export() assert export_result == "your_export_result" patch_aa_exports_api.assert_called_once_with("my_api_client") fake_exports_perform_export_sync.assert_called_once_with( "acme_inc", "retail", export=expected_export)
def test_cube(self): selection = aa.Selection(table_name="Flight Route", name="Blank Query", ancestor_counts=False) query = aa.Query(selection=selection) dimension = aa.Dimension( id="Dates", type="Selector", variable_name=REPORTING_PERIOD_YEARS_CODE, none_cell=True, omit_unclassified=True, ) dimension2 = aa.Dimension( id="Reporting Airport", type="Selector", variable_name=REPORTING_AIRPORT_CODE, none_cell=True, omit_unclassified=True, ) dimensions = [dimension, dimension2] measure = aa.Measure(id="Routes1", resolve_table_name="Flight Route", function="Count") cube = aa.Cube( base_query=query, resolve_table_name="Flight Route", storage="Full", dimensions=dimensions, measures=[measure], ) cube_api = aa.CubesApi(session.api_client) cube_calculation = cube_api.cubes_calculate_cube_synchronously( session.data_view, session.system, cube=cube) test_row = cube_calculation.measure_results[0].rows[7] self.assertEqual( test_row, "0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t179\t1633\t1765\t1896\t5473", )
def create_query(rule=None, top_n=None): """ Return query from selection, with possible given rule or top_n. """ return aa.Query( aa.Selection(table_name="Flight Route", rule=rule, top_n=top_n))
def count(self): query_final = aa.Query(selection=self._to_model_selection()) session = self.session return Selection(query_final, session).count
def count(self): query_final = aa.Query( selection=aa.Selection(table_name=self.name, ancestor_counts=True)) session = self.session return Selection(query_final, session).count