class StmPropagationModuleTest(unittest.TestCase): """Basic integration test to demonstrate use of service tester. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) self.working_project = self.service.new_working_project() self.assertIsNotNone(self.working_project) 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.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) end_state_V, stm_V = self.stm_module.run_stm_propagation( propagation_params, opm_params, only_dV=True) # 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) npt.assert_allclose(expected_end_state, np.array(end_state_V), rtol=1e-8, atol=0) npt.assert_allclose(expected_stm[:, 3:].getA(), stm_V.getA(), rtol=1e-8, atol=0)
class KeplerianTest(unittest.TestCase): """Integration test of using keplerian elements instead of cartesian. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) self.working_project = self.service.new_working_project() self.assertIsNotNone(self.working_project) def tearDown(self): self.service.teardown() def make_cartesian_and_keplerian_batches(self, start_time_str, end_time_str): keplerian_elements = { 'semi_major_axis_km': 3.1307289138037175E8, 'eccentricity': 0.5355029800000188, 'inclination_deg': 23.439676743246295, 'ra_of_asc_node_deg': 359.9942693176405, 'arg_of_pericenter_deg': 328.5584374618295, 'true_anomaly_deg': -127.01778914927144, 'gm': 1.327124400419394E11 } cartesian_state_vector = [ -3.0653634150102222e8, -1.1097955684640282e8, -4.8129706422527283e7, # x, y, z 15.7598552764090590, -10.5875673291958420, -4.5896734328869746 # dx, dy, dZ ] propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params_templ = { 'epoch': start_time_str, # state_vector or keplerian_elements will be set later. 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5 } cartesian_opm_params = opm_params_templ.copy() cartesian_opm_params['state_vector'] = cartesian_state_vector keplerian_opm_params = opm_params_templ.copy() keplerian_opm_params['keplerian_elements'] = keplerian_elements cartesian = Batch(propagation_params, OpmParams(cartesian_opm_params)) keplerian = Batch(propagation_params, OpmParams(keplerian_opm_params)) return cartesian, keplerian def test_keplerian_and_cartesian(self): start = datetime.datetime.now() end = start + datetime.timedelta(10) # 10 days start_time_str = start.isoformat() + 'Z' end_time_str = end.isoformat() + 'Z' cartesian, keplerian = self.make_cartesian_and_keplerian_batches( start_time_str, end_time_str) BatchRunManager(self.service.get_batches_module(), [cartesian, keplerian]).run() cartesian_end_state = cartesian.get_results().get_end_state_vector() keplerian_end_state = keplerian.get_results().get_end_state_vector() difference = np.subtract(cartesian_end_state, keplerian_end_state) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=1e-5) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=1e-10)
class PropagatorConfigTest(unittest.TestCase): """Test of propagator config manipulation. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) def tearDown(self): self.service.teardown() def test_get_public_configs(self): # Config management isn't very common, doesn't merit direct addition to service. configs = PropagatorConfigs(self.service.rest) public_config_1 = configs.get_config( PropagatorConfigs.PUBLIC_CONFIG_ALL_PLANETS_AND_MOON) self.assertEqual("00000000-0000-0000-0000-000000000001", public_config_1.get_uuid()) public_config_2 = configs.get_config( PropagatorConfigs.PUBLIC_CONFIG_SUN_ONLY) self.assertEqual("00000000-0000-0000-0000-000000000002", public_config_2.get_uuid()) public_config_3 = configs.get_config( PropagatorConfigs.PUBLIC_CONFIG_ALL_PLANETS_AND_MOON_AND_ASTEROIDS) self.assertEqual("00000000-0000-0000-0000-000000000003", public_config_3.get_uuid()) def test_config_management(self): # Config management isn't very common, doesn't merit direct addition to service. configs = PropagatorConfigs(self.service.rest) project = self.service.new_working_project() self.assertIsNotNone(project) config = configs.new_config({ 'project': project.get_uuid(), 'description': 'test config' }) self.assertEqual(project.get_uuid(), config.get_project()) my_configs = configs.get_configs() self.assertIn(config.get_uuid(), [c.get_uuid() for c in my_configs]) config_again = configs.get_config(config.get_uuid()) self.assertEqual(config.get_config_json(), config_again.get_config_json()) configs.delete_config(config.get_uuid()) my_configs = configs.get_configs() self.assertNotIn(config.get_uuid(), [c.get_uuid() for c in my_configs]) def test_config_in_use_pins_project(self): # Config management isn't very common, doesn't merit direct addition to service. configs = PropagatorConfigs(self.service.rest) projects = self.service.get_projects_module() project = self.service.new_working_project() project1 = projects.new_project(project.get_uuid(), "", "") self.assertIsNotNone(project1) project2 = projects.new_project(project.get_uuid(), "", "") self.assertIsNotNone(project2) print("Added child projects to working project: " + "[" + project1.get_uuid() + ", " + project2.get_uuid() + "]") config = configs.new_config({ 'project': project1.get_uuid(), 'description': 'test config' }) self.assertEqual(project1.get_uuid(), config.get_project()) batch = Batch( PropagationParams({ 'start_time': '2017-10-04T00:00:00Z', 'end_time': '2017-10-05T00:00:00Z', 'project_uuid': project2.get_uuid(), 'propagator_uuid': config.get_uuid() }), OpmParams({ 'epoch': '2017-10-04T00:00:00Z', 'state_vector': [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] })) BatchRunManager(self.service.get_batches_module(), [batch]).run() # Attempt to delete the project with the config in it. It should refuse because the # config is still in use by the batch. with self.assertRaises(RuntimeError): projects.delete_project(project1.get_uuid()) # Then delete the batch. After that, the project with the config in it should # delete no problem. self.service.batches.delete_batch(batch.get_uuid()) projects.delete_project(project1.get_uuid()) # Clean up the batch holder project. projects.delete_project(project2.get_uuid())
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 Batch(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-3, atol=0)
class BackwardsPropagationTest(unittest.TestCase): """Integration test of backwards propagation. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_adam_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) self.working_project = self.service.new_working_project() self.assertIsNotNone(self.working_project) 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': 86400, 'project_uuid': self.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 Batch(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 ReferenceFrameTest(unittest.TestCase): """Integration test of using different reference frames. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_config.json').get_config('dev') self.service = Service(config) self.assertTrue(self.service.setup()) self.working_project = self.service.new_working_project() self.assertIsNotNone(self.working_project) def tearDown(self): self.service.teardown() # This test and the following test are exactly the same propagation, but are done # in two different reference frames. def test_icrf(self): start_time_str = "2000-01-01T11:58:55.816Z" end_time_str = "2009-07-21T21:55:08.813Z" sun_icrf_state_vec = [ -306536341.5010222, -110979556.84640282, -48129706.42252728, 15.75985527640906, -10.587567329195842, -4.589673432886975 ] propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'step_size': 86400, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params = OpmParams({ 'epoch': start_time_str, 'state_vector': sun_icrf_state_vec, 'center_name': 'SUN', 'ref_frame': 'ICRF', }) batch = Batch(propagation_params, opm_params) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() end_state = batch.get_results().get_end_state_vector() expected_end_state = [ 73978163.61069362, -121822760.05571477, -52811158.83249758, 31.71000343989318, 29.9657246374751, .6754531613947713 ] difference = np.subtract(expected_end_state, end_state) print("Difference is %s" % difference) print("End state: %s" % end_state) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=.02) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=.00002) ephem = batch.get_results().get_parts()[-1].get_ephemeris() self.assertTrue("ICRF" in ephem) def test_sun_ememe(self): start_time_str = "2000-01-01T11:58:55.816Z" end_time_str = "2009-07-21T21:55:08.813Z" sun_ememe_state_vec = [ -306536346.18024945, -120966638.54521248, -12981.069369263947, 15.759854830195243, -11.539570959741736, 0.0005481049628786039 ] propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'step_size': 86400, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params = OpmParams({ 'epoch': start_time_str, 'state_vector': sun_ememe_state_vec, 'center_name': 'SUN', 'ref_frame': 'EMEME2000', }) batch = Batch(propagation_params, opm_params) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() end_state = batch.get_results().get_end_state_vector() # The output state is expected to be in ICRF. expected_end_state = [ 73978163.61069362, -121822760.05571477, -52811158.83249758, 31.71000343989318, 29.9657246374751, .6754531613947713 ] # These values are in EMEME. The resulting ephemeris is not expected to match these values. # expected_end_state = [73978158.47632701, -132777272.5255892, 5015.073123970032, # 31.710003506237434, 27.761693311026138, -11.299967713192564] difference = np.subtract(expected_end_state, end_state) print("Difference is %s" % difference) print("End state: %s" % end_state) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=.02) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=.00002) # The returned ephemeris will be in Sun-centered ICRF, not EMEME. My best guess is that # the ephemeris file doesn't support all reference frames, so if it encounters one that # isn't supported, it'll choose a similar one. ephem = batch.get_results().get_parts()[-1].get_ephemeris() self.assertTrue("ICRF" in ephem) self.assertFalse("EMEME" in ephem)
class AnonymousTest(unittest.TestCase): """Tests anonymous access to API. """ def setUp(self): cwd = os.getcwd() cwd_str = str(cwd).split("/") os.chdir("..") self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').read_config(os.getcwd() + '/test_adam_config.json') self.config.set_token("") self.service = Service(self.config) self.assertTrue(self.service.setup()) #if len(cwd_str) > 4: # # TRAVIS CI option # if cwd_str[1] == "home" and cwd_str[2] == "travis" and cwd_str[3] == "build": # self.config = ConfigManager(os.getcwd() + '/adam_home/config/adam_config_template.json').get_config() # print("home/travis/build found in root dir - USE JSON TEMPLATE") # #self.config = ConfigManager(None).get_config() # self.config.set_token("") # self.service = Service(self.config) # self.assertTrue(self.service.setup()) # else: # #self.config = ConfigManager(os.getcwd() + '/adam_test_config.json').get_config() # # next line used for testing Travis output with decrypted json info. # self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').read_config(os.getcwd() + '/test_adam_config.json') # self.config.set_token("") # self.service = Service(self.config) # self.assertTrue(self.service.setup()) #else: # # PERSONAL WORKSTATION option # self.config = ConfigManager(os.getcwd() + '/test_config.json').get_config() # # next line used for testing Travis output with decrypted json info. # #self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').read_config(os.getcwd() + '/test_adam_config.json') # self.config.set_token("") # self.service = Service(self.config) # self.assertTrue(self.service.setup()) #self.config = ConfigManager(os.getcwd() + '/test_adam_config.json').get_config() #self.config.set_token("") #self.service = Service(self.config) #self.assertTrue(self.service.setup()) def tearDown(self): self.service.teardown() def test_access(self): projects_module = self.service.get_projects_module() permissions_module = self.service.get_permissions_module() groups_module = self.service.get_groups_module() projects = projects_module.get_projects() self.assertEqual(1, len(projects)) self.assertEqual("public", projects[0].get_name()) # Can't add a project to public project. public_project = "00000000-0000-0000-0000-000000000001" with (self.assertRaises(RuntimeError)): projects_module.new_project(public_project, "", "") # Can't run a batch in the public project. batches_module = self.service.get_batches_module() dummy_propagation_params = PropagationParams({ 'start_time': 'AAA', 'end_time': 'BBB', 'project_uuid': 'CCC' }) dummy_opm_params = OpmParams({ 'epoch': 'DDD', 'state_vector': [1, 2, 3, 4, 5, 6] }) with (self.assertRaises(RuntimeError)): batches_module.new_batch(dummy_propagation_params, dummy_opm_params) # Anon should have no permissions. permissions = permissions_module.get_my_permissions() self.assertEqual(1, len(permissions)) self.assertEqual(0, len(permissions[""])) # And anon is in no groups. groups = groups_module.get_my_memberships() self.assertEqual(0, len(groups)) # Therefore anon can grant no permissions. with (self.assertRaises(RuntimeError)): permissions_module.grant_user_permission( "*****@*****.**", Permission("READ", "PROJECT", public_project)) # And can add/modify no groups. with (self.assertRaises(RuntimeError)): groups_module.new_group("", "") all_group = "00000000-0000-0000-0000-000000000001" with (self.assertRaises(RuntimeError)): groups_module.add_user_to_group("*****@*****.**", all_group) # Not even allowed to see the members of the magic all group. with (self.assertRaises(RuntimeError)): groups_module.get_group_members(all_group)