Exemplo n.º 1
0
    def test_put_content_unit_user_metadata_resource(self, mock_factory,
                                                     mock_resp):
        request = mock.MagicMock()
        request.body_as_json = 'mock_data'
        mock_cm = mock_factory.content_manager()

        metadata_resource = ContentUnitUserMetadataResourceView()
        response = metadata_resource.put(request, 'mock_type', 'mock_unit')

        mock_delta = {constants.PULP_USER_METADATA_FIELDNAME: 'mock_data'}
        mock_cm.update_content_unit.assert_called_once_with(
            'mock_type', 'mock_unit', mock_delta)
        mock_resp.assert_called_with(None)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 2
0
    def test_put_content_unit_user_metadata_resource_no_unit(self, mock_factory, mock_resp):
        """
        View should return a response not found and a helpful message when unit is not found.
        """
        request = mock.MagicMock()
        request.body = json.dumps('')
        mock_cqm = mock_factory.content_query_manager()
        mock_cqm.get_content_unit_by_id.side_effect = MissingResource()

        metadata_resource = ContentUnitUserMetadataResourceView()
        response = metadata_resource.put(request, 'mock_type', 'mock_unit')

        msg = _('No content unit resource: mock_unit')
        mock_resp.assert_called_once_with(msg, HttpResponseNotFound)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 3
0
    def test_put_content_unit_user_metadata_resource(self, mock_factory, mock_resp):
        """
        Test update content unit user metdata resource.
        """
        request = mock.MagicMock()
        request.body = json.dumps('mock_data')
        mock_cm = mock_factory.content_manager()

        metadata_resource = ContentUnitUserMetadataResourceView()
        response = metadata_resource.put(request, 'mock_type', 'mock_unit')

        mock_delta = {constants.PULP_USER_METADATA_FIELDNAME: 'mock_data'}
        mock_cm.update_content_unit.assert_called_once_with('mock_type', 'mock_unit', mock_delta)
        mock_resp.assert_called_with(None)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 4
0
    def test_put_content_unit_user_metadata_resource_no_unit(
            self, mock_factory, mock_resp):
        """
        View should return a response not found and a helpful message when unit is not found.
        """
        request = mock.MagicMock()
        mock_cqm = mock_factory.content_query_manager()
        mock_cqm.get_content_unit_by_id.side_effect = MissingResource()

        metadata_resource = ContentUnitUserMetadataResourceView()
        response = metadata_resource.put(request, 'mock_type', 'mock_unit')

        msg = _('No content unit resource: mock_unit')
        mock_resp.assert_called_once_with(msg, HttpResponseNotFound)
        self.assertTrue(response is mock_resp.return_value)