Example #1
0
    def test_post_uploads_collection_view(self, mock_factory, mock_reverse,
                                          mock_resp, mock_redirect):
        """
        View post should return a response that contains data for a new upload.
        """
        mock_upload_manager = mock.MagicMock()
        mock_upload_manager.initialize_upload.return_value = 'mock_id'
        mock_factory.content_upload_manager.return_value = mock_upload_manager

        request = mock.MagicMock()
        request.body = None
        mock_reverse.return_value = '/mock/path/'

        content_types_view = UploadsCollectionView()
        response = content_types_view.post(request)

        self.assertTrue(mock_upload_manager.initialize_upload.called)

        mock_resp.assert_called_once_with({
            'upload_id': 'mock_id',
            '_href': '/mock/path/'
        })
        mock_redirect.assert_called_once_with(mock_resp.return_value,
                                              '/mock/path/')
        self.assertTrue(response is mock_redirect.return_value)
Example #2
0
    def test_get_uploads_collection_view(self, mock_factory, mock_resp):
        """
        View should return an response that contains a serialized dict with a list of upload_ids.
        """
        mock_upload_manager = mock.MagicMock()
        mock_upload_manager.list_upload_ids.return_value = ['mock_upload_1', 'mock_upload_2']
        mock_factory.content_upload_manager.return_value = mock_upload_manager
        request = mock.MagicMock()

        content_types_view = UploadsCollectionView()
        response = content_types_view.get(request)

        expected_content = {'upload_ids': ['mock_upload_1', 'mock_upload_2']}
        mock_resp.assert_called_once_with(expected_content)
        self.assertTrue(response is mock_resp.return_value)