Esempio n. 1
0
    def test_download_and_extract_zip_file_when_download_fails(self, mock_logger):
        e = "Error description"
        responses.add(
            responses.GET, self.req_url,
            body=Exception(e))
        error_message = "Failed to fetch file from {}, error {}".format(self.req_url, e)

        download_and_extract_zip_file(self.req_url, self.download_location, self.extract_location)

        mock_logger.assert_called_with(error_message)
Esempio n. 2
0
    def test_download_and_extract_zip_file_success(self, mock_extract_zip, mock_delete_zip):
        responses.add(
            responses.GET, self.req_url,
            content_type="application/zip",
            body=self.zip_file.getvalue(), status=200)

        download_and_extract_zip_file(self.req_url, self.download_location, self.extract_location)

        with open(self.download_location, "rb") as downloaded:
            self.assertEqual(downloaded.read(), self.zip_file.getvalue())
        mock_extract_zip.assert_called_with(self.download_location, self.extract_location)
        mock_delete_zip.assert_called_with(self.download_location)