Exemplo n.º 1
0
 def test_no_options(self):
     ''' Tests if a default tooltip text is set for all items if no options are given '''
     BaseMap().get_tooltip_data(self.DATAFRAME.copy(), {}, None)
     self.assertEqual(
         BaseMap().get_tooltip_data(self.DATAFRAME.copy(), {},
                                    None).to_dict(orient="records"),
         [{
             'cd_mun_ibge': 123456,
             'tooltip': "Tooltip!"
         }, {
             'cd_mun_ibge': 234567,
             'tooltip': "Tooltip!"
         }])
Exemplo n.º 2
0
    def test_headers_custom_fields(self):
        ''' Tests if a default tooltip text is set for all items if no headers are given '''
        dataframe = self.DATAFRAME.rename(
            columns={
                'cd_mun_ibge': 'cd_m',
                'nm_municipio': 'nm_m',
                'latitude': 'lat',
                'longitude': 'long'
            })

        expect = self.EXPECT.copy()
        for item in expect:
            item['cd_m'] = item['cd_mun_ibge']
            del item['cd_mun_ibge']

        self.assertEqual(
            BaseMap().get_tooltip_data(
                dataframe, {
                    'id_field': 'cd_m',
                    'name_field': 'nm_m',
                    'lat': 'lat',
                    'long': 'long'
                }, {
                    "headers": [{
                        'text': 'Municipio:',
                        'value': 'nm_m'
                    }, {
                        'text': 'Valor A:',
                        'value': 'A_vl_indicador'
                    }, {
                        'text': 'Valor B:',
                        'value': 'B_vl_indicador'
                    }]
                }).to_dict(orient="records"), expect)
Exemplo n.º 3
0
 def test_existing_description(self):
     ''' Tests if returns the expected header build using card description options '''
     options = {'description': self.BASE_DESCRIPTION}
     expect = [{'text': '', 'value': 'au_field'}]
     expect.extend(self.BASE_EXPECT)
     self.assertEqual(
         BaseMap.get_headers({'name_field': 'au_field'}, options), expect)
Exemplo n.º 4
0
 def test_prepare_no_id_field(self):
     ''' Tests if dataframe returns default options if no identifier is given '''
     result = BaseMap.prepare_dataframe(self.DATAFRAME.copy(), {})
     self.assertEqual(result.copy().to_dict(orient="records"),
                      [{
                          "cd_mun_ibge": 123456,
                          'cd_indicador': 1,
                          'str_id': '123456'
                      }, {
                          "cd_mun_ibge": 234567,
                          'cd_indicador': 2,
                          'str_id': '234567'
                      }, {
                          "cd_mun_ibge": 345678,
                          'cd_indicador': 3,
                          'str_id': '345678'
                      }])
     result = result.reset_index()
     self.assertEqual(result.to_dict(orient="records"), [{
         "cd_mun_ibge": 123456,
         'cd_indicador': 1,
         'idx': 123456,
         'str_id': '123456'
     }, {
         "cd_mun_ibge": 234567,
         'cd_indicador': 2,
         'idx': 234567,
         'str_id': '234567'
     }, {
         "cd_mun_ibge": 345678,
         'cd_indicador': 3,
         'idx': 345678,
         'str_id': '345678'
     }])
Exemplo n.º 5
0
 def test_given_lat_long(self):
     ''' Tests lat and long columns retrieval, with no given value column definition '''
     self.assertEqual(
         BaseMap.get_location_columns({
             'lat': 'latitude',
             'long': 'longitude'
         }), ['latitude', 'longitude'])
Exemplo n.º 6
0
    def test_simple_return(self):
        ''' Simple test using parameters from each method invoke made in
            pre_draw '''
        (dataframe, folium_map,
         options) = BaseMap().pre_draw(self.DATAFRAME.copy(), {},
                                       {'headers': {
                                           'name': 'test'
                                       }}, None)

        self.assertEqual(dataframe.to_dict(orient="records"),
                         [{
                             "cd_mun_ibge": 123456,
                             'cd_indicador': 1,
                             'str_id': '123456'
                         }, {
                             "cd_mun_ibge": 234567,
                             'cd_indicador': 2,
                             'str_id': '234567'
                         }, {
                             "cd_mun_ibge": 345678,
                             'cd_indicador': 3,
                             'str_id': '345678'
                         }])
        self.assertTrue(isinstance(folium_map, FoliumMap))
        self.assertEqual(options, {'headers': {'name': 'test'}})
Exemplo n.º 7
0
 def test_existing_description_default_au_field(self):
     ''' Tests if returns the expected result, with default 'nm_municipio' header
         when there's no name_field attribute in chart_options '''
     options = {'description': self.BASE_DESCRIPTION}
     expect = [{'text': '', 'value': 'nm_municipio'}]
     expect.extend(self.BASE_EXPECT)
     self.assertEqual(BaseMap.get_headers({}, options), expect)
Exemplo n.º 8
0
 def test_given_lat_long_val(self):
     ''' Tests lat, long and value columns retrieval '''
     self.assertEqual(
         BaseMap.get_location_columns({
             'lat': 'latitude',
             'long': 'longitude',
             'value_field': 'val'
         }), ['latitude', 'longitude', 'val'])
