def test_sort_extra_data(self):
        """
        Tests that sorting on extra data takes the column type
        into account.
        """
        # arrange
        float_unit = Unit.objects.create(
            unit_name='test float unit',
            unit_type=FLOAT
        )

        ed_col_name = 'some float column'
        float_col = Column.objects.create(
            organization=self.org,
            column_name=ed_col_name,
            unit=float_unit,
        )

        test_mapping = ColumnMapping.objects.create(
            super_organization=self.org,
        )

        test_mapping.column_mapped.add(float_col)

        NUMBER_ACTIVE = 10  # if more than 10, then alpha sort puts 11 before 2
        NUMBER_PER_PAGE = 10
        for i in range(NUMBER_ACTIVE):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(
                organization=self.org,
                canonical_building=cb,
                tax_lot_id="%s" % i
            )
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.org
            b.extra_data = {
                ed_col_name: str(i * 13.17)
            }
            b.save()
        url = reverse_lazy("seed:search_buildings")
        post_data = {
            'filter_params': {},
            'number_per_page': NUMBER_PER_PAGE,
            'order_by': ed_col_name,
            'page': 1,
            'q': '',
            'sort_reverse': False,
            'project_id': None,
        }

        # act
        response = self.client.post(
            url,
            content_type='application/json',
            data=json.dumps(post_data)
        )
        json_string = response.content
        data = json.loads(json_string)

        # assert
        self.assertEqual(data['status'], 'success')

        float_col_data = map(lambda b: b['extra_data'][ed_col_name], data['buildings'])
        expected_data = map(
            lambda b: b.extra_data[ed_col_name],
            BuildingSnapshot.objects.order_by('pk')
        )

        self.assertEqual(float_col_data, expected_data)

        # sort reverse
        # arrange
        post_data['sort_reverse'] = True

        # act
        response = self.client.post(
            url,
            content_type='application/json',
            data=json.dumps(post_data)
        )
        json_string = response.content
        data = json.loads(json_string)

        # assert
        self.assertEqual(data['status'], 'success')

        float_col_data = map(lambda b: b['extra_data'][ed_col_name], data['buildings'])
        expected_data.reverse() # in-place mutation!

        self.assertEqual(float_col_data, expected_data)
dataset/ETHPy150Open buildingenergy/buildingenergy-platform/seed/tests/test_views.py/SearchViewTests.test_sort_extra_data/original