예제 #1
0
    def test_get_children_json(self):
        rest = _RestProxyForTest()
        adam_objects = AdamObjects(rest, 'MyType')

        rest.expect_get("/adam_object/by_parent/MyType/uuid1", 200, {
            'childTypes': ['ChildType'],
            'childUuids': ['childUuid1']
        })
        rest.expect_get("/adam_object/single/ChildType/childUuid1", 200,
                        {'anyJson': 5})
        rest.expect_get(
            "/adam_object/runnable_state/single/ChildType/childUuid1", 200, {
                'uuid': 'childUuid1',
                'calculationState': 'COMPLETED'
            })
        children_json = adam_objects._get_children_json('uuid1')
        self.assertEqual(1, len(children_json))
        child_json, child_runnable_state, child_type = children_json[0]
        self.assertEqual({'anyJson': 5}, child_json)
        self.assertEqual('childUuid1', child_runnable_state.get_uuid())
        self.assertEqual('COMPLETED', child_runnable_state.get_calc_state())
        self.assertIsNone(child_runnable_state.get_error())
        self.assertEqual('ChildType', child_type)

        rest.expect_get("/adam_object/by_parent/MyType/uuid1", 404, {})
        json = adam_objects._get_children_json('uuid1')
        self.assertEqual([], json)

        rest.expect_get("/adam_object/by_parent/MyType/uuid1", 403, {})
        with self.assertRaises(RuntimeError):
            adam_objects._get_children_json('uuid1')
예제 #2
0
    def get_children(self, uuid):
        child_response_list = AdamObjects._get_children_json(self, uuid)

        children = []
        for childJson, child_runnable_state, child_type in child_response_list:
            # All child types should be SinglePropagation, but ignore those
            # that aren't just in case.
            if not child_type == 'SinglePropagation':
                print('Skipping child of unexpected type ' + child_type)
                continue

            # Values in [] are guaranteed to be present. Values in .get() may be missing.
            childOpmParams = OpmParams.fromJsonResponse(
                childJson['propagationParameters']['opm'])
            childPropParams = PropagationParams.fromJsonResponse(
                childJson['propagationParameters'],
                childJson.get('description'))
            childProp = SinglePropagation(childPropParams, childOpmParams)
            childProp.set_uuid(childJson['uuid'])
            childProp.set_runnable_state(child_runnable_state)
            childProp.set_ephemeris(childJson.get('ephemeris'))
            childProp.set_final_state_vector(childJson.get('finalStateVector'))

            children.append(childProp)

        return children