class BatchRunnerTest(unittest.TestCase): """Integration test of batch running. """ def setUp(self): self.service = Service() self.assertTrue(self.service.setup_with_test_account()) def tearDown(self): self.service.teardown() def make_batch(self, state_vec, start_time, end_time): start_time_str = start_time.isoformat() + 'Z' end_time_str = end_time.isoformat() + 'Z' propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'step_size': 0, 'project_uuid': self.service.get_working_project().get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params = OpmParams({ 'epoch': start_time_str, 'state_vector': state_vec, 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5, 'originator': 'Test', 'object_name': 'TestObj', 'object_id': 'TestObjId', }) return Batch2(propagation_params, opm_params) def test_backwards_and_forwards(self): now = datetime.datetime.now() later = now + datetime.timedelta(10 * 365) # 10 years state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] print("Starting at %s" % (state_vec)) print("Propagating forward from %s to %s" % (now, later)) batch = self.make_batch(state_vec, now, later) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() forward_end_state = batch.get_results().get_end_state_vector() print("Final state at %s" % forward_end_state) print("Propagating backward from %s to %s" % (later, now)) batch = self.make_batch(forward_end_state, later, now) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() backwards_end_state = batch.get_results().get_end_state_vector() print("Final state at %s" % backwards_end_state) difference = np.subtract(state_vec, backwards_end_state) print("Difference is %s" % difference) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=1e-3) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=1e-10)
class BatchRunnerTest(unittest.TestCase): """Integration test of batch running. """ def setUp(self): self.service = Service() self.assertTrue(self.service.setup_with_test_account()) def tearDown(self): self.service.teardown() def new_dummy_batch(self, days_to_propagate): if (days_to_propagate > 36500): print( "Server has trouble handling propagation durations longer than 100 years. Try something smaller." ) return now = datetime.datetime.utcnow() later = now + datetime.timedelta(days_to_propagate) propagation_params = PropagationParams({ 'start_time': now.isoformat() + 'Z', 'end_time': later.isoformat() + 'Z', 'step_size': 60 * 60, # 1 hour. 'project_uuid': self.service.get_working_project().get_uuid(), 'description': 'Created by test at ' + str(now) + 'Z' }) state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] opm_params = OpmParams({ 'epoch': now.isoformat() + 'Z', 'state_vector': state_vec, 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5, 'originator': 'Test', 'object_name': 'TestObj', 'object_id': 'TestObjId', }) return Batch2(propagation_params, opm_params) def test_small_batch(self): num_batches = 3 duration = 365 # 1 year batches = [self.new_dummy_batch(duration) for i in range(num_batches)] runner = BatchRunManager(self.service.get_batches_module(), batches) runner.run() statuses = runner.get_latest_statuses() self.assertEqual(0, len(statuses['PENDING'])) self.assertEqual(0, len(statuses['RUNNING'])) self.assertEqual(num_batches, len(statuses['COMPLETED'])) self.assertEqual(0, len(statuses['FAILED'])) end_state_vec = [ -37535741.96415495, 492953227.1713997, 204483503.94517875, -11.337510170756701, 7.185009462698965, 3.3597614338244766 ] for batch in batches: npt.assert_allclose(end_state_vec, batch.get_results().get_end_state_vector(), rtol=1e-5, atol=0)
class StmPropagationModuleTest(unittest.TestCase): """Basic integration test to demonstrate use of service tester. """ def setUp(self): self.service = Service() self.assertTrue(self.service.setup_with_test_account()) self.stm_module = StmPropagationModule( self.service.get_batches_module()) def tearDown(self): self.service.teardown() def test_basic_stm(self): state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] start_time = datetime.datetime(2017, 10, 4, 0, 0, 0, 123456) end_time = datetime.datetime(2018, 10, 4, 0, 0, 0, 123456) propagation_params = PropagationParams({ 'start_time': start_time.isoformat() + 'Z', 'end_time': end_time.isoformat() + 'Z', 'project_uuid': self.service.get_working_project().get_uuid(), 'description': 'Created by test at ' + start_time.isoformat() + 'Z' }) opm_params = OpmParams({ 'epoch': start_time.isoformat() + 'Z', 'state_vector': state_vec, }) end_state, stm = self.stm_module.run_stm_propagation( propagation_params, opm_params) # Taken from printed output of ../state_stm_propagation.py expected_end_state = np.array([ -37523497.931654416, 492950622.8491298, 204482176.63445434, -11.336957217854795, 7.18499733419028, 3.3597496059480085 ]) expected_stm = np.matrix( [[ 9.70874844e+00, -1.21563565e+00, -9.26967637e-01, 5.34214567e+07, 1.64329953e+07, 5.30094892e+06 ], [ 7.11171945e+00, -3.24202476e+00, -5.93038128e-01, 3.90278376e+07, 3.82420496e+07, 9.62761631e+06 ], [ 2.50503331e+00, -3.00334152e-01, -2.62144498e+00, 1.46131045e+07, 1.04218322e+07, 1.53347450e+07 ], [ 2.14264136e-07, -2.82295666e-08, -2.23357566e-08, 1.33259336e+00, 6.98930318e-01, 2.41824966e-01 ], [ 4.69172199e-07, -2.03571494e-07, -6.32223023e-08, 2.52995851e+00, 2.04570983e+00, 7.47014439e-01 ], [ 1.82661672e-07, -4.57388872e-08, -1.15455121e-07, 9.96459361e-01, 8.11376173e-01, 3.16765622e-01 ]]) npt.assert_allclose(expected_end_state, np.array(end_state), rtol=1e-8, atol=0) npt.assert_allclose(expected_stm.getA(), stm.getA(), rtol=1e-8, atol=0)
class ProjectsTest(unittest.TestCase): """Integration test of project management. """ def setUp(self): self.service = Service() self.assertTrue(self.service.setup_with_test_account()) def delete_children(self, project): projects = self.service.get_projects_module().get_projects() # First topographically sort all children of <project> so that we can delete # them in dependency-order. parent_map = {} for p in projects: parent_map[p.get_uuid()] = p.get_parent() children = [project.get_uuid()] change = 1 while change > 0: change = 0 for p in projects: if not p.get_uuid() in children and p.get_parent() in children: children.append(p.get_uuid()) change = change + 1 children = children[1:] if len(children) > 0: print("Cleaning up " + str(len(children)) + " children of " + project.get_uuid()) for p in reversed(children): self.service.get_projects_module().delete_project(p) def tearDown(self): self.delete_children(self.service.get_working_project()) self.service.teardown() def test_projects(self): parent = self.service.get_working_project() p = self.service.get_projects_module() projects = p.get_projects() self.assertTrue(parent.get_uuid() in [p.get_uuid() for p in projects]) p1 = p.new_project(parent.get_uuid(), 'p1', 'description') self.assertTrue(p1.get_uuid() is not None) self.assertTrue(p1.get_parent() == parent.get_uuid()) self.assertTrue(p1.get_name() == 'p1') self.assertTrue(p1.get_description() == 'description') projects = p.get_projects() self.assertTrue(parent.get_uuid() in [p.get_uuid() for p in projects]) self.assertTrue(p1.get_uuid() in [p.get_uuid() for p in projects]) p2 = p.new_project(p1.get_uuid(), 'p2', 'another description') self.assertTrue(p2.get_uuid() is not None) self.assertTrue(p2.get_parent() == p1.get_uuid()) projects = p.get_projects() self.assertTrue(parent.get_uuid() in [p.get_uuid() for p in projects]) self.assertTrue(p1.get_uuid() in [p.get_uuid() for p in projects]) self.assertTrue(p2.get_uuid() in [p.get_uuid() for p in projects]) # Can't delete the project before its children are deleted. try: p.delete_project(p1.get_uuid()) self.fail("Expected error deleting project that still has children.") except RuntimeError: pass # This is expected p.delete_project(p2.get_uuid()) p.delete_project(p1.get_uuid())