예제 #1
0
    def test_instance_wrong(self, client):
        rv = client.post(f'/v1/operator/{self.name}/instances/{self.instance_name}/restart')
        assert rv.status_code != 200

        rv = client.post(f'/v1/operator/{self.name}/instances/{self.instance_name}/stop')
        assert rv.status_code != 200

        rv = client.post(f'/v1/operator/{self.name}/instances/{self.instance_name}/start')
        assert rv.status_code != 200
예제 #2
0
 def test_upload_api(self, client):
     data = {'fields': {self.field_name: {'url': self.test_url}}}
     rv = client.post(f"/v1/application/{self.name}/upload", json=data)
     assert rv.status_code == 200
     base_txt = os.path.join(os.path.dirname(__file__), 'base64.txt')
     with open(base_txt, 'r') as file:
         base_data = file.readline()
         data = {'fields': {self.field_name: {'data': base_data}}}
         rv = client.post(f"/v1/application/{self.name}/upload", json=data)
         assert rv.status_code == 200
     time.sleep(2)
예제 #3
0
    def test_create_and_delete_api(self, client):
        # create app
        data = {
            'fields': {
                self.field_name: {
                    'type': 'pipeline',
                    'value': self.pipeline_name
                }
            },
            's3Bucket': f"s3example{self.test_ver}"
        }
        rv = client.post(f'/v1/application/{self.name}', json=data)
        json_data = rv.get_json()
        assert rv.status_code == 200
        assert json_data['name'] == self.name

        rv = client.get(f"/v1/application/{self.name}")
        assert rv.status_code == 200

        # upload none filed
        data = {'fields': {}}
        rv = client.post(f"/v1/application/{self.name}/upload", json=data)
        assert rv.status_code != 200

        # # upload nonexist filed
        # data = {
        #     'fields': {
        #         "nonexist": {
        #             "url": self.test_url
        #         }
        #     }
        # }
        # rv = client.post(f"/v1/application/{self.name}/upload", json=data)
        # assert rv.status_code != 200

        # upload nonexist filed
        data = {'fields': {self.field_name: {}}}
        rv = client.post(f"/v1/application/{self.name}/upload", json=data)
        assert rv.status_code != 200

        # delete app
        data = {"force": True}
        rv = client.delete(f"/v1/application/{self.name}", json=data)
        assert rv.status_code == 200

        # delete none exist application
        rv = client.delete(f"/v1/application/{self.name}")
        assert rv.status_code != 200

        # upload nonexist app
        data = {'fields': {self.field_name: {'url': self.test_url}}}
        rv = client.post(f"/v1/application/{'notexist'}/upload", json=data)
        assert rv.status_code != 200
예제 #4
0
    def test_fetch_operator(self, client):
        data = {"url": "http://23.99.118.156/v1/operator"}
        rv = client.post('/v1/operator/fetch', json=data)
        assert rv.status_code == 200

        data = {"url": "http://23.99.118.156/v1/operator", "override": False}
        rv = client.post('/v1/operator/fetch', json=data)
        assert rv.status_code == 200

        wrong_data = {"url": "http://1.1./v1/operator", "override": False}
        rv = client.post('/v1/operator/fetch', json=wrong_data)
        assert rv.status_code != 200
예제 #5
0
    def test_score_api(self, client):
        for image_url in self.test_url:
            data = {
                'fields': {
                    self.field_name1: {
                        'url': image_url
                    },
                    self.field_name2: {
                        'url': image_url
                    }
                }
            }
            rv = client.post(f"/v1/application/{self.name}1/upload", json=data)
            assert rv.status_code == 200
        time.sleep(1)  # wait for milvus

        # test multi field score function
        topk = len(self.test_url) - 1
        for score_mode in self.score_modes:
            data = {
                'fields': {
                    self.field_name1: {
                        'url': self.test_search_url[0],
                        'inner_field_score_mode': 'first',
                        'weight': 6
                    },
                    self.field_name2: {
                        'url': self.test_search_url[1],
                        'inner_field_score_mode': 'random',
                        'weight': 2
                    },
                    "score_mode": score_mode
                },
                'topk': topk,
                'nprobe': 10
            }
            rv = client.post(f"/v1/application/{self.name}1/search", json=data)
            assert rv.status_code == 200
            json_data = rv.get_json()
            assert len(json_data) == topk

        # get and delete all entities
        rv = client.get(f"/v1/application/{self.name}1/entity?num=100")
        assert rv.status_code == 200
        json_data = rv.get_json()
        for data in json_data:
            reply = client.delete(
                f"/v1/application/{self.name}1/entity/{data['_id']}")
            assert reply.status_code == 200
            json_reply = reply.get_json()
            assert json_reply['_id'] == data['_id']
