Ejemplo n.º 1
0
    def get(self, request, type_id, unit_id):
        """
        Return a response containing information about the requested content unit.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param type_id: type of content contained in the repo
        :type  type_id: str
        :param unit_id: unique id of a unit
        :type  unit_id: str

        :return: response containing a dict with data about requested unit
        :rtype : django.http.HttpResponse
        """
        cqm = factory.content_query_manager()
        try:
            unit = cqm.get_content_unit_by_id(type_id, unit_id)
        except MissingResource:
            msg = _('No content unit resource: %(r)s') % {'r': unit_id}
            return generate_json_response(msg,
                                          response_class=HttpResponseNotFound)

        resource = serial_content.content_unit_obj(unit)
        resource.update({
            'children':
            serial_content.content_unit_child_link_objs(resource)
        })
        return generate_json_response_with_pulp_encoder(resource)
Ejemplo n.º 2
0
 def test_serialization(self, mock):
     dt = datetime(2012, 10, 24, 10, 20, tzinfo=dateutils.utc_tz())
     last_updated = dateutils.datetime_to_utc_timestamp(dt)
     unit = {'_last_updated': last_updated}
     serialized = content.content_unit_obj(unit)
     mock.assert_called_once_with(unit)
     self.assertTrue(LAST_UPDATED in serialized)
     self.assertEqual(serialized[LAST_UPDATED], '2012-10-24T10:20:00Z')
Ejemplo n.º 3
0
 def test_serialization(self, mock):
     dt = datetime(2012, 10, 24, 10, 20, tzinfo=dateutils.utc_tz())
     last_updated = dateutils.datetime_to_utc_timestamp(dt)
     unit = {'_last_updated': last_updated}
     serialized = content.content_unit_obj(unit)
     mock.assert_called_once_with(unit)
     self.assertTrue(LAST_UPDATED in serialized)
     self.assertEqual(serialized[LAST_UPDATED], '2012-10-24T10:20:00Z')
Ejemplo n.º 4
0
def _process_content_unit(content_unit, content_type):
    """
    Adds an href to the content unit and hrefs for its children.

    :param content_unit: content unit to serialize
    :type  content_unit: dict
    :param content_type: type of content_unit
    :type  content_type: str

    :return: serialized unit
    :rtype:  dict
    """
    unit = serial_content.content_unit_obj(content_unit)
    unit["_href"] = reverse("content_unit_resource", kwargs={"type_id": content_type, "unit_id": content_unit["_id"]})
    unit.update({"children": serial_content.content_unit_child_link_objs(unit)})
    return unit
Ejemplo n.º 5
0
def _process_content_unit(content_unit, content_type):
    """
    Adds an href to the content unit and hrefs for its children.

    :param content_unit: content unit to serialize
    :type  content_unit: dict
    :param content_type: type of content_unit
    :type  content_type: str

    :return: serialized unit
    :rtype:  dict
    """
    unit = serial_content.content_unit_obj(content_unit)
    unit['_href'] = reverse(
        'content_unit_resource',
        kwargs={'type_id': content_type, 'unit_id': content_unit['_id']}
    )
    unit.update({'children': serial_content.content_unit_child_link_objs(unit)})
    return unit
Ejemplo n.º 6
0
    def get(self, request, type_id, unit_id):
        """
        Return user metadata for a content unit.

        :param type_id: The Unit's type id.
        :type  type_id: basestring
        :param unit_id: The id of the unit that you wish to set the pulp_user_metadata field on
        :type  unit_id: basestring

        :return: response containing pulp user metadata field
        :rtype: django.http.HttpResponse or HttpResponseNotFound
        """
        cqm = factory.content_query_manager()
        try:
            unit = cqm.get_content_unit_by_id(type_id, unit_id)
        except MissingResource:
            msg = _("No content unit resource: %(r)s") % {"r": unit_id}
            return generate_json_response(msg, HttpResponseNotFound)

        resource = serial_content.content_unit_obj(unit[constants.PULP_USER_METADATA_FIELDNAME])
        return generate_json_response(resource)
Ejemplo n.º 7
0
def _process_content_unit(content_unit, content_type):
    """
    Adds an href to the content unit and hrefs for its children.

    :param content_unit: content unit to serialize
    :type  content_unit: dict
    :param content_type: type of content_unit
    :type  content_type: str

    :return: serialized unit
    :rtype:  dict
    """
    unit = serial_content.content_unit_obj(content_unit)
    unit['_href'] = reverse('content_unit_resource',
                            kwargs={
                                'type_id': content_type,
                                'unit_id': content_unit['_id']
                            })
    unit.update(
        {'children': serial_content.content_unit_child_link_objs(unit)})
    return unit
Ejemplo n.º 8
0
    def get(self, request, type_id, unit_id):
        """
        Return user metadata for a content unit.

        :param type_id: The Unit's type id.
        :type  type_id: basestring
        :param unit_id: The id of the unit that you wish to set the pulp_user_metadata field on
        :type  unit_id: basestring

        :return: response containing pulp user metadata field
        :rtype: django.http.HttpResponse or HttpResponseNotFound
        """
        cqm = factory.content_query_manager()
        try:
            unit = cqm.get_content_unit_by_id(type_id, unit_id)
        except MissingResource:
            msg = _('No content unit resource: %(r)s') % {'r': unit_id}
            return generate_json_response(msg, HttpResponseNotFound)

        resource = serial_content.content_unit_obj(
            unit[constants.PULP_USER_METADATA_FIELDNAME])
        return generate_json_response(resource)
Ejemplo n.º 9
0
    def get(self, request, type_id, unit_id):
        """
        Return a response containing information about the requested content unit.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param type_id: type of content contained in the repo
        :type  type_id: str
        :param unit_id: unique id of a unit
        :type  unit_id: str

        :return: response containing a dict with data about requested unit
        :rtype : django.http.HttpResponse
        """
        cqm = factory.content_query_manager()
        try:
            unit = cqm.get_content_unit_by_id(type_id, unit_id)
        except MissingResource:
            msg = _("No content unit resource: %(r)s") % {"r": unit_id}
            return generate_json_response(msg, response_class=HttpResponseNotFound)

        resource = serial_content.content_unit_obj(unit)
        resource.update({"children": serial_content.content_unit_child_link_objs(resource)})
        return generate_json_response_with_pulp_encoder(resource)
Ejemplo n.º 10
0
 def test_serialization_no_last_modified(self):
     serialized = content.content_unit_obj({})
     self.assertFalse(LAST_UPDATED in serialized)
Ejemplo n.º 11
0
 def test_serialization_no_last_modified(self):
     serialized = content.content_unit_obj({})
     self.assertFalse(LAST_UPDATED in serialized)