Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | """Tests for the componentexport module.""" |
| 5 | |
| 6 | from __future__ import absolute_import |
| 7 | from __future__ import division |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import mock |
| 11 | import unittest |
| 12 | import webapp2 |
| 13 | |
| 14 | import settings |
| 15 | from features import componentexport |
| 16 | from framework import urls |
| 17 | |
| 18 | |
| 19 | class ComponentTrainingDataExportTest(unittest.TestCase): |
| 20 | |
| 21 | def test_handler_definition(self): |
| 22 | instance = componentexport.ComponentTrainingDataExport() |
| 23 | self.assertIsInstance(instance, webapp2.RequestHandler) |
| 24 | |
| 25 | @mock.patch('framework.cloud_tasks_helpers._get_client') |
| 26 | def test_enqueues_task(self, get_client_mock): |
| 27 | componentexport.ComponentTrainingDataExport().get() |
| 28 | |
| 29 | queue = 'componentexport' |
| 30 | task = { |
| 31 | 'app_engine_http_request': |
| 32 | { |
| 33 | 'http_method': 'GET', |
| 34 | 'relative_uri': urls.COMPONENT_DATA_EXPORT_TASK |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | get_client_mock().queue_path.assert_called_with( |
| 39 | settings.app_id, settings.CLOUD_TASKS_REGION, queue) |
| 40 | get_client_mock().create_task.assert_called_once() |
| 41 | ((_parent, called_task), _kwargs) = get_client_mock().create_task.call_args |
| 42 | self.assertEqual(called_task, task) |