def test_find_share_dimensions_with_a_multiple_share_operations( self, mock_fetch_data: Mock, mock_paginate: Mock ): mock_widget = f.Widget( Share(mock_dataset.fields.votes, over=mock_dataset.fields.state), Share(mock_dataset.fields.wins, over=mock_dataset.fields.state), ) mock_widget.transform = Mock() dimensions = ( mock_dataset.fields.timestamp, mock_dataset.fields.state, mock_dataset.fields.political_party, ) mock_dataset.query.widget(mock_widget).dimension(*dimensions).fetch() mock_fetch_data.assert_called_once_with( ANY, ANY, ANY, FieldMatcher(mock_dataset.fields.state), ANY )
def test_query_choices_for_field_with_display_hint_table( self, mock_get_column_definitions: Mock, mock_fetch_data: Mock ): mock_hint_dataset.fields.candidate_name.choices.fetch() mock_fetch_data.assert_called_once_with( ANY, [ PypikaQueryMatcher( "SELECT " '"candidate_name" "$candidate_name",' '"candidate_name_display" ' '"$candidate_name_display" ' 'FROM "politics"."hints" ' 'WHERE NOT "candidate_name" IS NULL ' 'GROUP BY "$candidate_name",' '"$candidate_name_display" ' 'ORDER BY "$candidate_name"' ) ], FieldMatcher(mock_hint_dataset.fields.candidate_name), )
def test_query_choices_for_join_dimension_with_filter_from_base( self, mock_get_column_definitions: Mock, mock_fetch_data: Mock ): mock_hint_dataset.fields["district-name"].choices.filter( mock_hint_dataset.fields.candidate_name.isin(["Bill Clinton"]) ).fetch() mock_fetch_data.assert_called_once_with( ANY, [ PypikaQueryMatcher( "SELECT " '"district_name" "$district-name" ' 'FROM "politics"."hints" ' "WHERE \"candidate_name\" IN ('Bill Clinton') " 'AND NOT "district_name" IS NULL ' 'GROUP BY "$district-name" ' 'ORDER BY "$district-name"' ) ], FieldMatcher(mock_hint_dataset.fields["district-name"]), )
def test_query_choices_for_filters_from_base( self, mock_get_column_definitions: Mock, mock_fetch_data: Mock ): mock_hint_dataset.fields.political_party.choices.filter( mock_hint_dataset.fields.candidate_name.isin(["Bill Clinton"]) ).filter(mock_hint_dataset.fields["election-year"].isin([1992])).fetch() mock_fetch_data.assert_called_once_with( ANY, [ PypikaQueryMatcher( "SELECT " '"political_party" "$political_party" ' 'FROM "politics"."hints" ' "WHERE \"candidate_name\" IN ('Bill Clinton') " 'AND NOT "political_party" IS NULL ' 'GROUP BY "$political_party" ' 'ORDER BY "$political_party"' ) ], FieldMatcher(mock_hint_dataset.fields.political_party), )
def test_query_choices_for_join_dimension_with_filter_from_join( self, mock_get_column_definitions: Mock, mock_fetch_data: Mock): mock_hint_dataset.fields["district-name"].choices.filter( mock_hint_dataset.fields["district-name"].isin(["Manhattan" ])).fetch() mock_fetch_data.assert_called_once_with( ANY, [ PypikaQueryMatcher("SELECT " '"hints"."district_name" "$district-name" ' 'FROM "politics"."hints" ' 'FULL OUTER JOIN "locations"."district" ON ' '"hints"."district_id"="district"."id" ' 'WHERE "district"."district_name" IN (' "'Manhattan') " 'AND NOT "hints"."district_name" IS NULL ' 'GROUP BY "$district-name" ' 'ORDER BY "$district-name"') ], FieldMatcher(mock_hint_dataset.fields["district-name"]), )
def test_fetch_annotation_invalid_first_dimension(self, mock_fetch_data: Mock): dims = [mock_date_annotation_dataset.fields.political_party] mock_date_annotation_dataset.query.widget( self.mock_widget).dimension(*dims).fetch() mock_fetch_data.assert_called_once_with( mock_date_annotation_dataset.database, [ PypikaQueryMatcher("SELECT " '"political_party" "$political_party",' 'SUM("votes") "$votes" ' 'FROM "politics"."politician" ' 'GROUP BY "$political_party" ' 'ORDER BY "$political_party" ' 'LIMIT 200000') ], FieldMatcher(*dims), [], [], )
def test_query_choices_for_case_filter( self, mock_get_column_definitions: Mock, mock_fetch_data: Mock ): mock_hint_dataset.fields.political_party.choices.filter( mock_hint_dataset.fields.political_party_case.isin( ["Democrat", "Bill Clinton"] ) ).fetch() mock_fetch_data.assert_called_once_with( ANY, [ PypikaQueryMatcher( "SELECT " '"political_party" "$political_party" ' 'FROM "politics"."hints" ' 'WHERE NOT "political_party" IS NULL ' 'GROUP BY "$political_party" ' 'ORDER BY "$political_party"' ) ], FieldMatcher(mock_hint_dataset.fields.political_party), )
def test_query_choices_for_filters_from_joins( self, mock_get_column_definitions: Mock, mock_fetch_data: Mock ): mock_hint_dataset.fields.political_party.choices.filter( mock_hint_dataset.fields["district-name"].isin(["Manhattan"]) ).filter(mock_hint_dataset.fields["state"].isin(["Texas"])).fetch() mock_fetch_data.assert_called_once_with( ANY, [ PypikaQueryMatcher( "SELECT " '"hints"."political_party" "$political_party" ' 'FROM "politics"."hints" ' 'JOIN "locations"."state" ON ' '"hints"."state_id"="state"."id" ' 'WHERE "state"."state_name" IN (\'Texas\') ' 'AND NOT "hints"."political_party" IS NULL ' 'GROUP BY "$political_party" ' 'ORDER BY "$political_party"' ) ], FieldMatcher(mock_hint_dataset.fields.political_party), )