コード例 #1
0
ファイル: response.py プロジェクト: shairez/asgard-api
    def split(self) -> Apps:

        if self.is_read_request():
            response_content = json.loads(self.response.data)
            if self.is_list_apps_request():
                all_apps = list(
                    AsgardAppGroup.from_json(response_content).iterate_apps()
                )
                for response_app in all_apps:
                    yield response_app, response_app
                return
            elif self.is_group_request():
                response_group = AsgardAppGroup(
                    MarathonGroup.from_json(response_content)
                )
                for current_group in response_group.iterate_groups():
                    yield current_group, current_group
                return
            elif self.is_tasks_request():
                for task in response_content["tasks"]:
                    response_task = MarathonTask.from_json(task)
                    yield response_task, response_task
                return
            elif self.is_deployment():
                content = response_content
                deployments = (
                    MarathonDeployment.from_json(deploy) for deploy in content
                )

                for deployment in deployments:
                    yield deployment, deployment
                return
            elif self.is_queue_request():
                queue_data = response_content
                queued_apps = (
                    MarathonQueueItem.from_json(queue_item)
                    for queue_item in queue_data["queue"]
                )
                for queued_app in queued_apps:
                    yield queued_app, queued_app
                return
            else:
                response_app = AsgardApp.from_json(
                    response_content.get("app") or response_content
                )
                app = self.marathon_client.get_app(self.object_id)
                yield response_app, app
                return

        if self.is_write_request():
            response_content = json.loads(self.response.data)
            if "tasks" in response_content:
                for task in response_content["tasks"]:
                    response_task = MarathonTask.from_json(task)
                    yield response_task, response_task
                return
            return

        yield AsgardApp(), self.marathon_client.get_app(self.app_id)
コード例 #2
0
 def test_from_json(self):
     data = {
         "id": "/",
         "apps": [],
         "groups": [],
     }
     group = AsgardAppGroup.from_json(data)
     self.assertEqual("/", group.id)
コード例 #3
0
ファイル: test_request.py プロジェクト: shairez/asgard-api
    def test_get_original_group_migrated(self):
        found_group = {"id": "/dev/foo", "apps": [], "groups": []}
        with application.test_request_context("/v2/groups//foo",
                                              method="GET") as ctx:
            with RequestsMock() as rsps:
                rsps.add(
                    method="GET",
                    url=conf.MARATHON_ADDRESSES[0] + "/v2/groups//dev/foo",
                    body=json.dumps(found_group),
                    status=200,
                )
                ctx.request.user = self.user
                request = Request(ctx.request)

                group = request._get_original_group(self.user, "/foo")
                self.assertTrue(isinstance(group, AsgardAppGroup))
                self.assertEqual(AsgardAppGroup.from_json(found_group), group)
コード例 #4
0
 def test_eq(self):
     root_a = AsgardAppGroup.from_json({"id": "/"})
     root_b = AsgardAppGroup.from_json({"id": "/"})
     self.assertEqual(root_a, root_b)