示例#1
0
    def test_get_methods(self):
        propagation_params = {'a': 1}
        opm_params = {'b': 2}
        batch = Batch(propagation_params, opm_params)
        self.assertEqual(propagation_params, batch.get_propagation_params())
        self.assertEqual(opm_params, batch.get_opm_params())
        self.assertIsNone(batch.get_uuid())
        self.assertIsNone(batch.get_calc_state())
        self.assertIsNone(batch.get_state_summary())
        self.assertIsNone(batch.get_results())

        state_summary = StateSummary({'uuid': 'aaa', 'calc_state': 'RUNNING'})
        batch.set_state_summary(state_summary)
        self.assertEqual(state_summary, batch.get_state_summary())
        self.assertEqual('aaa', batch.get_uuid())
        self.assertEqual('RUNNING', batch.get_calc_state())

        results = {'c': 3}
        batch.set_results(results)
        self.assertEqual(results, batch.get_results())
    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())
示例#3
0
    def test_good_submit(self):
        """Test a good/passing batch submit

        This function tests a good batch submit run.

        """

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        def check_input(data_dict):
            """Check input data

            Checks input data by asserting the following:
                - start time = 'AAA'
                - end time = 'BBB'
                - step size = 86400 (default)
                - opm string in data dictionary is not None
                - originator = 'ADAM_User'
                - object name = 'dummy'
                - object ID = '001'
                - epoch and state vector are 'CCC' and [1, 2, 3, 4, 5, 6], respectively
                - object mass = 1000 (default)
                - object solar radiation area = 20 (default)
                - object solar radiation coefficient = 1 (default)
                - object drag area = 20 (default)
                - object drag coefficient = 2.2 (default)
                - propagator ID is default (none specified)

            Args:
                data_dict (dict) - input data for POST

            Returns:
                True
            """
            self.assertEqual(data_dict['start_time'], 'AAA')
            self.assertEqual(data_dict['end_time'], 'BBB')
            self.assertEqual(data_dict['step_duration_sec'], 86400)
            opm = data_dict['opm_string']
            self.assertIsNotNone(opm)
            self.assertIn('ORIGINATOR = ADAM_User', opm)
            self.assertIn('OBJECT_NAME = dummy', opm)
            self.assertIn('OBJECT_ID = 001', opm)
            self.assertIn('EPOCH = CCC', opm)
            self.assertIn('X = 1', opm)
            self.assertIn('Y = 2', opm)
            self.assertIn('Z = 3', opm)
            self.assertIn('X_DOT = 4', opm)
            self.assertIn('Y_DOT = 5', opm)
            self.assertIn('Z_DOT = 6', opm)
            self.assertIn('MASS = 1000', opm)
            self.assertIn('SOLAR_RAD_AREA = 20', opm)
            self.assertIn('SOLAR_RAD_COEFF = 1', opm)
            self.assertIn('DRAG_AREA = 20', opm)
            self.assertIn('DRAG_COEFF = 2.2', opm)
            self.assertEqual(data_dict['propagator_uuid'],
                             "00000000-0000-0000-0000-000000000001")
            return True

        # Set expected 'POST' request (good)
        rest.expect_post(self._base + "/batch", check_input, 200, {
            'calc_state': 'PENDING',
            'uuid': 'BLAH'
        })

        # Initiate Batch class
        batch = Batch()

        # Set start time, end time, and state vector with epoch
        batch.set_start_time("AAA")
        batch.set_end_time("BBB")
        batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6])

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Submit job
        batch.submit()

        # Assert that the calc state is 'PENDING' and the UUID is 'BLAH'
        self.assertEqual(batch.get_calc_state(), 'PENDING')
        self.assertEqual(batch.get_uuid(), 'BLAH')
示例#4
0
    def test_custom_inputs(self):
        """Test setting custom inputs

        This function tests that setting an optional input will yield that value (instead of the default value).

        """

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        def check_custom_inputs(data_dict):
            """Check custom inputs

            Checks input data for custom inputs by asserting the following:
                - propagator uuid = 00000000-0000-0000-0000-000000000002
                - step size = 216000
                - object mass = 500.5
                - object solar radiation area = 25.2
                - object solar radiation coefficient = 1.2
                - object drag area = 33.3
                - object drag coefficient = 2.5

            Args:
                data_dict (dict) - input data for POST

            Returns:
                True
            """
            self.assertEqual(data_dict['propagator_uuid'],
                             "00000000-0000-0000-0000-000000000002")
            self.assertEqual(data_dict['step_duration_sec'], 216000)
            self.assertIsNotNone(data_dict['description'])
            self.assertEqual(data_dict['description'], 'some description')
            opm = data_dict['opm_string']
            self.assertIn('ORIGINATOR = Robot', opm)
            self.assertIn('OBJECT_NAME = TestObj', opm)
            self.assertIn('OBJECT_ID = test1234', opm)
            self.assertIn('MASS = 500.5', opm)
            self.assertIn('SOLAR_RAD_AREA = 25.2', opm)
            self.assertIn('SOLAR_RAD_COEFF = 1.2', opm)
            self.assertIn('DRAG_AREA = 33.3', opm)
            self.assertIn('DRAG_COEFF = 2.5', opm)
            return True

        # Set expected 'POST' request (good)
        rest.expect_post(self._base + "/batch", check_custom_inputs, 200, {
            'calc_state': 'PENDING',
            'uuid': 'BLAH'
        })

        # Initiate Batch class
        batch = Batch()

        # Set start time, end time, and state vector with epoch
        batch.set_start_time("AAA")
        batch.set_end_time("BBB")
        batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6])

        # Set custom inputs
        batch.set_propagator_uuid("00000000-0000-0000-0000-000000000002")
        batch.set_step_size(3600, 'min')
        batch.set_mass(500.5)
        batch.set_solar_rad_area(25.2)
        batch.set_solar_rad_coeff(1.2)
        batch.set_drag_area(33.3)
        batch.set_drag_coeff(2.5)
        batch.set_originator('Robot')
        batch.set_object_name('TestObj')
        batch.set_object_id('test1234')
        batch.set_description('some description')

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Submit job
        batch.submit()

        # Assert that the calc state is 'PENDING' and the UUID is 'BLAH'
        self.assertEqual(batch.get_calc_state(), 'PENDING')
        self.assertEqual(batch.get_uuid(), 'BLAH')
