Python django.test() Examples
The following are 30
code examples of django.test().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django
, or try the search function
.
Example #1
Source File: test_error.py From scale with Apache License 2.0 | 6 votes |
def test_create_error_model(self): """Validate that a complete Error model is created using JobError """ job_type_name = 'test-job' name = 'bad-data' title = 'Bad Data' description = 'Error received when bad data is detected' category = 'DATA' error = JobError(job_type_name, name, title, description, category) model = error.create_model() self.assertEqual(model.name, name) self.assertEqual(model.title, title) self.assertEqual(model.description, description) self.assertEqual(model.category, category) self.assertEqual(model.job_type_name, job_type_name)
Example #2
Source File: test_middleware.py From django-cookies-samesite with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_supported_browsers(self, ua_string): session_name = 'sessionid-test' csrf_name = 'csrftoken-test' with self.settings( SESSION_COOKIE_NAME=session_name, CSRF_COOKIE_NAME=csrf_name, SESSION_COOKIE_SAMESITE='Lax' ): response = self.client.get( '/cookies-test/', HTTP_USER_AGENT=ua_string, ) self.assertEqual(response.cookies[session_name]['samesite'], 'Lax') self.assertEqual(response.cookies[csrf_name]['samesite'], 'Lax') cookies_string = sorted(response.cookies.output().split('\r\n')) self.assertTrue('; SameSite=Lax' in cookies_string[0]) self.assertTrue('; SameSite=Lax' in cookies_string[2])
Example #3
Source File: test_middleware.py From django-cookies-samesite with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_unsupported_browsers(self, ua_string): session_name = 'sessionid-test' csrf_name = 'csrftoken-test' with self.settings( SESSION_COOKIE_NAME=session_name, CSRF_COOKIE_NAME=csrf_name, SESSION_COOKIE_SAMESITE='Lax' ): response = self.client.get( '/cookies-test/', HTTP_USER_AGENT=ua_string, ) self.assertEqual(response.cookies[session_name]['samesite'], '') self.assertEqual(response.cookies[csrf_name]['samesite'], '') cookies_string = sorted(response.cookies.output().split('\r\n')) self.assertTrue('; SameSite=Lax' not in cookies_string[0]) self.assertTrue('; SameSite=Lax' not in cookies_string[1])
Example #4
Source File: test_middleware.py From django-cookies-samesite with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_cookie_names_changed(self): session_name = 'sessionid-test' csrf_name = 'csrftoken-test' with self.settings( SESSION_COOKIE_NAME=session_name, CSRF_COOKIE_NAME=csrf_name, SESSION_COOKIE_SAMESITE='Lax' ): response = self.client.get('/cookies-test/') self.assertEqual(response.cookies[session_name]['samesite'], 'Lax') self.assertEqual(response.cookies[csrf_name]['samesite'], 'Lax') cookies_string = sorted(response.cookies.output().split('\r\n')) self.assertTrue(csrf_name + '=' in cookies_string[0]) self.assertTrue('; SameSite=Lax' in cookies_string[0]) self.assertTrue(session_name + '=' in cookies_string[2]) self.assertTrue('; SameSite=Lax' in cookies_string[2])
Example #5
Source File: test_scale_post_steps.py From scale with Apache License 2.0 | 6 votes |
def test_scale_post_steps_successful(self, mock_env_vars, mock_job_exe_manager): """Tests successfully executing scale_post_steps.""" # Set up mocks def get_env_vars(name, *args, **kwargs): return str(self.job.id) if name == 'SCALE_JOB_ID' else str(self.job_exe.exe_num) mock_env_vars.side_effect = get_env_vars mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.return_value = RESULTS mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.id = self.job_exe.id mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_id = self.job_exe.job_id mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type_id = self.job_exe.job_type_id mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.exe_num = self.job_exe.exe_num # Call method to test cmd = PostCommand() cmd.run_from_argv(['manage.py', 'scale_post_steps']) # Check results job_exe_output = JobExecutionOutput.objects.get(job_exe_id=self.job_exe.id) self.assertDictEqual(job_exe_output.get_output().get_dict(), JOB_RESULTS.get_dict())
Example #6
Source File: test_middleware.py From django-cookies-samesite with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_cookie_samesite_django30(self): # Raise DeprecationWarning for newer versions of Django with patch('django.get_version', return_value=DJANGO_SUPPORTED_VERSION): with self.assertRaises(DeprecationWarning) as exc: self.client.get('/cookies-test/') self.assertEqual(exc.exception.args[0], ( 'Your version of Django supports SameSite flag in the cookies mechanism. ' 'You should remove django-cookies-samesite from your project.' )) with patch('django_cookies_samesite.middleware.django.get_version', return_value=DJANGO_SUPPORTED_VERSION): with self.assertRaises(DeprecationWarning) as exc: self.client.get('/cookies-test/') self.assertEqual(exc.exception.args[0], ( 'Your version of Django supports SameSite flag in the cookies mechanism. ' 'You should remove django-cookies-samesite from your project.' ))
Example #7
Source File: test_middleware.py From django-cookies-samesite with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_cookie_samesite_none_force_all(self): with self.settings(SESSION_COOKIE_SAMESITE='None', SESSION_COOKIE_SAMESITE_FORCE_ALL=True): response = self.client.get('/cookies-test/') self.assertEqual(response.cookies['sessionid']['samesite'], 'None') self.assertEqual(response.cookies['csrftoken']['samesite'], 'None') self.assertEqual(response.cookies['custom_cookie']['samesite'], 'None') self.assertEqual(response.cookies['zcustom_cookie']['samesite'], 'None') cookies_string = sorted(response.cookies.output().split('\r\n')) self.assertTrue('custom_cookie=' in cookies_string[1]) self.assertTrue('; SameSite=None' in cookies_string[1]) self.assertTrue('csrftoken=' in cookies_string[0]) self.assertTrue('; SameSite=None' in cookies_string[0]) self.assertTrue('sessionid=' in cookies_string[2]) self.assertTrue('; SameSite=None' in cookies_string[2]) self.assertTrue('zcustom_cookie=' in cookies_string[3]) self.assertTrue('; SameSite=None' in cookies_string[3])
Example #8
Source File: tests.py From django-seo with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_path_conflict(self): """ Check the crazy scenario where an existing metadata object has the same path. """ old_path = self.product_metadata._path self.product_metadata._path = '/products/2/' self.product_metadata.save() self.assertEqual(self.product_metadata._object_id, self.product.pk) # Create a new product that will take the same path new_product = Product.objects.create() Coverage._meta.get_model('modelinstance').objects.filter(_content_type=self.product_content_type, _object_id=new_product.id).update(title="New Title") # This test will not work if we have the id wrong if new_product.id != 2: raise Exception("Test Error: the product ID is not as expected, this test cannot work.") # Check that the existing path was corrected product_metadata = Coverage._meta.get_model('modelinstance').objects.get(id=self.product_metadata.id) self.assertEqual(old_path, product_metadata._path) # Check the new data is available under the correct path metadata = get_metadata(path="/products/2/") self.assertEqual(metadata.title.value, u"New Title")
Example #9
Source File: test_mapping.py From scale with Apache License 2.0 | 6 votes |
def test_save_models(self): """Tests calling JobErrorMapping.save_models() successfully""" job_type_name = 'test-job' mapping = JobErrorMapping(job_type_name) error_1 = JobError(job_type_name, 'mapped_error_1', title='Title', description='Description', category='ALGORITHM') error_2 = JobError(job_type_name, 'mapped_error_2', category='DATA') mapping.add_mapping(1, error_1) mapping.add_mapping(2, error_2) # Make sure error models are created successfully mapping.save_models() self.assertEqual(Error.objects.filter(job_type_name=job_type_name).count(), 2) # Make some changes error_1.description = 'New description' error_2.category = 'ALGORITHM' # Make sure error models are updated successfully mapping.save_models() self.assertEqual(Error.objects.get(name='mapped_error_1').description, 'New description') self.assertEqual(Error.objects.get(name='mapped_error_2').category, 'ALGORITHM')
Example #10
Source File: test_scale_post_steps.py From scale with Apache License 2.0 | 6 votes |
def test_scale_post_steps_no_stderr(self, mock_env_vars, mock_job_exe_manager): """Tests successfully executing scale_post_steps.""" # Set up mocks def get_env_vars(name, *args, **kwargs): return str(self.job.id) if name == 'SCALE_JOB_ID' else str(self.job_exe.exe_num) mock_env_vars.side_effect = get_env_vars mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.stdout = 'something' mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.stderr = None mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.return_value = RESULTS mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.id = self.job_exe.id mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_id = self.job_exe.job_id mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type_id = self.job_exe.job_type_id mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.exe_num = self.job_exe.exe_num # Call method to test cmd = PostCommand() cmd.run_from_argv(['manage.py', 'scale_post_steps']) # Check results job_exe_output = JobExecutionOutput.objects.get(job_exe_id= self.job_exe.id) self.assertDictEqual(job_exe_output.get_output().get_dict(), JOB_RESULTS.get_dict())
Example #11
Source File: test_job_interface.py From scale with Apache License 2.0 | 6 votes |
def test_input_data_names_must_be_unique(self): definition = { 'command': 'test-command', 'command_arguments': '${param-1}', 'version': '1.0', 'input_data': [{ 'name': 'param-1', 'type': 'file', }, { 'name': 'param-1', 'type': 'property', }] } try: JobInterface(definition) self.fail('Expected invalid job definition to throw an exception') except InvalidInterfaceDefinition: pass
Example #12
Source File: conftest.py From django-phone-verify with GNU General Public License v3.0 | 6 votes |
def client(): """Django Test Client, with some convenient overriden methods. """ from django.test import Client class _Client(Client): @property def json(self): """Add json method on the client for sending json type request. Usages: >>> import json >>> url = reverse("phone-verify") >>> client.json.get(url) >>> client.json.post(url, data=json.dumps(payload)) """ return PartialMethodCaller( obj=self, content_type='application/json;charset="utf-8"' ) return _Client()
Example #13
Source File: test_checks.py From django-hijack-admin with MIT License | 6 votes |
def test_check_custom_user_model_default_admin(self): # Django doesn't re-register admins when using `override_settings`, # so we have to do it manually in this test case. admin.site.register(get_user_model(), UserAdmin) warnings = checks.check_custom_user_model(HijackAdminConfig) expected_warnings = [ Warning( 'django-hijack-admin does not work out the box with a custom user model.', hint='Please mix HijackUserAdminMixin into your custom UserAdmin.', obj=settings.AUTH_USER_MODEL, id='hijack_admin.W001', ) ] self.assertEqual(warnings, expected_warnings) admin.site.unregister(get_user_model())
Example #14
Source File: test_configurators.py From scale with Apache License 2.0 | 5 votes |
def test_configure_queued_job_ingest_without_new_workspace(self, mock_msg_mgr): """Tests successfully calling configure_queued_job() on an ingest job without a new workspace""" workspace_1 = storage_test_utils.create_workspace() from ingest.models import Ingest from ingest.test import utils as ingest_test_utils scan = ingest_test_utils.create_scan() ingest = ingest_test_utils.create_ingest(scan=scan, workspace=workspace_1) message = create_scan_ingest_job_message(ingest.id, scan.id) result = message.execute() ingest = Ingest.objects.get(pk=ingest.id) expected_args = 'scale_ingest -i %s' % str(ingest.id) expected_env_vars = {'INGEST_ID': str(ingest.id), 'WORKSPACE': workspace_1.name} expected_workspaces = {workspace_1.name: {'mode': 'rw'}} expected_config = {'version': '2.0', 'tasks': [{'type': 'main', 'args': expected_args, 'env_vars': expected_env_vars, 'workspaces': expected_workspaces}]} configurator = QueuedExecutionConfigurator({}) # Test method exe_config = configurator.configure_queued_job(ingest.job) config_dict = exe_config.get_dict() # Make sure the dict validates ExecutionConfiguration(config_dict) self.assertDictEqual(config_dict, expected_config)
Example #15
Source File: test_scale_post_steps.py From scale with Apache License 2.0 | 5 votes |
def test_scale_post_steps_io_error(self, mock_env_vars, mock_job_exe_manager, mock_sys_exit): """Tests executing scale_post_steps when an IO error occurs.""" # Set up mocks def get_env_vars(name, *args, **kwargs): return str(self.job.id) if name == 'SCALE_JOB_ID' else str(self.job_exe.exe_num) mock_env_vars.side_effect = get_env_vars mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.side_effect = IOError() # Call method to test cmd = PostCommand() cmd.run_from_argv(['manage.py', 'scale_post_steps']) # Check results mock_sys_exit.assert_called_with(ScaleIOError().exit_code)
Example #16
Source File: test_job_interface.py From scale with Apache License 2.0 | 5 votes |
def test_files_in_command(self, mock_retrieve_call, mock_os_mkdir, mock_isdir): def new_retrieve(arg1): return { 'files1_out': ['/test/file1/foo.txt', '/test/file1/bar.txt'], } mock_retrieve_call.side_effect = new_retrieve job_interface_dict, job_data_dict, job_environment_dict = self._get_simple_interface_data_env() job_interface_dict['command_arguments'] = '${files1}' job_interface_dict['input_data'] = [{ 'name': 'files1', 'type': 'files', 'required': True, }] job_data_dict['input_data'].append({ 'name': 'files1', 'file_ids': [1, 2, 3], }) job_data_dict['output_data'].append({ 'name': 'files1_out', 'workspace_id': self.workspace.id, }) job_interface = JobInterface(job_interface_dict) job_data = JobData(job_data_dict) job_environment = job_environment_dict job_exe_id = 1 job_interface.perform_pre_steps(job_data) job_command_arguments = job_interface.fully_populate_command_argument(job_data, job_environment, job_exe_id) expected_command_arguments = os.path.join(SCALE_JOB_EXE_INPUT_PATH, 'files1') self.assertEqual(job_command_arguments, expected_command_arguments, 'expected a different command from pre_steps')
Example #17
Source File: test_job_interface.py From scale with Apache License 2.0 | 5 votes |
def test_command_string_special_formats_should_have_dollar_sign(self): definition = { 'command': 'test-command', 'command_arguments': '${param-1:-f param-1}', 'version': '1.0', 'input_data': [{ 'name': 'param-1', 'type': 'file', }] } try: JobInterface(definition) self.fail('Expected invalid job definition to throw an exception') except InvalidInterfaceDefinition: pass
Example #18
Source File: test_scale_post_steps.py From scale with Apache License 2.0 | 5 votes |
def test_scale_post_steps_database_operation_error(self, mock_env_vars, mock_db, mock_sys_exit): """Tests executing scale_post_steps when a database operation error occurs.""" # Set up mocks def get_env_vars(name, *args, **kwargs): return str(self.job.id) if name == 'SCALE_JOB_ID' else str(self.job_exe.exe_num) mock_env_vars.side_effect = get_env_vars mock_db.side_effect = OperationalError() # Call method to test cmd = PostCommand() cmd.run_from_argv(['manage.py', 'scale_post_steps']) # Check results mock_sys_exit.assert_called_with(ScaleOperationalError().exit_code)
Example #19
Source File: test_job_interface.py From scale with Apache License 2.0 | 5 votes |
def test_minimal_input_validation(self): definition = { 'command': 'test-command', 'command_arguments': 'some_argument', 'version': '1.0', } try: JobInterface(definition) except InvalidInterfaceDefinition: self.fail('A valid definition should not raise an Exception')
Example #20
Source File: test_job_interface.py From scale with Apache License 2.0 | 5 votes |
def test_command_param_will_fail_without_input(self): definition = { 'command': 'test-command', 'command_arguments': '${param-1}', 'version': '1.0', } try: JobInterface(definition) self.fail('Expected invalid job definition to throw an exception') except InvalidInterfaceDefinition: pass
Example #21
Source File: test_configurators.py From scale with Apache License 2.0 | 5 votes |
def test_configure_queued_job_scan(self, mock_msg_mgr): """Tests successfully calling configure_queued_job() on a Scan job""" workspace = storage_test_utils.create_workspace() configuration = {'version': '1.0', 'workspace': workspace.name, 'scanner': {'type': 'dir'}, 'recursive': True, 'files_to_ingest': [{'filename_regex': '.*'}]} from ingest.models import Scan from ingest.test import utils as ingest_test_utils scan = ingest_test_utils.create_scan(configuration=configuration) scan = Scan.objects.queue_scan(scan.id, False) expected_args = 'scale_scan -i %s -d False' % str(scan.id) expected_env_vars = {'SCAN_ID': str(scan.id), 'DRY_RUN': str(False)} expected_workspaces = {workspace.name: {'mode': 'rw'}} expected_config = {'version': '2.0', 'tasks': [{'type': 'main', 'args': expected_args, 'env_vars': expected_env_vars, 'workspaces': expected_workspaces}]} configurator = QueuedExecutionConfigurator({}) # Test method exe_config = configurator.configure_queued_job(scan.job) config_dict = exe_config.get_dict() # Make sure the dict validates ExecutionConfiguration(config_dict) self.assertDictEqual(config_dict, expected_config)
Example #22
Source File: test_configurators.py From scale with Apache License 2.0 | 5 votes |
def test_configure_queued_job_strike(self, mock_msg_mgr): """Tests successfully calling configure_queued_job() on a Strike job""" wksp_config_1 = {'version': '1.0', 'broker': {'type': 'host', 'host_path': '/my/path'}} workspace_1 = storage_test_utils.create_workspace(json_config=wksp_config_1) wksp_config_2 = {'version': '1.0', 'broker': {'type': 'host', 'host_path': '/other/my/path'}} workspace_2 = storage_test_utils.create_workspace(json_config=wksp_config_2) configuration = {'version': '2.0', 'workspace': workspace_1.name, 'monitor': {'type': 'dir-watcher', 'transfer_suffix': '_tmp'}, 'files_to_ingest': [{'filename_regex': '.*txt', 'new_workspace': workspace_2.name}]} from ingest.test import utils as ingest_test_utils strike = ingest_test_utils.create_strike(configuration=configuration) strike.job.input = {'json': {'STRIKE_ID': str(strike.id)}} strike.job.status = 'QUEUED' strike.job.save() expected_args = 'scale_strike -i %s' % str(strike.id) expected_env_vars = {'STRIKE_ID': str(strike.id)} expected_workspaces = {workspace_1.name: {'mode': 'rw'}} expected_config = {'version': '2.0', 'tasks': [{'type': 'main', 'args': expected_args, 'env_vars': expected_env_vars, 'workspaces': expected_workspaces}]} configurator = QueuedExecutionConfigurator({}) # Test method exe_config = configurator.configure_queued_job(strike.job) config_dict = exe_config.get_dict() # Make sure the dict validates ExecutionConfiguration(config_dict) self.assertDictEqual(config_dict, expected_config)
Example #23
Source File: test_scale_pre_steps.py From scale with Apache License 2.0 | 5 votes |
def test_scale_pre_steps_database_error(self, mock_env_vars, mock_db, mock_sys_exit): """Tests executing scale_pre_steps when a database error occurs.""" # Set up mocks def get_env_vars(name, *args, **kwargs): return str(self.seed_job.id) if name == 'SCALE_JOB_ID' else str(self.seed_exe.exe_num) mock_env_vars.side_effect = get_env_vars mock_db.side_effect = DatabaseError() # Call method to test cmd = PreCommand() cmd.run_from_argv(['manage.py', 'scale_pre_steps']) # Check results mock_sys_exit.assert_called_with(ScaleDatabaseError().exit_code)
Example #24
Source File: test_configurators.py From scale with Apache License 2.0 | 5 votes |
def test_configure_queued_job_old_ingest(self): """Tests successfully calling configure_queued_job() on an old (before revision 3) ingest job""" workspace_1 = storage_test_utils.create_workspace() workspace_2 = storage_test_utils.create_workspace() from ingest.test import utils as ingest_test_utils from ingest.models import Ingest ingest = ingest_test_utils.create_ingest(workspace=workspace_1, new_workspace=workspace_2) ingest_job_type = Ingest.objects.get_ingest_job_type() ingest_rev_2 = JobTypeRevision.objects.get(job_type=ingest_job_type, revision_num=2) ingest.job.job_type_rev = ingest_rev_2 # Job has old revision (2nd) of ingest job type ingest.job.input = {'json': {'ingest_id': str(ingest.id)}} ingest.job.status = 'QUEUED' ingest.job.save() expected_args = 'scale_ingest -i %s' % str(ingest.id) expected_env_vars = {'INGEST_ID': str(ingest.id)} expected_workspaces = {workspace_1.name: {'mode': 'rw'}, workspace_2.name: {'mode': 'rw'}} expected_config = {'version': '2.0', 'tasks': [{'type': 'main', 'args': expected_args, 'env_vars': expected_env_vars, 'workspaces': expected_workspaces}]} configurator = QueuedExecutionConfigurator({}) # Test method exe_config = configurator.configure_queued_job(ingest.job) config_dict = exe_config.get_dict() # Make sure the dict validates ExecutionConfiguration(config_dict) self.assertDictEqual(config_dict, expected_config)
Example #25
Source File: test_manager.py From scale with Apache License 2.0 | 5 votes |
def get_resources(self): """Returns the resources that are required/have been scheduled for this task :returns: The scheduled resources for this task :rtype: :class:`node.resources.node_resources.NodeResources` """ return NodeResources() # Non-abstract class to test implementation of base Task class
Example #26
Source File: test_manager.py From scale with Apache License 2.0 | 5 votes |
def get_resources(self): """Returns the resources that are required/have been scheduled for this task :returns: The scheduled resources for this task :rtype: :class:`node.resources.node_resources.NodeResources` """ return NodeResources() # Non-abstract class to test implementation of base SystemTask class
Example #27
Source File: test_clock.py From scale with Apache License 2.0 | 5 votes |
def test_multiple_processors(self): """Tests running multiple processors for the same trigger rule.""" clock.register_processor('test-name', lambda: self.processor) rule = job_test_utils.create_clock_rule(name='test-name', event_type='TEST_TYPE') clock._trigger_event(rule) self.assertEqual(self.processor.process_event.call_count, 2)
Example #28
Source File: test_clock.py From scale with Apache License 2.0 | 5 votes |
def test_trigger_event_last(self): """Tests triggering a new event after the rule has processed an event previously.""" rule = job_test_utils.create_clock_rule(name='test-name', event_type='TEST_TYPE') last = job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2015, 1, 1, tzinfo=utc)) clock._trigger_event(rule, last) events = TriggerEvent.objects.filter(type='TEST_TYPE').order_by('-occurred') self.assertEqual(len(events), 2) self.assertNotEqual(events[0], last) self.processor.process_event.assert_called_with(events[0], last)
Example #29
Source File: test_clock.py From scale with Apache License 2.0 | 5 votes |
def test_trigger_event_first(self): """Tests triggering a new event the first time for a rule.""" rule = job_test_utils.create_clock_rule(name='test-name', event_type='TEST_TYPE') clock._trigger_event(rule, None) events = TriggerEvent.objects.filter(type='TEST_TYPE') self.assertEqual(len(events), 1) self.processor.process_event.assert_called_with(events[0], None)
Example #30
Source File: test_clock.py From scale with Apache License 2.0 | 5 votes |
def test_check_rule_last_event(self, mock_check_schedule, mock_trigger_event): """Tests a valid rule checks the most recent matching event type.""" rule = job_test_utils.create_clock_rule(name='test-name', schedule='PT1H0M0S') job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2013, 1, 1, tzinfo=utc)) job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2012, 1, 1, tzinfo=utc)) last = job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2014, 1, 1, tzinfo=utc)) job_test_utils.create_clock_event(rule=rule, occurred=datetime.datetime(2011, 1, 1, tzinfo=utc)) job_test_utils.create_clock_event(occurred=datetime.datetime(2015, 1, 1, tzinfo=utc)) clock._check_rule(rule) mock_check_schedule.assert_called_with(datetime.timedelta(hours=1), last)