예제 #6
0
 def test_new_application_api(self, client):
     PreOperator().create({
         "endpoint": f"{local_ip()}:50001",
         "name": self.op_name
     })
     PrePipeline().create({
         "name": self.pipeline_name,
         "input": "image",
         "description": "this is a test pipeline",
         "processors": "",
         "encoder": self.op_name,
         "index_file_size": 1024
     })
     data = {
         'fields': {
             self.field_name: {
                 'type': 'object',
                 'pipeline': self.pipeline_name
             }
         },
         's3Buckets': "s3example"
     }
     rv = client.post(f'/v1/application/{self.name}', json=data)
     json_data = rv.get_json()
     assert rv.status_code == 200
     assert json_data['_application_name'] == self.name
     try:
         os.mkdir('./tmp')
     except Exception as e:
         pass
예제 #7
0
    def test_register_api(self, client):
        data = {
            "name": self.name,
            "addr": self.addr,
            "author": self.author,
            "type": self.type,
            "description": self.description,
            "version": self.version
        }
        rv = client.post('/v1/operator/register', json=data)
        json_data = rv.get_json()
        assert rv.status_code == 200
        assert json_data["_name"] == self.name
        assert json_data["_addr"] == self.addr

        # register exist operator
        rv = client.post('/v1/operator/register', json=data)
        assert rv.status_code != 200
예제 #8
0
 def test_search_api(self, client):
     data = {
         'fields': {
             self.field_name: {
                 'url': self.test_url
             }
         },
         'topk': 5,
         'nprobe': 10
     }
     rv = client.post(f"/v1/application/{self.name}/search", json=data)
     assert rv.status_code == 200
예제 #9
0
 def test_new_application_api_error(self, client):
     # create wrong app
     none_exist_pipeline_data = {
         'fields': {
             self.field_name: {
                 'type': 'object',
                 'pipeline': 'none_exist_pipeline'
             }
         },
         's3Buckets': "s3example"
     }
     rv = client.post(f'/v1/application/{self.name}',
                      json=none_exist_pipeline_data)
     json_data = rv.get_json()
     assert rv.status_code != 200
     data = {
         'fields': {
             self.field_name: {
                 'type': 'str',
                 'pipeline': self.pipeline_name
             }
         },
         's3Buckets': "s3example"
     }
     rv = client.post(f'/v1/application/{self.name}', json=data)
     json_data = rv.get_json()
     assert rv.status_code != 200
     data = {
         'fields': {
             self.field_name: {
                 'type': 'object',
                 'pipeline': self.pipeline_name
             }
         },
         's3Buckets': "s3example"
     }
     rv = client.post(f'/v1/application/fail_app', json=data)
     json_data = rv.get_json()
     assert rv.status_code != 200
예제 #10
0
    def test_create_pipeline_api(self, client):
        data = {
            "description": "this is a test pipeline",
            "encoder": {
                "name": "pytest1",
                "instance": "ins1"
            },
        }
        rv = client.post(f'/v1/pipeline/{self.name}', json=data)
        json_data = rv.get_json()
        assert rv.status_code == 200
        assert json_data['name'] == self.name

        # create exist pipeline
        rv = client.post(f'/v1/pipeline/{self.name}', json=data)
        assert rv.status_code != 200

        data = {
            "url":
            "https://live.staticflickr.com/65535/50063878058_c7c04603cc_o.jpg"
        }
        rv = client.post(f"/v1/pipeline/{self.name}/test", json=data)
        assert rv.status_code == 200
예제 #11
0
 def test_create_pipeline_api(self, client):
     PreOperator().create({"endpoint": f"{local_ip()}:50001", "name": "pytestop"})
     data = {
         "input": "image",
         "description": "this is a test pipeline",
         "processors": "",
         "encoder": "pytestop",
         "indexFileSize": 1024
     }
     rv = client.post(f'/v1/pipeline/{self.name}', json=data)
     json_data = rv.get_json()
     PreOperator().delete({"name": "pytestop"})
     assert rv.status_code == 200
     assert json_data['_pipeline_name'] == self.name
