def test_set_bytes_http_errors(self): gde = GirderDataElement('someId') gde.writable = mock.MagicMock(return_value=True) # Test access denied throws ReadOnlyError gde.gc.uploadFileContents = mock.MagicMock( side_effect=girder_client.HttpError(401, '', None, None)) self.assertRaises(ReadOnlyError, gde.set_bytes, b=b'foo') # Test any other error (like a 500) re-raises the HttpError gde.gc.uploadFileContents = mock.MagicMock( side_effect=girder_client.HttpError(500, '', None, None)) self.assertRaises(girder_client.HttpError, gde.set_bytes, b=b'foo')
def test_set_bytes_http_errors(self): gde = GirderDataElement('someId') gde.writable = mock.MagicMock(return_value=True) # Test access denied throws ReadOnlyError gde.gc.uploadFileContents = mock.MagicMock( side_effect=girder_client.HttpError(401, '', None, None)) self.assertRaises(ReadOnlyError, gde.set_bytes, b=b'foo') # Test any other error (like a 500) re-raises the HttpError gde.gc.uploadFileContents = mock.MagicMock( side_effect=girder_client.HttpError(500, '', None, None)) self.assertRaises(girder_client.HttpError, gde.set_bytes, b=b'foo')
def test_writable(self, m_getItem, m_getFolder, _m_get_file_model): m_getItem.return_value = {'folderId': 'someFolderId'} m_getFolder.return_value = {'_accessLevel': 1} self.assertTrue(GirderDataElement('someId').writable()) # Access level 0 should cause it to be unwritable m_getFolder.return_value = {'_accessLevel': 0} self.assertFalse(GirderDataElement('someId').writable()) # A nonexistent file model should make writable return false gde = GirderDataElement('someId') gde.get_file_model = mock.MagicMock(return_value=None) self.assertFalse(gde.writable())
def test_writable(self, m_getItem, m_getFolder, _m_get_file_model): m_getItem.return_value = {'folderId': 'someFolderId'} m_getFolder.return_value = {'_accessLevel': 1} self.assertTrue(GirderDataElement('someId').writable()) # Access level 0 should cause it to be unwritable m_getFolder.return_value = {'_accessLevel': 0} self.assertFalse(GirderDataElement('someId').writable()) # A nonexistent file model should make writable return false gde = GirderDataElement('someId') gde.get_file_model = mock.MagicMock(return_value=None) self.assertFalse(gde.writable())
def test_set_bytes_non_writable(self): gde = GirderDataElement('someId') gde.writable = mock.MagicMock(return_value=False) self.assertRaises(ReadOnlyError, gde.set_bytes, b=None)
def test_set_bytes(self, m_uploadFileContents): gde = GirderDataElement('someId') gde.writable = mock.MagicMock(return_value=True) gde.set_bytes(b'foo') m_uploadFileContents.assert_called_once()
def test_set_bytes_non_writable(self): gde = GirderDataElement('someId') gde.writable = mock.MagicMock(return_value=False) self.assertRaises(ReadOnlyError, gde.set_bytes, b=None)
def test_set_bytes(self, m_uploadFileContents): gde = GirderDataElement('someId') gde.writable = mock.MagicMock(return_value=True) gde.set_bytes(b'foo') m_uploadFileContents.assert_called_once()