Пример #1
0
    def create_stream_summary_test(self, streamId, startTime, endTime):
        with pytest.raises(APIError) as e:
            self.api.create_stream_summary(
                streamId=streamId, startTime="test", endTime=endTime
            )
        assert "Invalid dates provided" in str(e)
        with pytest.raises(APIError) as e:
            self.api.create_stream_summary(
                streamId=streamId,
                startTime=datetime.utcfromtimestamp(
                    int(time.time()) - (24 * 60 * 60 * 8)
                ),
                endTime=endTime,
            )
        assert "Provided dates are not within your stream" in str(e)

        res = self.api.create_stream_summary(streamId, startTime, endTime)
        assert res["summary"]["feed"] == streamId
        assert (
            datetime.strptime(res["summary"]["startTime"], "%Y-%m-%dT%H:%M:%S.000Z")
            == startTime
        )
        assert (
            datetime.strptime(res["summary"]["endTime"], "%Y-%m-%dT%H:%M:%S.000Z")
            == endTime
        )

        print_test_pass()
Пример #2
0
 def query_collection_by_scores_test(self, task_id):
     print(task_id)
     res = self.api.query_collection_by_scores(taskId=task_id,
                                               thresholds={"cat": 0.5},
                                               numResults=5)
     assert res["results"] != None
     print_test_pass()
Пример #3
0
    def create_stream_test(self, url, name, dmca):
        res = self.api.create_stream(url=url, name=name, dmca=dmca)

        assert res["streamId"] != None

        print_test_pass()
        return res["streamId"]
Пример #4
0
    def classify_image_test(self, detector_id, url, urls, file, files):
        with pytest.raises(APIError) as e:
            # self.api.classify_image(detectorId=detector_id, url='invalid-url')
            self.api.classify_image(detectorId=detector_id)
        assert "invalid_query_err" in str(e)
        print("Classify invalid url test passed")

        res = self.api.classify_image(detectorId=detector_id, url=url)
        assert res["results"][0]["predictions"] != None
        print("Classify one url test passed")

        res = self.api.classify_image(detectorId=detector_id, file=file)
        assert res["results"][0]["predictions"] != None
        print("Classify one file test passed")

        res = self.api.classify_image(detectorId=detector_id, file=files)
        assert len(res["results"]) == 2
        assert res["results"][0]["predictions"] != None
        print("Classify multiple files test passed")

        res = self.api.classify_image(detectorId=detector_id, url=urls)
        assert len(res["results"]) == 2
        assert res["results"][0]["predictions"] != None
        print("Classify multiple urls test passed")

        print_test_pass()
Пример #5
0
    def localize_image_test(self, localizer, localizer_label, url):
        res = self.api.localize_image(localizer=localizer,
                                      localizerLabel=localizer_label,
                                      url=url)
        assert res["results"][0]["predictions"] != None

        print_test_pass()
Пример #6
0
 def update_collection_index_test(self, task_id):
     res = self.api.update_collection_index(taskId=task_id,
                                            updateIndex=False)
     assert res["collectionTask"] != None
     collection_task_id = res["collectionTask"]["_id"]
     assert collection_task_id == task_id
     print_test_pass()
Пример #7
0
 def kill_collection_index_test(self, task_id):
     res = self.api.kill_collection_index(taskId=task_id,
                                          includeCollectionInfo=False)
     collection_task = res["collectionTask"]
     assert collection_task != None
     assert collection_task["_id"] == task_id
     print_test_pass()
Пример #8
0
    def redo_detector_test(self, detector_id):
        res = self.api.redo_detector(detectorId=detector_id)
        redo_detector_id = res["detectorId"]
        assert redo_detector_id != None

        print_test_pass()
        return redo_detector_id
Пример #9
0
    def monitor_stream_test(self, stream_id, detector_id, thresholds,
                            task_name):
        end_time = "5 minutes"

        with pytest.raises(APIError) as e:
            self.api.monitor_stream(
                streamId=RANDOM_MONGO_ID,
                detectorId=detector_id,
                thresholds=thresholds,
                endTime=end_time,
                taskName=task_name,
            )
        assert "invalid_query_err" in str(e)

        res = self.api.monitor_stream(
            streamId=stream_id,
            detectorId=detector_id,
            thresholds=thresholds,
            endTime=end_time,
            taskName=task_name,
        )
        assert res["monitoringId"] != None

        print_test_pass()
        return res["monitoringId"]
Пример #10
0
    def delete_video_summary_test(self, summaryId):
        with pytest.raises(APIError) as e:
            self.api.delete_video_summary(summaryId="123")
        assert "invalid_query_err" in str(e)

        res = self.api.delete_video_summary(summaryId=summaryId)
        assert res["summaryId"] == summaryId
        print_test_pass()
