Ejemplo n.º 1
0
 def test_adjust_groups_root_request_path(self):
     with application.test_request_context('/v2/groups/',
                                           method='GET') as ctx:
         request_wrapper = Request(ctx.request)
         original_app = MarathonGroup(id="/dev/")
         request_wrapper._adjust_request_path_if_needed(
             request_wrapper.request, original_app)
         self.assertEqual("/v2/groups/dev", request_wrapper.request.path)
Ejemplo n.º 2
0
 def test_adjust_groups_request_path_repeating_final_part(self):
     with application.test_request_context(
             '/v2/groups/grp0/other/parts/grp0/', method='GET') as ctx:
         request_wrapper = Request(ctx.request)
         original_app = MarathonGroup(id="/dev/grp0/grp0")
         request_wrapper._adjust_request_path_if_needed(
             request_wrapper.request, original_app)
         self.assertEqual("/v2/groups/dev/grp0/grp0",
                          request_wrapper.request.path)
Ejemplo n.º 3
0
 def test_adjust_group_versions_request_path(self):
     with application.test_request_context("/v2/groups/my-group/versions",
                                           method="GET") as ctx:
         request_wrapper = Request(ctx.request)
         original_app = MarathonGroup(id="/dev/my-group")
         request_wrapper._adjust_request_path_if_needed(
             request_wrapper.request, original_app)
         self.assertEqual("/v2/groups/dev/my-group/versions",
                          request_wrapper.request.path)
 def test_from_json_parses_root_group(self):
     data = {
                "id": "/",
                "groups": [
                    {"id": "/foo", "apps": []},
                    {"id": "/bla", "apps": []},
                ],
                "apps": []
     }
     group = MarathonGroup().from_json(data)
     self.assertEqual("/", group.id)
    def test_from_json_parses_group_with_enforce_role(self):
        data = {
                   "id": "/mygroup/works",
                   "groups": [
                       {"id": "/foo", "apps": []},
                   ],
                   "apps": [],
                   "enforceRole": False,

        }
        group = MarathonGroup().from_json(data)
        self.assertEqual("/mygroup/works", group.id)
Ejemplo n.º 6
0
def _group_get(**kwargs):  # pylint: disable=W0142
    """
    Return Marathon app object
    """
    defaults = {
        'apps': None,
        'dependencies': None,
        'groups': None,
        'id': None,
        'version': None,
    }
    kwargs = dict((k, kwargs.get(k) or defaults.get(k)) for k in defaults)

    return MarathonGroup(**kwargs)  # pylint: disable=W0142
Ejemplo n.º 7
0
    def join(self, apps: Apps) -> FlaskResponse:

        body = json.loads(self.response.data)
        if self.is_list_apps_request():
            apps_json_repr = [
                response_app.json_repr(minimal=True) for response_app, _ in apps
            ]
            body = {"apps": apps_json_repr}
        elif self.is_read_request() and self.is_app_request():
            # TODO: Retornar 404 nesse caso. Pensar em como fazer.
            # No caso de ser um acesso a uma app específica, e ainda sim recebermos apps = [],
            # deveríamos retornar 404. Chegar uma lista vazia qui significa que a app foi removida
            # do response, ou seja, quem fez o request não pode visualizar esses dados, portanto, 404.
            response_app = apps[0][0] if apps else AsgardApp()
            body = {"app": response_app.json_repr(minimal=True)}
            if "/versions/" in self.request.path:
                body = body["app"]
        elif self.is_read_request() and self.is_group_request():
            response_group = apps[0][0] if apps else MarathonGroup()
            body = response_group.json_repr(minimal=False)
        elif self.is_read_request() and self.is_deployment():
            deployments_json_repr = [
                response_deployment.json_repr(minimal=True)
                for response_deployment, _ in apps
            ]
            body = deployments_json_repr
        elif self.is_read_request() and self.is_queue_request():
            queue_json_repr = [
                queue.json_repr(minimal=True) for queue, _ in apps
            ]
            body = {"queue": queue_json_repr}
        elif self.is_tasks_request():
            original_response_data = json.loads(self.response.data)
            all_tasks = []
            for task, _ in apps:
                all_tasks.append(task.json_repr(minimal=False))
            body = {"tasks": all_tasks}
            try:
                original_response_data["tasks"]
            except KeyError:
                body = original_response_data

        return FlaskResponse(
            response=json.dumps(body, cls=self.json_encoder),
            status=self.response.status,
            headers=self.response.headers,
        )
Ejemplo n.º 8
0
 def __init__(self, wrapped_group=MarathonGroup()):
     self._marathon_group = wrapped_group