def test_remap_fields(self, mock_get_model): mock_get_model.return_value = self.content_unit_model content.remap_fields_with_serializer(self.content_unit) self.assertTrue('type_specific_id' not in self.content_unit, 'type-specific ID field not remapped') self.assertTrue('id' in self.content_unit) self.assertEqual(self.content_unit['id'], 'foo')
def _generate_response(cls, query, options, *args, **kwargs): """ Perform the database query using the given search data, and return the resuls as a JSON serialized HttpReponse object. This overrides the base class so we can validate repo existance and to choose the search method depending on how many unit types we are dealing with. :param query: The criteria that should be used to search for objects :type query: dict :param options: additional options for including extra data :type options: dict :return: The serialized search results in an HttpReponse :rtype: django.http.HttpResponse """ repo_id = kwargs.get('repo_id') model.Repository.objects.get_repo_or_missing_resource(repo_id) criteria = UnitAssociationCriteria.from_client_input(query) manager = manager_factory.repo_unit_association_query_manager() if criteria.type_ids is not None and len(criteria.type_ids) == 1: type_id = criteria.type_ids[0] units = manager.get_units_by_type(repo_id, type_id, criteria=criteria) else: units = manager.get_units(repo_id, criteria=criteria) for unit in units: content.remap_fields_with_serializer(unit['metadata']) return generate_json_response_with_pulp_encoder(units)
def test_remap_fields(self, mock_get_model): mock_get_model.return_value = self.content_unit_model content.remap_fields_with_serializer(self.content_unit) self.assertTrue('type_specific_id' not in self.content_unit, 'type-specific ID field not remapped') self.assertTrue('id' in self.content_unit) self.assertEqual(self.content_unit['id'], 'foo')