def test_get_file_model(self, m_getFile): # Check static expected values in model. This happens to be actual # return values, however we are mocking out any actual network # communication. expected_m = { '_id': self.EXAMPLE_ITEM_ID, '_modelType': 'file', 'exts': ['png'], 'mimeType': 'image/png', 'name': 'Lenna.png', 'sha512': self.EXAMPLE_SHA512, 'size': 473831 } m_getFile.return_value = expected_m e = GirderDataElement(self.EXAMPLE_ITEM_ID, self.EXAMPLE_GIRDER_API_ROOT) m = e.get_file_model() self.assertEqual(m['_id'], expected_m['_id']) self.assertEqual(m['_modelType'], expected_m['_modelType']) self.assertEqual(m['exts'], expected_m['exts']) self.assertEqual(m['mimeType'], expected_m['mimeType']) self.assertEqual(m['name'], expected_m['name']) self.assertEqual(m['sha512'], expected_m['sha512']) self.assertEqual(m['size'], expected_m['size'])
def test_get_file_model(self, m_getFile): # Check static expected values in model. This happens to be actual # return values, however we are mocking out any actual network # communication. expected_m = { '_id': self.EXAMPLE_ITEM_ID, '_modelType': 'file', 'exts': ['png'], 'mimeType': 'image/png', 'name': 'Lenna.png', 'sha512': self.EXAMPLE_SHA512, 'size': 473831 } m_getFile.return_value = expected_m e = GirderDataElement(self.EXAMPLE_ITEM_ID, self.EXAMPLE_GIRDER_API_ROOT) m = e.get_file_model() self.assertEqual(m['_id'], expected_m['_id']) self.assertEqual(m['_modelType'], expected_m['_modelType']) self.assertEqual(m['exts'], expected_m['exts']) self.assertEqual(m['mimeType'], expected_m['mimeType']) self.assertEqual(m['name'], expected_m['name']) self.assertEqual(m['sha512'], expected_m['sha512']) self.assertEqual(m['size'], expected_m['size'])
def test_get_file_model(self, m_gtm, m_requests): # Check static expected values in model. This happens to be actual # return values, however we are mocking out any actual network # communication. expected_m = { '_id': self.EXAMPLE_ITEM_ID, '_modelType': 'file', 'exts': ['png'], 'mimeType': 'image/png', 'name': 'Lenna.png', 'sha512': self.EXAMPLE_SHA512, 'size': 473831 } # as if a successful call m_requests.get().configure_mock(status_code=200) m_requests.get().json.return_value = expected_m e = GirderDataElement(self.EXAMPLE_ITEM_ID, self.EXAMPLE_GIRDER_API_ROOT) m = e.get_file_model() nose.tools.assert_equal(m['_id'], expected_m['_id']) nose.tools.assert_equal(m['_modelType'], expected_m['_modelType']) nose.tools.assert_equal(m['exts'], expected_m['exts']) nose.tools.assert_equal(m['mimeType'], expected_m['mimeType']) nose.tools.assert_equal(m['name'], expected_m['name']) nose.tools.assert_equal(m['sha512'], expected_m['sha512']) nose.tools.assert_equal(m['size'], expected_m['size'])
def test_get_file_model_item_no_exists(self, m_getFile): def raise_http_error(*_, **__): raise girder_client.HttpError(None, None, None, None) m_getFile.side_effect = raise_http_error e = GirderDataElement('foo', self.EXAMPLE_GIRDER_API_ROOT) m = e.get_file_model() self.assertIsNone(m)
def test_get_file_model_item_no_exists(self, m_gtm, m_requests): # i.e. status 400 returned, should return None m_requests.get().configure_mock(status_code=400) e = GirderDataElement('id') m = e.get_file_model() nose.tools.assert_is_none(m) nose.tools.assert_equal(m_requests.get().raise_for_status.call_count, 0)
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_is_empty_nonzero_bytes(self): e = GirderDataElement('someId') e.get_file_model = mock.MagicMock(return_value={'size': 7}) self.assertFalse(e.is_empty())
def test_is_empty_zero_size(self): # Uses model return size parameter e = GirderDataElement('someId') e.get_file_model = mock.MagicMock(return_value={'size': 0}) self.assertTrue(e.is_empty())
def test_is_empty_none_model(self): # Uses model return, empty if no model return (no item in girder by # ID) e = GirderDataElement('someId') e.get_file_model = mock.MagicMock(return_value=None) self.assertTrue(e.is_empty())
def test_is_empty_nonzero_bytes(self): e = GirderDataElement('someId') e.get_file_model = mock.MagicMock(return_value={'size': 7}) self.assertFalse(e.is_empty())
def test_is_empty_zero_size(self): # Uses model return size parameter e = GirderDataElement('someId') e.get_file_model = mock.MagicMock(return_value={'size': 0}) self.assertTrue(e.is_empty())
def test_is_empty_none_model(self): # Uses model return, empty if no model return (no item in girder by # ID) e = GirderDataElement('someId') e.get_file_model = mock.MagicMock(return_value=None) self.assertTrue(e.is_empty())