コード例 #1
0
class IncompatibleFieldsFilterTest(unittest.TestCase):
    @with_json_fixture("../fixtures/single_full_app.json")
    def setUp(self, single_full_app_fixture):
        self.request = Request(None)
        self.single_full_app_fixture = single_full_app_fixture
        self.filter = IncompatibleFieldsFilter()
        self.request_app = AsgardApp.from_json(self.single_full_app_fixture)
        self.original_app = AsgardApp.from_json(self.single_full_app_fixture)

    def test_update_app_remove_ports_fields(self):
        self.original_app.ports = self.single_full_app_fixture['container'][
            'docker']['portMappings'][0]['servicePort']
        merged_app = self.request.merge_marathon_apps(self.original_app,
                                                      self.request_app)
        filtered_app = self.filter.write(None, merged_app, self.original_app)
        self.assertEqual([], filtered_app.ports)

    def test_update_app_remove_port_definitions_fields(self):
        port_definitions = [{
            "port": 10019,
            "protocol": "tcp",
            "name": "http",
            "labels": {
                "vip": "192.168.0.1:80"
            }
        }]
        self.original_app.port_definitions = port_definitions
        merged_app = self.request.merge_marathon_apps(self.original_app,
                                                      self.request_app)
        filtered_app = self.filter.write(None, merged_app, self.original_app)
        self.assertEqual([], filtered_app.port_definitions)
コード例 #2
0
    def test_split_groups_read_on_specific_group(self, group_b_fixture):

        with application.test_request_context('/v2/groups/group-b',
                                              method='GET') as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)
            with RequestsMock() as rsps:
                rsps.add(method='GET',
                         url=conf.MARATHON_ADDRESSES[0] +
                         '/v2/groups//dev/group-b',
                         body=json.dumps(group_b_fixture),
                         status=200)

                apps = list(request_parser.split())
                self.assertEqual(2, len(apps))

                original_app_one = MarathonApp.from_json(
                    {"id": "/dev/group-b/appb0"})
                original_app_two = MarathonApp.from_json(
                    {"id": "/dev/group-b/group-b0/app0"})
                expected_apps = [
                    (request_parser.merge_marathon_apps(
                        MarathonApp(), original_app_one), original_app_one),
                    (request_parser.merge_marathon_apps(
                        MarathonApp(), original_app_two), original_app_two),
                ]
                self.assertEqual(expected_apps, apps)
コード例 #3
0
ファイル: test_request.py プロジェクト: shairez/asgard-api
    def test_a_request_with_n_apps_returns_n_marathonapps(self, fixture):
        with application.test_request_context("/v2/apps/",
                                              method="GET") as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)
            with RequestsMock() as rsps:
                rsps.add(
                    method="GET",
                    url=conf.MARATHON_ADDRESSES[0] + "/v2/groups//dev/",
                    body=json.dumps(fixture),
                    status=200,
                )
                apps = list(request_parser.split())

                self.assertEqual(
                    [request_app for request_app, _ in apps],
                    [
                        request_parser.merge_marathon_apps(
                            request_app, original_app)
                        for request_app, original_app in apps
                    ],
                )

                self.assertEqual(
                    [app.id for app, _ in apps],
                    [app["id"] for app in fixture["apps"]],
                )
コード例 #4
0
ファイル: test_request.py プロジェクト: shairez/asgard-api
    def test_can_read_app_if_already_migrated(self, single_full_app_fixture):
        """
        Conferimos que é possível fazer um GET em
        /v2/apps/<app-id> para uma app que já está migrada.
        O <app-id> usado é sempre *sem* namespace
        """
        request_data = deepcopy(single_full_app_fixture)
        single_full_app_fixture["id"] = "/dev/foo"
        with application.test_request_context("/v2/apps/foo",
                                              method="GET") as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)
            with RequestsMock() as rsps:
                rsps.add(
                    method="GET",
                    url=conf.MARATHON_ADDRESSES[0] + "/v2/apps//dev/foo",
                    body=json.dumps({"app": single_full_app_fixture}),
                    status=200,
                )

                apps = list(request_parser.split())

                original_app = MarathonApp.from_json(single_full_app_fixture)
                expected_app = (
                    request_parser.merge_marathon_apps(MarathonApp(),
                                                       original_app),
                    original_app,
                )
                self.assertEqual(apps, [expected_app])
