def test_get_object_bounding_box_single_cuboid(self): """ Test getting the bounding box of a object""" test_mat = np.ones((128, 128, 16)) test_mat[0:128, 0:128, 0:16] = 4 test_mat = test_mat.astype(np.uint64) test_mat = test_mat.reshape((16, 128, 128)) bb = blosc.compress(test_mat, typesize=64) # Create request factory = APIRequestFactory() request = factory.post('/' + version + '/cutout/col1/exp1/bbchan1/0/1536:1664/1536:1664/0:16/', bb, content_type='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='bbchan1', resolution='0', x_range='1536:1664', y_range='1536:1664', z_range='0:16', t_range=None) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # Create Request to get data you posted request = factory.get('/' + version + '/cutout/col1/exp1/bbchan1/0/1536:1664/1536:1664/0:16/', accepts='application/blosc') # log in user force_authenticate(request, user=self.user) # Make request response = Cutout.as_view()(request, collection='col1', experiment='exp1', channel='bbchan1', resolution='0', x_range='1536:1664', y_range='1536:1664', z_range='0:16', t_range=None).render() self.assertEqual(response.status_code, status.HTTP_200_OK) # Decompress raw_data = blosc.decompress(response.content) data_mat = np.fromstring(raw_data, dtype=np.uint64) data_mat = np.reshape(data_mat, (16, 128, 128), order='C') # Test for data equality (what you put in is what you got back!) np.testing.assert_array_equal(data_mat, test_mat) # get the bounding box # Create request factory = APIRequestFactory() request = factory.get('/' + version + '/boundingbox/col1/exp1/bbchan1/0/4') # log in user force_authenticate(request, user=self.user) # Make request response = BoundingBox.as_view()(request, collection='col1', experiment='exp1', channel='bbchan1', resolution='0', id='4') self.assertEqual(response.status_code, status.HTTP_200_OK) bb = response.data self.assertEqual(bb['t_range'], [0, 1]) self.assertEqual(bb['x_range'], [1536, 2048]) self.assertEqual(bb['y_range'], [1536, 2048]) self.assertEqual(bb['z_range'], [0, 16])
def test_reserve_id_resolves(self): """ Test that the bounding box urls resolve Returns: None """ match = resolve('/' + version + '/boundingbox/col1/exp1/channel1/0/10') self.assertEqual(match.func.__name__, BoundingBox.as_view().__name__)