def test_get_configs(self):
        rest = _RestProxyForTest()
        configs_module = PropagatorConfigs(rest)

        rest.expect_get(PropagatorConfigs.REST_ENDPOINT_PREFIX, 200,
                        {'items': []})
        configs = configs_module.get_configs()
        self.assertEqual(0, len(configs))

        rest.expect_get(
            PropagatorConfigs.REST_ENDPOINT_PREFIX, 200, {
                'items': [{
                    'uuid': 'aaa',
                    'project': 'bbb'
                }, {
                    'uuid': 'ccc',
                    'project': 'ddd'
                }]
            })
        configs = configs_module.get_configs()
        self.assertEqual(2, len(configs))
        self.assertEqual('aaa', configs[0].get_uuid())
        self.assertEqual('bbb', configs[0].get_project())
        self.assertEqual('ccc', configs[1].get_uuid())
        self.assertEqual('ddd', configs[1].get_project())
示例#2
0
    def test_new_config(self):
        rest = _RestProxyForTest()
        configs = PropagatorConfigs(rest)

        expected_data = {}

        def check_input(data_dict):
            self.assertEqual(expected_data, data_dict)
            return True

        expected_data = {'project': 'project'}
        rest.expect_post("/config", check_input, 200, {
            'uuid': 'uuid',
            'project': 'project'
        })
        config = configs.new_config({'project': 'project'})
        self.assertEqual("uuid", config.get_uuid())
        self.assertEqual("project", config.get_project())
        self.assertEqual(None, config.get_description())

        expected_data = FULL_CONFIG_JSON_INPUT
        rest.expect_post("/config", check_input, 200, FULL_CONFIG_JSON_OUTPUT)
        config = configs.new_config(FULL_CONFIG_JSON_INPUT)
        self.assertEqual(FULL_CONFIG_JSON_OUTPUT, config.get_config_json())

        with self.assertRaises(KeyError):
            configs.new_config({'unrecognized': 'foo'})

        with self.assertRaises(KeyError):
            configs.new_config({'sun': 'not an option'})
    def test_get_config(self):
        rest = _RestProxyForTest()
        configs = PropagatorConfigs(rest)

        rest.expect_get(f"{PropagatorConfigs.REST_ENDPOINT_PREFIX}/aaa", 200, {
            'uuid': 'aaa',
            'project': 'bbb'
        })
        config = configs.get_config('aaa')
        self.assertEqual('aaa', config.get_uuid())
        self.assertEqual('bbb', config.get_project())

        # the public config exists
        rest.expect_get(
            f"{PropagatorConfigs.REST_ENDPOINT_PREFIX}/00000000-0000-0000-0000-000000000003",
            200, FULL_CONFIG_JSON_OUTPUT)
        config = configs.get_config("00000000-0000-0000-0000-000000000003")
        self.assertEqual(FULL_CONFIG_JSON_OUTPUT, config.get_config_json())

        # propagator config with id "aaa" does not exist
        rest.expect_get(f"{PropagatorConfigs.REST_ENDPOINT_PREFIX}/aaa", 404,
                        {})
        config = configs.get_config('aaa')
        self.assertIsNone(config)

        rest.expect_get(f"{PropagatorConfigs.REST_ENDPOINT_PREFIX}/aaa", 403,
                        {})
        with self.assertRaises(RuntimeError):
            config = configs.get_config('aaa')
示例#4
0
    def test_get_public_configs(self, service):
        # Config management isn't very common, doesn't merit direct addition to service.
        configs = PropagatorConfigs(service.rest)

        public_config_1 = configs.get_config(PropagatorConfigs.PUBLIC_CONFIG_ALL_PLANETS_AND_MOON)
        assert "00000000-0000-0000-0000-000000000001" == public_config_1.get_uuid()

        public_config_2 = configs.get_config(PropagatorConfigs.PUBLIC_CONFIG_SUN_ONLY)
        assert "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)
        assert "00000000-0000-0000-0000-000000000003" == public_config_3.get_uuid()
示例#5
0
    def test_delete_config(self):
        rest = _RestProxyForTest()
        configs = PropagatorConfigs(rest)

        rest.expect_delete("/config/aaa", 204)
        configs.delete_config('aaa')

        # 200 isn't a valid return value for delete calls right now
        rest.expect_delete("/config/aaa", 200)
        with self.assertRaises(RuntimeError):
            configs.delete_config('aaa')

        rest.expect_delete("/config/aaa", 404)
        with self.assertRaises(RuntimeError):
            configs.delete_config('aaa')
    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())
示例#7
0
    def test_config_management(self, service):
        # Config management isn't very common, doesn't merit direct addition to service.
        configs = PropagatorConfigs(service.rest)

        project = service.new_working_project()
        assert project is not None

        config = configs.new_config({'project': project.get_uuid(), 'description': 'test config'})
        assert project.get_uuid() == config.get_project()

        my_configs = configs.get_configs()
        assert config.get_uuid() in [c.get_uuid() for c in my_configs]

        config_again = configs.get_config(config.get_uuid())
        assert config.get_config_json() == config_again.get_config_json()

        configs.delete_config(config.get_uuid())

        my_configs = configs.get_configs()
        assert config.get_uuid() not in [c.get_uuid() for c in my_configs]
示例#8
0
    def test_get_config(self):
        rest = _RestProxyForTest()
        configs = PropagatorConfigs(rest)

        rest.expect_get("/config/aaa", 200, {'uuid': 'aaa', 'project': 'bbb'})
        config = configs.get_config('aaa')
        self.assertEqual('aaa', config.get_uuid())
        self.assertEqual('bbb', config.get_project())

        rest.expect_get("/config/00000000-0000-0000-0000-000000000003", 200,
                        FULL_CONFIG_JSON_OUTPUT)
        config = configs.get_config("00000000-0000-0000-0000-000000000003")
        self.assertEqual(FULL_CONFIG_JSON_OUTPUT, config.get_config_json())

        rest.expect_get("/config/aaa", 404, {})
        config = configs.get_config('aaa')
        self.assertIsNone(config)

        rest.expect_get("/config/aaa", 403, {})
        with self.assertRaises(RuntimeError):
            config = configs.get_config('aaa')
    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])