Пример #11
0
    def delete_feedback_test(self, detector_id):
        for feedback_id in self.feedback_ids:
            res = self.api.delete_feedback(
                feedbackId=feedback_id, detectorId=detector_id
            )
            assert res["feedbackId"] is not None

        print_test_pass()
Пример #12
0
    def add_feedback_test(self, detector_id):
        feedback = [
            {
                "feedbackType": "positive",
                "label": "cat",
                "boundingBox": {"top": 0.1, "left": 0.1, "height": 0.1, "width": 0.1,},
            }
        ]

        res = self.api.add_feedback(
            detectorId=detector_id, file=TEST_IMAGE_FILE, feedback=feedback
        )
        assert len(res["feedback"]) == 1

        feedback_id = res["feedback"][0]["id"]
        assert feedback_id is not None
        self.feedback_ids.append(feedback_id)

        url_feedback = [
            {
                "feedbackType": "positive",
                "label": "cat",
                "boundingBox": {"top": 0.1, "left": 0.1, "height": 0.1, "width": 0.1,},
            },
            {
                "feedbackType": "negative",
                "label": "cat",
                "boundingBox": {"top": 0.3, "left": 0.3, "height": 0.3, "width": 0.3,},
            },
        ]

        res = self.api.add_feedback(
            detectorId=detector_id, feedback=url_feedback, url=TEST_IMAGE_URL
        )
        assert len(res["feedback"]) == 2

        for feedback_item in res["feedback"]:
            feedback_id = feedback_item["id"]
            assert feedback_id is not None
            self.feedback_ids.append(feedback_id)

        single_feedback = {
            "feedbackType": "negative",
            "label": "cat",
            "boundingBox": {"top": 0.2, "left": 0.2, "height": 0.2, "width": 0.2,},
        }

        res = self.api.add_feedback(
            detectorId=detector_id, url=TEST_IMAGE_URL, feedback=single_feedback
        )
        assert len(res["feedback"]) == 1

        feedback_id = res["feedback"][0]["id"]
        assert feedback_id is not None
        self.feedback_ids.append(feedback_id)

        print_test_pass()
Пример #13
0
    def get_video_results_test(self, video_id, threshold):
        with pytest.raises(APIError) as e:
            self.api.classify_video(detectorId=RANDOM_MONGO_ID,
                                    url="invalid-url")
        assert "invalid_query_err" in str(e)

        res = self.api.get_video_results(videoId=video_id, threshold=threshold)
        assert res != None

        print_test_pass()
Пример #14
0
    def register_stream_test(self, url, name):
        res = self.api.register_stream(url=url, name=name)
        assert res["streamId"] != None

        with pytest.raises(APIError) as e:
            self.api.register_stream(url=url, name=name)
        assert "invalid_query_err" in str(e)

        print_test_pass()
        return res["streamId"]
Пример #15
0
    def classify_video_test(self, detector_id, url):
        with pytest.raises(APIError) as e:
            self.api.classify_video(detectorId=detector_id, url="invalid-url")
        assert "invalid_query_err" in str(e)

        res = self.api.classify_video(detectorId=detector_id, url=url)
        video_id = res["videoId"]
        assert video_id != None

        print_test_pass()
        return video_id
Пример #16
0
    def get_video_summary_test(self, summaryId):
        with pytest.raises(APIError) as e:
            self.api.get_video_summary(summaryId="123")
        assert "invalid_query_err" in str(e)

        res = self.api.get_video_summary(summaryId=summaryId)

        assert res["progress"] == 0
        assert res["state"] == "requested"

        print_test_pass()
Пример #17
0
    def create_detector_test(self, file, name, detector_type):
        with pytest.raises(APIConnectionError) as e:
            invalid_zip_path = os.getcwd() + "/test/test_file/invalid.zip"
            self.api.create_detector(
                file=invalid_zip_path, name=name, detectorType=detector_type
            )
        assert "No such file or directory" in str(e)

        res = self.api.create_detector(file=file, name=name, detectorType=detector_type)
        assert res["detectorId"] != None

        print_test_pass()
        return res["detectorId"]
Пример #18
0
    def update_annotations_test(self, detector_id, label_id, image_id, bbox):
        with pytest.raises(APIError) as e:
            self.api.update_annotations(
                detectorId=detector_id, labelId=label_id, images=[]
            )
        assert "invalid_query_err" in str(e)

        res = self.api.update_annotations(
            detectorId=detector_id,
            labelId=label_id,
            images=[{"id": image_id, "bbox": bbox}],
        )
        assert res["message"] == "successfully updated 1 images"
        print_test_pass()