示例#5
0
    def test_custom_inputs(self):
        """Test setting custom inputs

        This function tests that setting an optional input will yield that value (instead of the default value).

        """

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        def check_custom_inputs(data_dict):
            """Check custom inputs

            Checks input data for custom inputs by asserting the following:
                - propagator uuid = 00000000-0000-0000-0000-000000000002
                - step size = 216000
                - covariance = [0, 1, 2, ... , 20]
                - perturbation = 3
                - hypercube = FACES
                - object mass = 500.5
                - object solar radiation area = 25.2
                - object solar radiation coefficient = 1.2
                - object drag area = 33.3
                - object drag coefficient = 2.5

            Args:
                data_dict (dict) - input data for POST

            Returns:
                True
            """
            self.assertEqual(data_dict['propagator_uuid'],
                             "00000000-0000-0000-0000-000000000002")
            self.assertEqual(data_dict['step_duration_sec'], 216000)
            self.assertIsNotNone(data_dict['description'])
            self.assertEqual(data_dict['description'], 'some description')
            opm = data_dict['opm_string']
            self.assertIn('ORIGINATOR = Robot', opm)
            self.assertIn('OBJECT_NAME = TestObj', opm)
            self.assertIn('OBJECT_ID = test1234', opm)
            self.assertIn('MASS = 500.5', opm)
            self.assertIn('SOLAR_RAD_AREA = 25.2', opm)
            self.assertIn('SOLAR_RAD_COEFF = 1.2', opm)
            self.assertIn('DRAG_AREA = 33.3', opm)
            self.assertIn('DRAG_COEFF = 2.5', opm)
            self.assertIn('CX_X = 0', opm)
            self.assertIn('CY_X = 1', opm)
            self.assertIn('CY_Y = 2', opm)
            self.assertIn('CZ_X = 3', opm)
            self.assertIn('CZ_Y = 4', opm)
            self.assertIn('CZ_Z = 5', opm)
            self.assertIn('CX_DOT_X = 6', opm)
            self.assertIn('CX_DOT_Y = 7', opm)
            self.assertIn('CX_DOT_Z = 8', opm)
            self.assertIn('CX_DOT_X_DOT = 9', opm)
            self.assertIn('CY_DOT_X = 10', opm)
            self.assertIn('CY_DOT_Y = 11', opm)
            self.assertIn('CY_DOT_Z = 12', opm)
            self.assertIn('CY_DOT_X_DOT = 13', opm)
            self.assertIn('CY_DOT_Y_DOT = 14', opm)
            self.assertIn('CZ_DOT_X = 15', opm)
            self.assertIn('CZ_DOT_Y = 16', opm)
            self.assertIn('CZ_DOT_Z = 17', opm)
            self.assertIn('CZ_DOT_X_DOT = 18', opm)
            self.assertIn('CZ_DOT_Y_DOT = 19', opm)
            self.assertIn('CZ_DOT_Z_DOT = 20', opm)
            self.assertIn('USER_DEFINED_ADAM_INITIAL_PERTURBATION = 3 [sigma]',
                          opm)
            self.assertIn('USER_DEFINED_ADAM_HYPERCUBE = FACES', opm)
            return True

        # Set expected 'POST' request (good)
        rest.expect_post("/batch", check_custom_inputs, 200, {
            'calc_state': 'PENDING',
            'uuid': 'BLAH'
        })

        # Initiate Batch class
        batch = Batch(rest)

        # Set start time, end time, and state vector with epoch
        batch.set_start_time("AAA")
        batch.set_end_time("BBB")
        batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6])

        # Set custom inputs
        batch.set_propagator_uuid("00000000-0000-0000-0000-000000000002")
        batch.set_step_size(3600, 'min')
        batch.set_covariance([x for x in range(0, 21)], 'FACES', 3)
        batch.set_mass(500.5)
        batch.set_solar_rad_area(25.2)
        batch.set_solar_rad_coeff(1.2)
        batch.set_drag_area(33.3)
        batch.set_drag_coeff(2.5)
        batch.set_originator('Robot')
        batch.set_object_name('TestObj')
        batch.set_object_id('test1234')
        batch.set_description('some description')

        # Submit job
        batch.submit()

        # Assert that the calc state is 'PENDING' and the UUID is 'BLAH'
        self.assertEqual(batch.get_calc_state(), 'PENDING')
        self.assertEqual(batch.get_uuid(), 'BLAH')