def test_server_failed_part(self): """Test a failing server for a specific part This function tests a failed submit on the server side (i.e. code returned is not 200) for a specified part. """ # Dummy UUID and part number for testing uuid = 'BLAH' part = 3 # Use REST proxy for testing rest = _RestProxyForTest() # Set expected 'GET' request with 404 error rest.expect_get(self._base + '/batch/' + uuid + '/' + str(part), 404, {}) # Initiate Batch class batch = Batch() # Set UUID, parts count, and overall calc state (as 'RUNNING') batch._uuid = uuid batch._parts_count = 10 batch._calc_state = 'COMPLETED' # Override network access with proxy batch.set_rest_accessor(rest) # Assert that a 404 error code will raise a RuntimeError with self.assertRaises(RuntimeError): batch.get_part_state(part)
def test_part_not_in_range(self): """Test a part not in the part range This function tests that a part not within its range will raise an error. """ # Dummy UUID and part number for testing uuid = 'BLAH' part = 15 # Use REST proxy for testing rest = _RestProxyForTest() # Initiate Batch class batch = Batch() # Set UUID, parts count, and overall calc state (as 'RUNNING') batch._uuid = uuid batch._parts_count = 10 batch._calc_state = 'COMPLETED' # Override network access with proxy batch.set_rest_accessor(rest) # Assert that a part outside its range will return an IndexError with self.assertRaises(IndexError): batch.get_part_state(part)
def test_is_not_ready_part(self): """Test when an individual part is not ready This function tests that a job will correctly indicate when a part is not ready. """ # Dummy UUID and part number for testing uuid = 'BLAH' part = 3 # Use REST proxy for testing rest = _RestProxyForTest() # Set expected 'GET' request with calc_state as 'RUNNING' rest.expect_get(self._base + '/batch/' + uuid + '/' + str(part), 200, { 'calc_state': 'RUNNING', 'part_index': part }) # Initiate Batch class batch = Batch() # Set UUID, parts count, and overall calc state (as 'RUNNING') batch._uuid = uuid batch._parts_count = 10 batch._calc_state = 'RUNNING' # Override network access with proxy batch.set_rest_accessor(rest) # Assert that checking if the part is ready will return False self.assertFalse(batch.is_ready_part(part))
def test_get_ephemeris(self): """Test that an ephemeris is returned if the job has completed successfully This function tests that a job that is completed successfully will return the expected ephemeris. """ # Dummy UUID and part number for testing uuid = 'BLAH' part = 3 # Use REST proxy for testing rest = _RestProxyForTest() # Set expected 'GET' request with calc_state as 'COMPLETED' for specific part rest.expect_get( self._base + '/batch/' + uuid + '/' + str(part), 200, { 'calc_state': 'COMPLETED', 'error': 'No error!', 'stk_ephemeris': 'something', 'part_index': part }) # Initiate Batch class batch = Batch() # Set UUID, parts count, and overall calc state (as 'COMPLETED') batch._uuid = uuid batch._parts_count = 10 batch._calc_state = 'COMPLETED' # Override network access with proxy batch.set_rest_accessor(rest) # Assert that an overall calc state as 'COMPLETED' will return the expected ephemeris self.assertEqual(batch.get_part_ephemeris(part), 'something') # Assert that the error is as expected self.assertEqual(batch.get_part_error(part), 'No error!') # Assert that the calc state for the specific part's run is as expected self.assertEqual(batch.get_part_state(part), 'COMPLETED') # Assert that checking if the part is ready will return True self.assertTrue(batch.is_ready_part(part))
def test_is_ready_failed_part(self): """Test when an individual part has failed This function tests that a job will correctly indicate when a part has failed, that it returns the expected error, and that it returns None for ephemeris. """ # Dummy UUID and part number for testing uuid = 'BLAH' part = 3 # Use REST proxy for testing rest = _RestProxyForTest() # Set expected 'GET' request with calc_state as 'FAILED' rest.expect_get(self._base + '/batch/' + uuid + '/' + str(part), 200, { 'calc_state': 'FAILED', 'error': 'Some error', 'part_index': part }) # Initiate Batch class batch = Batch() # Set UUID, parts count, and overall calc state (as 'FAILED') batch._uuid = uuid batch._parts_count = 10 batch._calc_state = 'FAILED' # Override network access with proxy batch.set_rest_accessor(rest) # Assert that the calc state for the specific part's run is as expected self.assertEqual(batch.get_part_state(part), 'FAILED') # Assert that the error returned is as expected self.assertEqual(batch.get_part_error(part), 'Some error') # Assert that attempting to retrieve a part's ephemeris will return None self.assertEqual(batch.get_part_ephemeris(part), None)