Exemplo n.º 9
0
 def test_au_title_valid(self):
     ''' Tests if the title is generated correctly '''
     self.assertEqual(
         BaseMap().get_au_title({'field': 'field_value'},
                                [{
                                    'value': 'field'
                                }, {
                                    'value': 'field_2'
                                }]), "field_value")
Exemplo n.º 10
0
 def test_existing_description_no_chart_options(self):
     ''' Tests if returns the expected result, with default 'nm_municipio' header
         when no chart_option is sent '''
     options = {'description': self.BASE_DESCRIPTION}
     self.assertEqual(BaseMap.get_headers(None, options),
                      [{
                          'text': '',
                          'value': 'nm_municipio'
                      }])
Exemplo n.º 11
0
 def test_existing_headers_over_description(self):
     ''' Tests if headers prevails when there's also description option '''
     options = {
         'headers': {
             'name': 'test'
         },
         'description': self.BASE_DESCRIPTION
     }
     self.assertEqual(
         BaseMap.get_headers({'name_field': 'au_field'}, options),
         options.get('headers'))
Exemplo n.º 12
0
 def test_headers(self):
     ''' Tests if a default tooltip text is set for all items if no headers are given '''
     self.assertEqual(
         BaseMap().get_tooltip_data(self.DATAFRAME.copy(), {}, {
             "headers": [{
                 'text': 'Municipio:',
                 'value': 'nm_municipio'
             }, {
                 'text': 'Valor A:',
                 'value': 'A_vl_indicador'
             }, {
                 'text': 'Valor B:',
                 'value': 'B_vl_indicador'
             }]
         }).to_dict(orient="records"), self.EXPECT)
Exemplo n.º 13
0
 def test_prepare_id_field(self):
     ''' Tests if dataframe returns dataframe with index and stringified index
         accrding to given id field '''
     result = BaseMap.prepare_dataframe(self.DATAFRAME.copy(),
                                        {"id_field": "cd_indicador"})
     self.assertEqual(result.copy().to_dict(orient="records"),
                      [{
                          "cd_mun_ibge": 123456,
                          'cd_indicador': 1,
                          'str_id': '1'
                      }, {
                          "cd_mun_ibge": 234567,
                          'cd_indicador': 2,
                          'str_id': '2'
                      }, {
                          "cd_mun_ibge": 345678,
                          'cd_indicador': 3,
                          'str_id': '3'
                      }])
     result = result.reset_index()
     self.assertEqual(result.to_dict(orient="records"), [{
         "cd_mun_ibge": 123456,
         'cd_indicador': 1,
         'idx': 1,
         'str_id': '1'
     }, {
         "cd_mun_ibge": 234567,
         'cd_indicador': 2,
         'idx': 2,
         'str_id': '2'
     }, {
         "cd_mun_ibge": 345678,
         'cd_indicador': 3,
         'idx': 3,
         'str_id': '3'
     }])
Exemplo n.º 14
0
 def test_default_lat_long_no_options(self):
     ''' Tests for default lat and long fields, with no value column definition,
         when no chart_options is given '''
     self.assertEqual(BaseMap.get_location_columns(None), ['lat', 'long'])
Exemplo n.º 15
0
 def test_existing_headers(self):
     ''' Tests if returns the existing headers AS-IS '''
     options = {'headers': {'name': 'test'}}
     self.assertEqual(
         BaseMap.get_headers({'name_field': 'au_field'}, options),
         options.get('headers'))
Exemplo n.º 16
0
 def test_existing_headers_no_chart_options(self):
     ''' Tests if returns the existing headers AS-IS '''
     options = {'headers': {'name': 'test'}}
     self.assertEqual(BaseMap.get_headers(None, options),
                      options.get('headers'))
Exemplo n.º 17
0
 def test_prepare_no_options(self):
     ''' Tests if dataframe returns AS-IS if no options are given '''
     self.assertEqual(
         BaseMap.prepare_dataframe(self.DATAFRAME.copy(),
                                   None).to_dict(orient="records"),
         self.DATAFRAME.copy().to_dict(orient="records"))
Exemplo n.º 18
0
 def test_au_title_no_data(self):
     ''' Tests if default title is returned when row object is None '''
     self.assertEqual(BaseMap.get_au_title(None, [{
         'value': 'field'
     }]), self.DEFAULT_TITLE)
Exemplo n.º 19
0
 def test_au_title_empty_headers(self):
     ''' Tests if default title is returned when empty header is given '''
     self.assertEqual(BaseMap.get_au_title({'field': 'field_value'}, []),
                      self.DEFAULT_TITLE)
Exemplo n.º 20
0
 def test_default_lat_long(self):
     ''' Tests for default lat and long fields, with no value column definition '''
     self.assertEqual(BaseMap.get_location_columns({}), ['lat', 'long'])
Exemplo n.º 21
0
 def test_au_title_no_headers(self):
     ''' Tests if default title is returned when no headers are given '''
     self.assertEqual(BaseMap.get_au_title({'field': 'field_value'}, None),
                      self.DEFAULT_TITLE)
Exemplo n.º 22
0
 def test_default_lat_long_value(self):
     ''' Tests for default lat and long fields, with given value column definition '''
     self.assertEqual(BaseMap.get_location_columns({'value_field': 'val'}),
                      ['lat', 'long', 'val'])