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 spammodel 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 | from features import spammodel |
| 15 | from framework import urls |
| 16 | |
| 17 | |
| 18 | class TrainingDataExportTest(unittest.TestCase): |
| 19 | |
| 20 | def test_handler_definition(self): |
| 21 | instance = spammodel.TrainingDataExport() |
| 22 | self.assertIsInstance(instance, webapp2.RequestHandler) |
| 23 | |
| 24 | @mock.patch('framework.cloud_tasks_helpers._get_client') |
| 25 | def test_enqueues_task(self, get_client_mock): |
| 26 | spammodel.TrainingDataExport().get() |
| 27 | task = { |
| 28 | 'app_engine_http_request': |
| 29 | { |
| 30 | 'relative_uri': urls.SPAM_DATA_EXPORT_TASK + '.do', |
| 31 | 'body': '', |
| 32 | 'headers': { |
| 33 | 'Content-type': 'application/x-www-form-urlencoded' |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | get_client_mock().create_task.assert_called_once() |
| 38 | ((_parent, called_task), _kwargs) = get_client_mock().create_task.call_args |
| 39 | self.assertEqual(called_task, task) |