예제 #12
0
    def test_inner_field_score_api(self, client):
        for image_url in self.test_url:
            data = {
                'fields': {
                    self.field_name2: {
                        'url': image_url
                    }
                }
            }
            rv = client.post(f"/v1/application/{self.name}/upload", json=data)
            assert rv.status_code == 200
        time.sleep(1)  # wait for milvus

        # search in empty milvus collection
        data = {
            'fields': {
                self.field_name1: {
                    'url': self.test_search_url[0],
                    'inner_field_score_mode': "first"
                }
            },
            'topk': 3,
            'nprobe': 10
        }
        rv = client.post(f"/v1/application/{self.name}/search", json=data)
        assert rv.status_code != 200

        # search with nonexist field
        data = {
            'fields': {
                "wrong_field": {
                    'url': self.test_search_url[0],
                    'inner_field_score_mode': "first"
                }
            },
            'topk': 3,
            'nprobe': 10
        }
        rv = client.post(f"/v1/application/{self.name}/search", json=data)
        assert rv.status_code != 200

        # test inner filed score mode search
        for inner_field_score_mode in self.inner_fields:
            data = {
                'fields': {
                    self.field_name2: {
                        'url': self.test_search_url[0],
                        'inner_field_score_mode': inner_field_score_mode
                    }
                },
                'topk': 3,
                'nprobe': 10
            }
            rv = client.post(f"/v1/application/{self.name}/search", json=data)
            assert rv.status_code == 200
            json_data = rv.get_json()
            assert len(json_data) == 3

        # test score function insufficent topk search
        topk = len(self.test_url) * 10
        for inner_field_score_mode in self.inner_fields:
            data = {
                'fields': {
                    self.field_name2: {
                        'url': self.test_search_url[0],
                        'inner_field_score_mode': inner_field_score_mode
                    }
                },
                'topk': topk,
                'nprobe': 10
            }
            rv = client.post(f"/v1/application/{self.name}/search", json=data)
            assert rv.status_code == 200
            json_data = rv.get_json()
            assert len(json_data) > 0
            assert len(json_data) < topk

        # get and delete all entities
        rv = client.get(f"/v1/application/{self.name}/entity?num=100")
        assert rv.status_code == 200
        json_data = rv.get_json()
        for data in json_data:
            reply = client.delete(
                f"/v1/application/{self.name}/entity/{data['_id']}")
            assert reply.status_code == 200
            json_reply = reply.get_json()
            assert json_reply['_id'] == data['_id']
예제 #13
0
    def test_new_application_api_error(self, client):
        """create wrong app"""
        none_exist_pipeline_data = {
            'fields': {
                self.field_name: {
                    'type': 'pipeline',
                    'value': 'none_exist_pipeline'
                }
            },
            's3Buckets': "s3example"
        }
        rv = client.post(f'/v1/application/{self.name}',
                         json=none_exist_pipeline_data)
        assert rv.status_code != 200

        # create with unsupported type
        wrong_type_data = {
            'fields': {
                self.field_name: {
                    'type': 'str',
                    'value': self.pipeline_name
                }
            },
            's3Buckets': "s3example"
        }
        rv = client.post(f'/v1/application/{self.name}', json=wrong_type_data)
        assert rv.status_code != 200

        # create with unsupported type
        wrong_type_data = {'fields': ["hello"], 's3Buckets': "s3example"}
        rv = client.post(f'/v1/application/{self.name}', json=wrong_type_data)
        assert rv.status_code != 200

        # create with nonexist pipeline
        wrong_type_data = {
            'fields': {
                self.field_name: {
                    'type': 'pipeline',
                    'value': "wrong field"
                }
            },
            's3Buckets': "s3example"
        }
        rv = client.post(f'/v1/application/{self.name}', json=wrong_type_data)
        assert rv.status_code != 200

        # create with none type or value
        wrong_type_data = {
            'fields': {
                self.field_name: {
                    'type': 'string',
                    'pipeline': self.pipeline_name
                }
            },
            's3Buckets': "s3example"
        }
        rv = client.post(f'/v1/application/{self.name}', json=wrong_type_data)
        assert rv.status_code != 200

        # create with type and wrong value
        wrong_type_data = {
            'fields': {
                self.field_name: {
                    'type': 'string',
                    'value': 1.0
                }
            },
            's3Buckets': "s3example"
        }
        rv = client.post(f'/v1/application/{self.name}', json=wrong_type_data)
        assert rv.status_code != 200

        existed_s3_data = {
            'fields': {
                self.field_name: {
                    'type': 'pipeline',
                    'value': self.pipeline_name
                }
            },
            's3Buckets': f"s3example{self.test_ver}"
        }
        rv = client.post(f'/v1/application/fail_app', json=existed_s3_data)
        assert rv.status_code != 200

        existed_app_data = {
            'fields': {
                self.field_name: {
                    'type': 'pipeline',
                    'value': self.pipeline_name
                }
            },
            's3Buckets': f"s3example{self.test_ver}"
        }
        rv = client.post(f'/v1/application/{self.name}1',
                         json=existed_app_data)
        assert rv.status_code != 200
