def test_get_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.get(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)
def test_get_content_unit_user_metadata_resource(self, mock_factory, mock_resp, mock_serial): """ View should return a response contains user metadata """ mock_unit = {constants.PULP_USER_METADATA_FIELDNAME: 'mock_metadata'} mock_cqm = mock_factory.content_query_manager() mock_cqm.get_content_unit_by_id.return_value = mock_unit mock_serial.content_unit_obj.return_value = 'mock_serial_metadata' request = mock.MagicMock() metadata_resource = ContentUnitUserMetadataResourceView() response = metadata_resource.get(request, 'mock_type', 'mock_unit') mock_serial.content_unit_obj.assert_called_once_with('mock_metadata') expected_content = 'mock_serial_metadata' mock_resp.assert_called_once_with(expected_content) self.assertTrue(response is mock_resp.return_value)