Exemplo n.º 1
0
    def testExistsIsNyUpload(
        self, mock_get_all_tx: Mock, mock_open: Mock, mock_get: Mock
    ) -> None:
        historical_path = build_path(HISTORICAL_BUCKET, "new_york", EXISTING_PDF_NAME)
        upload_path = build_path(UPLOAD_BUCKET, "new_york", EXISTING_PDF_NAME)
        # Make the info call return an older modified time than the server time.
        self.fs.test_add_path(historical_path, local_path=None)
        mock_get_all_tx.return_value = {EXISTING_TEST_URL}
        mock_get.side_effect = _MockGet

        headers = {"X-Appengine-Cron": "test-cron"}
        response = self.client.get("/scrape_state?state=new_york", headers=headers)
        self.assertEqual(response.status_code, 200)

        self.assertListEqual(self.fs.all_paths, [historical_path, upload_path])
        mock_open.assert_called_with(ANY, "wb")
        mock_get.assert_called_with(EXISTING_TEST_URL, verify=True)
Exemplo n.º 2
0
    def testMultipleUrlsOne200OneNoExists(
        self, mock_get_all_tx: Mock, mock_open: Mock, mock_get: Mock
    ) -> None:
        historical_path1 = build_path(HISTORICAL_BUCKET, "texas", EXISTING_PDF_NAME)
        upload_path2 = build_path(UPLOAD_BUCKET, "texas", EXISTING_PDF_NAME2)

        # Make the info call return an older modified time than the server time.
        self.fs.test_add_path(historical_path1, local_path=None)
        mock_get_all_tx.return_value = {EXISTING_TEST_URL, EXISTING_TEST_URL2}
        mock_get.side_effect = _MockGet

        headers = {"X-Appengine-Cron": "test-cron"}
        response = self.client.get("/scrape_state?state=texas", headers=headers)
        self.assertEqual(response.status_code, 200)

        self.assertCountEqual(self.fs.all_paths, [historical_path1, upload_path2])
        self.assertListEqual(mock_open.call_args_list, [call(ANY, "wb")])
        self.assertCountEqual(
            mock_get.call_args_list, [call(EXISTING_TEST_URL2, verify=True)]
        )
Exemplo n.º 3
0
    def testExistsNoUpload(
        self, mock_get_all_tx: Mock, mock_open: Mock, mock_get: Mock
    ) -> None:
        historical_path = build_path(HISTORICAL_BUCKET, "texas", EXISTING_PDF_NAME)
        # Make the info call return an older modified time than the server time.
        self.fs.test_add_path(historical_path, local_path=None)
        self.fs.test_set_delegate(FailOnUploadDelegate())
        mock_get_all_tx.return_value = {EXISTING_TEST_URL}
        mock_get.side_effect = _MockGet

        headers = {"X-Appengine-Cron": "test-cron"}
        response = self.client.get("/scrape_state?state=texas", headers=headers)
        self.assertEqual(response.status_code, 200)

        self.assertListEqual(self.fs.all_paths, [historical_path])
        self.assertEqual(mock_open.called, False)
Exemplo n.º 4
0
    def testCaNoExistsUpload200(
        self, mock_get_all_ca: Mock, mock_open: Mock, mock_post: Mock
    ) -> None:
        upload_path = build_path(UPLOAD_BUCKET, "california", EXISTING_CA_NAME)
        # Make the info call return an older modified time than the server time.
        mock_get_all_ca.return_value = [(EXISTING_TEST_URL_CA, CA_POST_DATA)]
        mock_post.side_effect = _MockGet

        headers = {"X-Appengine-Cron": "test-cron"}
        response = self.client.get("/scrape_state?state=california", headers=headers)
        self.assertEqual(response.status_code, 200)

        self.assertListEqual(self.fs.all_paths, [upload_path])
        mock_open.assert_called_with(ANY, "wb")
        mock_post.assert_called_with(
            EXISTING_TEST_URL_CA, data=CA_POST_DATA, verify=True
        )