예제 #14
0
    def test_application_other_api(self, client):
        # upload error url image
        data = {'fields': {self.field_name: {'url': self.test_url[:3]}}}
        rv = client.post(f"/v1/application/{self.name}1/upload", json=data)
        assert rv.status_code != 200

        # upload error base64 image
        base_txt = os.path.join(os.path.dirname(__file__), 'base64.txt')
        with open(base_txt, 'r') as file:
            base_data = file.readline()
            data = {'fields': {self.field_name: {'data': base_data[:10]}}}
            rv = client.post(f"/v1/application/{self.name}1/upload", json=data)
            assert rv.status_code != 200
        time.sleep(1)  # wait for milvus

        # upload url image
        data = {'fields': {self.field_name: {'url': self.test_url}}}
        rv = client.post(f"/v1/application/{self.name}1/upload", json=data)
        assert rv.status_code == 200

        # upload base64 image
        base_txt = os.path.join(os.path.dirname(__file__), 'base64.txt')
        with open(base_txt, 'r') as file:
            base_data = file.readline()
            data = {'fields': {self.field_name: {'data': base_data}}}
            rv = client.post(f"/v1/application/{self.name}1/upload", json=data)
            assert rv.status_code == 200
        time.sleep(1)  # wait for milvus

        # count entity
        rv = client.get(f"/v1/application/{self.name}1/entity/count")
        assert rv.status_code == 200

        # search
        data = {
            'fields': {
                self.field_name: {
                    'url': self.test_url
                }
            },
            'topk': 5,
            'nprobe': 10
        }
        rv = client.post(f"/v1/application/{self.name}1/search", json=data)
        assert rv.status_code == 200

        # search score function
        data = {
            'fields': {
                self.field_name: {
                    'url': self.test_url,
                    'inner_field_score_mode': 'first'
                }
            },
            'topk': 5,
            'nprobe': 10
        }
        rv = client.post(f"/v1/application/{self.name}1/search", json=data)
        assert rv.status_code == 200

        data = {
            'fields': {
                self.field_name: {
                    'url': self.test_url,
                    'inner_field_score_mode': 'wrong_mode'
                }
            },
            'topk': 5,
            'nprobe': 10
        }
        rv = client.post(f"/v1/application/{self.name}1/search", json=data)
        assert rv.status_code != 200

        # detele unempty app
        rv = client.delete(f"/v1/application/{self.name}1")
        assert rv.status_code != 200

        # get all entities and delete all
        rv = client.get(f"/v1/application/{self.name}1/entity?num=4&page=101")
        assert rv.status_code == 200
        json_data = rv.get_json()
        assert len(json_data) == 0

        rv = client.get(f"/v1/application/{self.name}1/entity?num=4&page=0")
        assert rv.status_code == 200
        json_data = rv.get_json()
        assert len(json_data) == 2
        for data in json_data:
            reply = client.delete(
                f"/v1/application/{self.name}1/entity/{data['_id']}")
            assert reply.status_code == 200
            json_reply = reply.get_json()
            assert json_reply['_id'] == data['_id']
        # delete none exist entity
        reply = client.delete(f"/v1/application/{self.name}1/entity/-1")
        assert reply.status_code != 200
예제 #15
0
 def test_regist_api(self, client):
     data = {"endpoint": self.endpoint, "name": self.name}
     rv = client.post('/v1/operator/regist', json=data)
     json_data = rv.get_json()
     assert json_data["_endpoint"] == self.endpoint
     assert json_data["_name"] == self.name
예제 #16
0
 def test_create_instance(self, client):
     data = {"instanceName": self.instance_name}
     rv = client.post(f'/v1/operator/{self.name}/instances', json=data)
     assert rv.status_code == 200
예제 #17
0
 def test_restart_instance(self, client):
     rv = client.post(
         f'/v1/operator/{self.name}/instances/{self.instance_name}/restart')
     assert rv.status_code == 200
예제 #18
0
    def test_pipeline_error_api(self, client):
        rv = client.delete(f"/v1/pipeline/{self.name}")
        assert rv.status_code != 200

        rv = client.post(f"/v1/pipeline/{self.name}/test")
        assert rv.status_code != 200