コード例 #5
0
ファイル: test_request.py プロジェクト: shairez/asgard-api
    def test_split_groups_read_on_root_group(self,
                                             group_dev_namespace_fixture):

        with application.test_request_context("/v2/groups",
                                              method="GET") as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)
            with RequestsMock() as rsps:
                rsps.add(
                    method="GET",
                    url=conf.MARATHON_ADDRESSES[0] + "/v2/groups//dev/",
                    body=json.dumps(group_dev_namespace_fixture),
                    status=200,
                )

                apps = list(request_parser.split())
                self.assertEqual(3, len(apps))

                original_app_one = MarathonApp.from_json({"id": "/dev/a/app0"})
                original_app_two = MarathonApp.from_json(
                    {"id": "/dev/group-b/appb0"})
                original_app_three = MarathonApp.from_json(
                    {"id": "/dev/group-b/group-b0/app0"})
                expected_apps = [
                    (
                        request_parser.merge_marathon_apps(
                            MarathonApp(), original_app_one),
                        original_app_one,
                    ),
                    (
                        request_parser.merge_marathon_apps(
                            MarathonApp(), original_app_two),
                        original_app_two,
                    ),
                    (
                        request_parser.merge_marathon_apps(
                            MarathonApp(), original_app_three),
                        original_app_three,
                    ),
                ]
                self.assertEqual(apps, expected_apps)
コード例 #6
0
    def test_a_read_single_app_request_returns_a_single_marathonapp_if_app_exists(
            self, fixture):
        with application.test_request_context('/v2/apps//foo',
                                              method='GET',
                                              data=b'') as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)

            with patch.object(request_parser, 'marathon_client') as client:
                original_app = MarathonApp.from_json(fixture)
                client.get_app.return_value = original_app
                apps = list(request_parser.split())

            self.assertEqual(apps, [(request_parser.merge_marathon_apps(
                MarathonApp(), original_app), client.get_app.return_value)])
コード例 #7
0
 def test_a_request_for_write_operation_with_appid_in_url_path_returns_a_tuple_of_marathonapp(
         self, fixture):
     scale_up = {'instances': 10}
     with application.test_request_context(
             '/v2/apps/foo', method='PUT',
             data=json.dumps(scale_up)) as ctx:
         ctx.request.user = self.user
         request_parser = Request(ctx.request)
         with RequestsMock() as rsps:
             rsps.add(method='GET',
                      url=conf.MARATHON_ADDRESSES[0] + '/v2/apps//dev/foo',
                      body=json.dumps({'app': fixture}),
                      status=200)
             apps = list(request_parser.split())
             original_app = MarathonApp.from_json(fixture)
             expected_apps = (request_parser.merge_marathon_apps(
                 MarathonApp.from_json(scale_up),
                 original_app), original_app)
             self.assertEqual(apps, [expected_apps])
コード例 #8
0
    def test_a_request_for_restart_operation_with_appid_in_url_path_returns_a_tuple_of_marathonapp(
            self, fixture):
        with application.test_request_context('/v2/apps/xablau/restart',
                                              method='PUT',
                                              data=b'{"force": true}') as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)
            with RequestsMock() as rsps:
                rsps.add(method='GET',
                         url=conf.MARATHON_ADDRESSES[0] +
                         '/v2/apps//dev/xablau',
                         body=json.dumps({'app': fixture}),
                         status=200)
                apps = list(request_parser.split())

                original_app = MarathonApp.from_json(fixture)
                expected_app = (request_parser.merge_marathon_apps(
                    MarathonApp(), original_app), original_app)
                self.assertEqual(apps, [expected_app])
コード例 #9
0
    def test_a_request_with_n_apps_returns_n_marathonapps(self, fixture):
        with application.test_request_context('/v2/apps/',
                                              method='GET') as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)
            with RequestsMock() as rsps:
                rsps.add(method='GET',
                         url=conf.MARATHON_ADDRESSES[0] + '/v2/apps',
                         body=json.dumps(fixture),
                         status=200)
                apps = list(request_parser.split())

                self.assertEqual([request_app for request_app, _ in apps], [
                    request_parser.merge_marathon_apps(request_app,
                                                       original_app)
                    for request_app, original_app in apps
                ])

                self.assertEqual([app.id for app, _ in apps],
                                 [app['id'] for app in fixture['apps']])
コード例 #10
0
    def test_split_does_not_break_when_removing_force_parameter_if_request_is_a_list(
            self, fixture):
        request_data = {"id": "/foo", "instances": 2}
        with application.test_request_context(
                '/v2/apps/', method='PUT',
                data=json.dumps(request_data)) as ctx:
            ctx.request.user = self.user
            request_parser = Request(ctx.request)
            with RequestsMock() as rsps:
                rsps.add(method='GET',
                         url=conf.MARATHON_ADDRESSES[0] + '/v2/apps//dev/foo',
                         body=json.dumps({'app': fixture}),
                         status=200)
                apps = list(request_parser.split())

                original_app = MarathonApp.from_json(fixture)
                expected_app = (request_parser.merge_marathon_apps(
                    MarathonApp.from_json(request_data),
                    original_app), original_app)
                self.assertEqual(apps, [expected_app])