def setUp(self):
     self.image_path = get_file_path("test_jpg.jpg")
     self.img_bytes = azure_services.get_file_bytes(self.image_path)
     self.aod = azure_services.ObjectDetector(
         image_data=self.img_bytes,
         prediction_key=settings.OBJ_DET_PREDICTION_KEY,
         obj_det_url=settings.OBJ_DET_API_URL)
 def test_analyse_image_returns_none_with_non_image_input(self):
     txt_bytes = azure_services.get_file_bytes(
         get_file_path("test_file.txt"))
     aod = azure_services.ObjectDetector(
         image_data=txt_bytes,
         prediction_key=settings.OBJ_DET_PREDICTION_KEY,
         obj_det_url=settings.OBJ_DET_API_URL)
     results = aod.analyse_image()
     self.assertIsNone(results)
 def test_analyse_image_returns_none_with_bad_prediction_key(self):
     """
     Check that analyse_image returns None when prediction_key == None
     """
     aod = azure_services.ObjectDetector(
         image_data=self.img_bytes,
         prediction_key="invalid_pred_key",
         obj_det_url=settings.OBJ_DET_API_URL)
     results = aod.analyse_image()
     self.assertIsNone(results)
 def test_analyse_image_returns_none_with_bad_image_path(self):
     """
     Check that analyse_image returns None when image_path == None
     """
     aod = azure_services.ObjectDetector(
         image_data=None,
         prediction_key=settings.OBJ_DET_PREDICTION_KEY,
         obj_det_url=settings.OBJ_DET_API_URL)
     results = aod.analyse_image()
     self.assertIsNone(results)
 def test_analyse_image_returns_none_with_bad_api_url(self):
     """
     Check that analyse_image returns None when obj_det_url is invalid
     """
     # slice the last digit off the actual API URL
     invalid_url = settings.OBJ_DET_API_URL[:-1]
     aod = azure_services.ObjectDetector(
         image_data=self.img_bytes,
         prediction_key=settings.OBJ_DET_PREDICTION_KEY,
         obj_det_url=invalid_url)
     results = aod.analyse_image()
     self.assertIsNone(results)
    def test_analyse_image_returns_correct_data(self):
        """
        Check that analyse_image returns the correct results when provided the correct arguments 
        """
        # get actual results from Azure service
        aod = azure_services.ObjectDetector(
            image_data=self.img_bytes,
            prediction_key=settings.OBJ_DET_PREDICTION_KEY,
            obj_det_url=settings.OBJ_DET_API_URL)
        results = aod.analyse_image()
        # get expected results from features file
        expected_results = RESULTS.OBJ_DET_RESULTS

        # we cannot compare the two at the top level, because the results
        # include timestamps, UUIDs etc. that will differ. But the predictions
        # should be the same.
        self.assertListEqual(results["predictions"],
                             expected_results["predictions"])