def test_get_renamed_fields_no_renaming(self): """ Test when not renaming fields, returns an empty dictionary """ group_by = GroupBy( query_param="test", fields="id", queryset=self.queryset, ) self.assertEquals(bool(group_by.get_renamed_fields()), False)
def test_get_renamed_fields_with_renaming(self): """ Test when renaming fields, returns a key-value with renamed-actual """ group_by = GroupBy( query_param="test", fields="id", renamed_fields="id_renamed", queryset=self.queryset, ) renamed_fields = group_by.get_renamed_fields() self.assertEqual(len(renamed_fields), 1) self.assertItemsEqual(renamed_fields.keys(), ["id_renamed"])
def test_get_renamed_fields_partly(self): """ Test renaming only a few of the fields also works """ group_by = GroupBy( query_param="test", fields=("id", "name"), renamed_fields="id_renamed", queryset=self.queryset, ) renamed_fields = group_by.get_renamed_fields() self.assertEqual(len(renamed_fields), 1) self.assertCountEqual(renamed_fields.keys(), ["id_renamed"])
def test_get_renamed_fields_with_multiple_renaming(self): """ Test when renaming multiple fields, returns a key-value with renamed-actual """ group_by = GroupBy( query_param="test", fields=("id", "name"), renamed_fields=("id_renamed", "name_renamed"), queryset=self.queryset, ) renamed_fields = group_by.get_renamed_fields() self.assertEqual(len(renamed_fields), 2) self.assertCountEqual(renamed_fields.keys(), [ "id_renamed", "name_renamed"])