def test_new_project(self):
        rest = _RestProxyForTest()
        projects = Projects(rest)

        expected_data = {}

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

        expected_data = {'parent': None, 'name': None, 'description': None}
        rest.expect_post("/project", check_input, 200, {'uuid': 'aaa'})
        project = projects.new_project(None, None, None)
        self.assertEqual("aaa", project.get_uuid())
        self.assertEqual(None, project.get_parent())
        self.assertEqual(None, project.get_name())
        self.assertEqual(None, project.get_description())

        expected_data = {'parent': 'ppp', 'name': 'nnn', 'description': 'ddd'}
        rest.expect_post("/project", check_input, 200, {'uuid': 'ccc'})
        project = projects.new_project('ppp', 'nnn', 'ddd')
        self.assertEqual("ccc", project.get_uuid())
        self.assertEqual('ppp', project.get_parent())
        self.assertEqual('nnn', project.get_name())
        self.assertEqual('ddd', project.get_description())

        rest.expect_post("/project", check_input, 404, {})
        with self.assertRaises(RuntimeError):
            project = projects.new_project('ppp', 'nnn', 'ddd')
    def test_get_sub_projects(self):
        rest = _RestProxyForTest()
        projects_module = Projects(rest)

        projects_response = {
            'items': [{
                'uuid': 'aaa',
                'parent': 'p1'
            }, {
                'uuid': 'bbb',
                'parent': 'p2'
            }, {
                'uuid': 'ccc'
            }, {
                'uuid': 'ddd',
                'parent': 'p2'
            }]
        }

        rest.expect_get("/project", 200, projects_response)
        projects = projects_module.get_sub_projects('p1')
        self.assertEqual(1, len(projects))
        self.assertEqual('aaa', projects[0].get_uuid())

        rest.expect_get("/project", 200, projects_response)
        projects = projects_module.get_sub_projects('p2')
        self.assertEqual(2, len(projects))
        self.assertEqual('bbb', projects[0].get_uuid())
        self.assertEqual('ddd', projects[1].get_uuid())

        rest.expect_get("/project", 200, projects_response)
        projects = projects_module.get_sub_projects(None)
        self.assertEqual(1, len(projects))
        self.assertEqual('ccc', projects[0].get_uuid())
    def test_get_projects(self):
        rest = _RestProxyForTest()
        projects_module = Projects(rest)

        rest.expect_get("/project", 200,
                        {'items': [{
                            'uuid': 'aaa'
                        }, {
                            'uuid': 'bbb'
                        }]})
        projects = projects_module.get_projects()
        self.assertEqual(2, len(projects))
        self.assertEqual('aaa', projects[0].get_uuid())
        self.assertEqual('bbb', projects[1].get_uuid())
    def test_get_project(self):
        rest = _RestProxyForTest()
        projects = Projects(rest)

        rest.expect_get("/project/aaa", 200, {'uuid': 'aaa'})
        project = projects.get_project('aaa')
        self.assertEqual("aaa", project.get_uuid())
        self.assertEqual(None, project.get_parent())
        self.assertEqual(None, project.get_name())
        self.assertEqual(None, project.get_description())

        rest.expect_get("/project/ccc", 200, {
            'uuid': 'ccc',
            'parent': 'ppp',
            'name': 'nnn',
            'description': 'ddd'
        })
        project = projects.get_project('ccc')
        self.assertEqual("ccc", project.get_uuid())
        self.assertEqual('ppp', project.get_parent())
        self.assertEqual('nnn', project.get_name())
        self.assertEqual('ddd', project.get_description())

        rest.expect_get("/project/aaa", 404, {})
        project = projects.get_project('aaa')
        self.assertEqual(project, None)

        rest.expect_get("/project/aaa", 403, {})
        with self.assertRaises(RuntimeError):
            project = projects.get_project('aaa')
    def test_delete_project(self):
        rest = _RestProxyForTest()
        projects = Projects(rest)

        rest.expect_delete("/project/aaa", 204)
        projects.delete_project('aaa')

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

        rest.expect_delete("/project/aaa", 404)
        with self.assertRaises(RuntimeError):
            projects.delete_project('aaa')
Beispiel #6
0
        if auth.initial_authorization():
            with open(tokenFile, "w") as f:
                f.write(auth.get_token())
except RuntimeError as e:
    print('Encountered server error while attempting to authorize: ' + str(e))

if auth.get_token() == "":
    print('Could not authorize user.')
else:
    print('Welcome, ' + auth.get_user())

# auth.get_token() can now be used to authorize calls to other API methods.
auth_rest = AuthorizingRestProxy(rest, auth.get_token())

# Get projects TODO: move this somewhere else
projects = Projects(auth_rest)
project = projects.new_project('ffffffff-ffff-ffff-ffff-ffffffffffff', None,
                               "parent")
child = projects.new_project(project.get_uuid(), None, "child")
print('Current projects, including newly-created parent and child:')
projects.print_projects()
projects.delete_project(child.get_uuid())
projects.delete_project(project.get_uuid())

# Example inputs

# 6x1 state vector (position [km], velocity [km/s])
state_vec = [
    130347560.13690618, -74407287.6018632, -35247598.541470632,
    23.935241263310683, 27.146279819258538, 10.346605942591514
]