Пример #19
0
    def create_label_with_images_with_images_test(self, name, detector_id, image_files):
        with pytest.raises(APIError) as e:
            self.api.create_label_with_images(
                detectorId=RANDOM_MONGO_ID, name=name, imageFiles=image_files
            )
        assert "invalid_query_err" in str(e)

        res = self.api.create_label_with_images(
            detectorId=detector_id, name=name, imageFiles=image_files
        )
        assert "successfully uploaded 1 images to label" in res["message"]

        print_test_pass()
        return res["labelId"]
Пример #20
0
 def query_collection_by_image_test(self, task_id, url):
     res = self.api.query_collection_by_image(
         taskId=task_id,
         numResults=1,
         url=url,
         boundingBox={
             "top": 0.1,
             "left": 0.1,
             "height": 0.8,
             "width": 0.8
         },
     )
     assert res["results"] != None
     print_test_pass()
Пример #21
0
    def import_detector_test(
        self, name, input_tensor, output_tensor, detector_type, file_proto, labels
    ):
        res = self.api.import_detector(
            name=name,
            inputTensor=input_tensor,
            outputTensor=output_tensor,
            detectorType=detector_type,
            fileProto=file_proto,
            labels=labels,
        )

        assert res["detectorId"] != None

        print_test_pass()
        return res["detectorId"]
Пример #22
0
    def create_collection_index_test(self, collection_id):
        with pytest.raises(APIError) as e:
            self.api.create_collection_index(
                collectionId=collection_id,
                detectorId=RANDOM_MONGO_ID,
                fileTypes="images",
            )
        assert "invalid_query_err" in str(e)

        res = self.api.create_collection_index(
            collectionId=collection_id,
            detectorId=EVERYDAY_OBJECT_DETECTOR_ID,
            fileTypes="images",
        )
        task_id = res["collectionTask"]["_id"]
        assert task_id != None

        print_test_pass()
        return task_id
Пример #23
0
    def create_video_summary_test(self, url=None, videoId=None, file=None):
        if url and file:
            with pytest.raises(APIError) as e:
                self.api.create_video_summary(url=url, file=file)
            assert "You may only specify a file or a URL, not both" in str(e)

        if url:
            with pytest.raises(APIError) as e:
                self.api.create_video_summary(url=TEST_LOCAL_VIDEO_URL)
            assert "You provided an invalid URL" in str(e)

            res = self.api.create_video_summary(url=url,)
        if file:
            res = self.api.create_video_summary(file=file,)

        assert res["summary"] != None
        assert res["summary"]["video"] != None

        print_test_pass()
        return res["summary"]["_id"]
Пример #24
0
    def create_collection_test(self):
        with pytest.raises(APIError) as e:
            self.api.create_collection(name="invalid-collection",
                                       url="invalid-url",
                                       sourceType="s3")
        assert "invalid_query_err" in str(e)

        # should create collection with correct params
        sourceType = "s3"
        res = self.api.create_collection(name=COLLECTION_NAME,
                                         url=S3_BUCKET_URL,
                                         sourceType=sourceType)
        collection_id = res["collection"]["_id"]
        assert collection_id != None
        assert res["collection"]["name"] == COLLECTION_NAME
        assert res["collection"]["url"] == S3_BUCKET_URL
        assert res["collection"]["sourceType"] == sourceType
        assert len(res["collection"]["detectingTasks"]) == 0

        print_test_pass()
        return collection_id
Пример #25
0
 def delete_stream_test(self, stream_id):
     res = self.api.delete_stream(streamId=stream_id)
     assert res["message"] == "Successfully deleted stream."
     print_test_pass()
Пример #26
0
 def delete_monitoring_test(self, monitoring_id):
     res = self.api.delete_monitoring(monitoringId=monitoring_id)
     assert res["message"] == "Successfully deleted monitoring."
     print_test_pass()
Пример #27
0
 def kill_monitoring_test(self, monitoring_id):
     res = self.api.kill_monitoring(monitoringId=monitoring_id)
     assert res["message"] == "Successfully killed monitoring."
     print_test_pass()
Пример #28
0
 def get_monitoring_result_test(self, monitoring_id):
     res = self.api.get_monitoring_result(monitoringId=monitoring_id)
     assert res != None
     print_test_pass()
Пример #29
0
 def search_streams_test(self):
     res = self.api.search_streams(permission="private")
     assert res[0]["streamId"] != None
     print_test_pass()
Пример #30
0
 def search_monitorings_test(self, stream_id, monitoring_id):
     res = self.api.search_monitorings(streamId=stream_id)
     assert res[0]["monitoringId"] == monitoring_id
     print_test_pass()