예제 #1
0
    def test_search_instance(self, cluster_id):
        # 匹配到关键字
        request = factory.post(
            '/apis/iam/v1/namespaces/',
            {
                'method': MethodType.SEARCH_INSTANCE,
                'type': ResourceType.Namespace,
                'page': {
                    'offset': 0,
                    'limit': 5
                },
                'filter': {
                    'keyword': 'def',
                    'parent': {
                        'id': cluster_id
                    }
                },
            },
        )
        p_view = ResourceAPIView.as_view()
        response = p_view(request)
        data = response.data
        assert data['count'] == 1

        # 匹配不到关键字
        request = factory.post(
            '/apis/iam/v1/namespaces/',
            {
                'method': MethodType.SEARCH_INSTANCE,
                'type': ResourceType.Namespace,
                'page': {
                    'offset': 0,
                    'limit': 5
                },
                'filter': {
                    'keyword': 'test',
                    'parent': {
                        'id': cluster_id
                    }
                },
            },
        )
        p_view = ResourceAPIView.as_view()
        response = p_view(request)
        data = response.data
        assert data['count'] == 0
예제 #2
0
    def test_search_instance(self, project_id, template_qsets):
        # 匹配到关键字
        request = factory.post(
            '/apis/iam/v1/templatesets/',
            {
                'method': MethodType.SEARCH_INSTANCE,
                'type': ResourceType.Templateset,
                'page': {
                    'offset': 0,
                    'limit': 5
                },
                "filter": {
                    'parent': {
                        'id': project_id
                    },
                    'keyword': 'test'
                },
            },
        )
        p_view = ResourceAPIView.as_view()
        response = p_view(request)
        data = response.data
        assert data['count'] == 2

        # 匹配不到关键字
        request = factory.post(
            '/apis/iam/v1/templatesets/',
            {
                'method': MethodType.SEARCH_INSTANCE,
                'type': ResourceType.Templateset,
                'page': {
                    'offset': 0,
                    'limit': 5
                },
                'filter': {
                    'keyword': 'ttt',
                    'parent': {
                        'id': project_id
                    }
                },
            },
        )
        p_view = ResourceAPIView.as_view()
        response = p_view(request)
        data = response.data
        assert data['count'] == 0
예제 #3
0
 def test_fetch_instance_info(self, project_id):
     request = factory.post(
         '/apis/iam/v1/projects/',
         {
             'method': MethodType.FETCH_INSTANCE_INFO,
             'type': ResourceType.Project,
             'filter': {
                 'ids': [project_id]
             },
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert data[0]['display_name'] == 'unittest-proj'
     assert data[0]['id'] == project_id
예제 #4
0
 def test_fetch_instance_info_with_cluster_ids(self, cluster_id):
     """传入已存在的 cluster_id,查询特定 cluster_id 数据"""
     request = factory.post(
         '/apis/iam/v1/clusters/',
         {
             'method': MethodType.FETCH_INSTANCE_INFO,
             'type': ResourceType.Cluster,
             'filter': {
                 'ids': [cluster_id]
             },
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert len(data) == 1
     assert data[0]["id"] == cluster_id
예제 #5
0
 def test_list_instance(self):
     request = factory.post(
         '/apis/iam/v1/projects/',
         {
             'method': MethodType.LIST_INSTANCE,
             'type': ResourceType.Project,
             'page': {
                 'offset': 0,
                 'limit': 5
             }
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert data['count'] == 2
     assert data['results'][0]['display_name'] == 'unittest-proj'
예제 #6
0
 def test_fetch_instance_info(self, cluster_id):
     iam_ns_id = calc_iam_ns_id(cluster_id, 'default')
     request = factory.post(
         '/apis/iam/v1/namespaces/',
         {
             'method': MethodType.FETCH_INSTANCE_INFO,
             'type': ResourceType.Namespace,
             'filter': {
                 'ids': [iam_ns_id]
             },
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert len(data) == 1
     assert data[0]['id'] == iam_ns_id
     assert data[0]['display_name'] == 'default'
예제 #7
0
 def test_fetch_instance_info_with_tplset_ids(self, template_qsets):
     request = factory.post(
         '/apis/iam/v1/templatesets/',
         {
             'method': 'fetch_instance_info',
             'type': 'templateset',
             'page': {
                 'offset': 0,
                 'limit': 1
             },
             "filter": {
                 'ids': [template_qsets[0].id]
             },
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert len(data) == 1
예제 #8
0
 def test_list_instance(self, project_id):
     request = factory.post(
         '/apis/iam/v1/clusters/',
         {
             'method': MethodType.LIST_INSTANCE,
             'type': ResourceType.Cluster,
             'page': {
                 'offset': 0,
                 'limit': 1
             },
             'filter': {
                 'parent': {
                     'id': project_id
                 }
             },
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert data['count'] == 1
예제 #9
0
 def test_list_instance(self, cluster_id):
     request = factory.post(
         '/apis/iam/v1/namespaces/',
         {
             'method': MethodType.LIST_INSTANCE,
             'type': ResourceType.Namespace,
             'page': {
                 'offset': 0,
                 'limit': 5
             },
             'filter': {
                 'parent': {
                     'id': cluster_id
                 }
             },
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert data['count'] == 1
     assert data['results'][0]['display_name'] == 'default'
예제 #10
0
 def test_list_instance(self, project_id, template_qsets):
     request = factory.post(
         '/apis/iam/v1/templatesets/',
         {
             'method': MethodType.LIST_INSTANCE,
             'type': ResourceType.Templateset,
             'page': {
                 'offset': 0,
                 'limit': 1
             },
             "filter": {
                 'parent': {
                     'id': project_id
                 }
             },
         },
     )
     p_view = ResourceAPIView.as_view()
     response = p_view(request)
     data = response.data
     assert data['count'] == 2
     assert data['results'][0]['display_name'] in [
         'nginx-test', 'redis-test'
     ]