def test_twilio_inbound_sms_auth(notify_db_session, notify_api, client, mocker, auth, usernames, passwords, status_code): mocker.patch('twilio.request_validator.RequestValidator.validate', return_value=True) mocker.patch( "app.notifications.receive_notifications.send_inbound_sms_to_service.apply_async" ) create_service_with_inbound_number( service_name='b', inbound_number='+61412345678', service_permissions=[EMAIL_TYPE, SMS_TYPE, INBOUND_SMS_TYPE]) data = urllib.parse.urlencode({ 'MessageSid': '1', 'From': '+61412999999', 'To': '+61412345678', 'Body': 'this is a message' }) with set_config_values( notify_api, { 'TWILIO_INBOUND_SMS_USERNAMES': usernames, 'TWILIO_INBOUND_SMS_PASSWORDS': passwords, }): response = twilio_post(client, data, auth=auth) assert response.status_code == status_code
def test_post_letter_notification_with_test_key_creates_pdf_and_sets_status_to_sending_and_sends_fake_response_file( notify_api, client, sample_letter_template, mocker, env): data = { 'template_id': str(sample_letter_template.id), 'personalisation': { 'address_line_1': 'Her Royal Highness Queen Elizabeth II', 'address_line_2': 'Buckingham Palace', 'address_line_3': 'London', 'postcode': 'SW1 1AA', 'name': 'Lizzie' }, 'reference': 'foo' } fake_create_letter_task = mocker.patch( 'app.celery.letters_pdf_tasks.create_letters_pdf.apply_async') fake_create_dvla_response_task = mocker.patch( 'app.celery.research_mode_tasks.create_fake_letter_response_file.apply_async' ) with set_config_values(notify_api, {'NOTIFY_ENVIRONMENT': env}): letter_request(client, data, service_id=sample_letter_template.service_id, key_type=KEY_TYPE_TEST) notification = Notification.query.one() fake_create_letter_task.assert_called_once_with( [str(notification.id)], queue='research-mode-tasks') assert fake_create_dvla_response_task.called assert notification.status == NOTIFICATION_SENDING
def test_should_use_default_sending_domain_and_email_from( sample_service, mock_email_client, sample_email_template_with_html, notify_api ): db_notification = create_notification( template=sample_email_template_with_html, to_field="*****@*****.**", personalisation={'name': 'Jo'} ) sample_service.sending_domain = None sample_service.email_from = None with set_config_values(notify_api, { 'NOTIFY_EMAIL_DOMAIN': 'default.email.domain', 'NOTIFY_EMAIL_FROM': 'default-email-from' }): send_to_providers.send_email_to_provider(db_notification) mock_email_client.send_email.assert_called_once_with( '"Sample service" <*****@*****.**>', '*****@*****.**', 'Jo <em>some HTML</em>', body='Hello Jo\nThis is an email from GOV.\u200bUK with <em>some HTML</em>\n', html_body=ANY, reply_to_address=None, attachments=[] )
def test_post_notification_does_not_use_save_queue_for_letters(client, sample_letter_template, mocker): mock_save = mocker.patch("app.v2.notifications.post_notifications.save_email_or_sms_to_queue") mock_create_pdf_task = mocker.patch('app.celery.tasks.letters_pdf_tasks.get_pdf_for_templated_letter.apply_async') with set_config_values(current_app, { 'HIGH_VOLUME_SERVICE': [str(sample_letter_template.service_id)], }): data = { 'template_id': str(sample_letter_template.id), 'personalisation': { 'address_line_1': 'Her Royal Highness Queen Elizabeth II', 'address_line_2': 'Buckingham Palace', 'address_line_3': 'London', 'postcode': 'SW1 1AA', } } response = client.post( path='/v2/notifications/letter', data=json.dumps(data), headers=[('Content-Type', 'application/json'), create_authorization_header(service_id=sample_letter_template.service_id)] ) assert response.status_code == 201 json_resp = response.get_json() assert not mock_save.called mock_create_pdf_task.assert_called_once_with([str(json_resp['id'])], queue='create-letters-pdf-tasks')
def test_post_letter_notification_with_test_key_creates_pdf_and_sets_status_to_sending_and_sends_fake_response_file( notify_api, client, sample_letter_template, mocker, env): data = { "template_id": str(sample_letter_template.id), "personalisation": { "address_line_1": "Her Royal Highness Queen Elizabeth II", "address_line_2": "Buckingham Palace", "address_line_3": "London", "postcode": "SW1 1AA", "name": "Lizzie", }, "reference": "foo", } fake_create_letter_task = mocker.patch( "app.celery.letters_pdf_tasks.create_letters_pdf.apply_async") fake_create_dvla_response_task = mocker.patch( "app.celery.research_mode_tasks.create_fake_letter_response_file.apply_async" ) with set_config_values(notify_api, {"NOTIFY_ENVIRONMENT": env}): letter_request( client, data, service_id=sample_letter_template.service_id, key_type=KEY_TYPE_TEST, ) notification = Notification.query.one() fake_create_letter_task.assert_called_once_with( [str(notification.id)], queue="research-mode-tasks") assert fake_create_dvla_response_task.called assert notification.status == NOTIFICATION_SENDING
def test_proxy_key_on_admin_auth_endpoint(notify_api, check_proxy_header, header_value, expected_status): token = create_jwt_token( current_app.config["ADMIN_CLIENT_SECRET"], current_app.config["ADMIN_CLIENT_USER_NAME"], ) with set_config_values( notify_api, { "ROUTE_SECRET_KEY_1": "key_1", "ROUTE_SECRET_KEY_2": "", "CHECK_PROXY_HEADER": check_proxy_header, }, ): with notify_api.test_client() as client: response = client.get( path="/service", headers=[ ("X-Custom-Forwarder", header_value), ("Authorization", "Bearer {}".format(token)), ], ) assert response.status_code == expected_status
def test_group_letters_splits_on_file_count(notify_api): letters = [ {'Key': 'A.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'B.pdf', 'Size': 2, 'ServiceId': '123'}, {'Key': 'C.pdf', 'Size': 3, 'ServiceId': '123'}, {'Key': 'D.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'E.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'F.pdf', 'Size': 5, 'ServiceId': '123'}, {'Key': 'G.pdf', 'Size': 6, 'ServiceId': '123'}, {'Key': 'H.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'I.pdf', 'Size': 1, 'ServiceId': '123'}, ] with set_config_values(notify_api, {'MAX_LETTER_PDF_COUNT_PER_ZIP': 3}): x = group_letters(letters) assert next(x) == [ {'Key': 'A.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'B.pdf', 'Size': 2, 'ServiceId': '123'}, {'Key': 'C.pdf', 'Size': 3, 'ServiceId': '123'} ] assert next(x) == [ {'Key': 'D.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'E.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'F.pdf', 'Size': 5, 'ServiceId': '123'} ] assert next(x) == [ {'Key': 'G.pdf', 'Size': 6, 'ServiceId': '123'}, {'Key': 'H.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'I.pdf', 'Size': 1, 'ServiceId': '123'} ] # make sure iterator is exhausted assert next(x, None) is None
def test_post_notifications_doesnt_use_save_queue_for_test_notifications( client, notify_db_session, mocker, notification_type ): save_task = mocker.patch(f"app.celery.tasks.save_api_{notification_type}.apply_async") mock_send_task = mocker.patch(f'app.celery.provider_tasks.deliver_{notification_type}.apply_async') service = create_service( service_name='high volume service', ) with set_config_values(current_app, { 'HIGH_VOLUME_SERVICE': [str(service.id)], }): template = create_template(service=service, content='((message))', template_type=notification_type) data = { "template_id": template.id, "personalisation": {"message": "Dear citizen, have a nice day"} } data.update({"email_address": "*****@*****.**"}) if notification_type == EMAIL_TYPE \ else data.update({"phone_number": "+447700900855"}) response = client.post( path=f'/v2/notifications/{notification_type}', data=json.dumps(data), headers=[('Content-Type', 'application/json'), create_authorization_header(service_id=service.id, key_type='test')] ) json_resp = response.get_json() assert response.status_code == 201 assert json_resp['id'] assert json_resp['content']['body'] == "Dear citizen, have a nice day" assert json_resp['template']['id'] == str(template.id) assert mock_send_task.called assert not save_task.called assert len(Notification.query.all()) == 1
def test_get_letters_pdf_calls_notifications_template_preview_service_correctly( notify_api, mocker, client, sample_letter_template, personalisation): contact_block = 'Mr Foo,\n1 Test Street,\nLondon\nN1' filename = 'opg' with set_config_values(notify_api, { 'TEMPLATE_PREVIEW_API_HOST': 'http://localhost/notifications-template-preview', 'TEMPLATE_PREVIEW_API_KEY': 'test-key' }): with requests_mock.Mocker() as request_mock: mock_post = request_mock.post( 'http://localhost/notifications-template-preview/print.pdf', content=b'\x00\x01', status_code=200) get_letters_pdf( sample_letter_template, contact_block=contact_block, filename=filename, values=personalisation) assert mock_post.last_request.json() == { 'values': personalisation, 'letter_contact_block': contact_block, 'filename': filename, 'template': { 'subject': sample_letter_template.subject, 'content': sample_letter_template.content, 'template_type': sample_letter_template.template_type } }
def test_switch_providers_on_slow_delivery_switches_once_then_does_not_switch_if_already_switched( notify_api, mocker, prepare_current_provider, sample_user, sample_template): mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user) starting_provider = get_current_provider('sms') _create_slow_delivery_notification(sample_template, starting_provider.identifier) _create_slow_delivery_notification(sample_template, starting_provider.identifier) with set_config_values(notify_api, {'SWITCH_SLOW_SMS_PROVIDER_ENABLED': True}): switch_current_sms_provider_on_slow_delivery() new_provider = get_current_provider('sms') _create_slow_delivery_notification(sample_template, new_provider.identifier) _create_slow_delivery_notification(sample_template, new_provider.identifier) switch_current_sms_provider_on_slow_delivery() final_provider = get_current_provider('sms') assert new_provider.identifier != starting_provider.identifier assert new_provider.priority < starting_provider.priority assert final_provider.identifier == new_provider.identifier
def test_group_letters_splits_on_file_size(notify_api, mocker): mocker.patch('app.celery.letters_pdf_tasks.letter_in_created_state', return_value=True) letters = [ # ends under max but next one is too big {'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2}, # ends on exactly max {'Key': 'C.pdf', 'Size': 3}, {'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1}, # exactly max goes in next file {'Key': 'F.pdf', 'Size': 5}, # if it's bigger than the max, still gets included {'Key': 'G.pdf', 'Size': 6}, # whatever's left goes in last list {'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1}, ] with set_config_values(notify_api, {'MAX_LETTER_PDF_ZIP_FILESIZE': 5}): x = group_letters(letters) assert next(x) == [{'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2}] assert next(x) == [{'Key': 'C.pdf', 'Size': 3}, {'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1}] assert next(x) == [{'Key': 'F.pdf', 'Size': 5}] assert next(x) == [{'Key': 'G.pdf', 'Size': 6}] assert next(x) == [{'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1}] # make sure iterator is exhausted assert next(x, None) is None
def test_preview_letter_template_precompiled_pdf_file_type( notify_api, client, admin_request, sample_service, mocker): template = create_template(sample_service, template_type='letter', template_name='Pre-compiled PDF', subject='Pre-compiled PDF', hidden=True) notification = create_notification(template) with set_config_values( notify_api, { 'TEMPLATE_PREVIEW_API_HOST': 'http://localhost/notifications-template-preview', 'TEMPLATE_PREVIEW_API_KEY': 'test-key' }): with requests_mock.Mocker(): content = b'\x00\x01' mock_get_letter_pdf = mocker.patch( 'app.template.rest.get_letter_pdf', return_value=content) resp = admin_request.get( 'template.preview_letter_template_by_notification_id', service_id=notification.service_id, notification_id=notification.id, file_type='pdf') assert mock_get_letter_pdf.called_once_with(notification) assert base64.b64decode(resp['content']) == content
def test_get_letters_pdf_calculates_billing_units(notify_api, mocker, client, sample_letter_template, page_count, expected_billable_units): contact_block = 'Mr Foo,\n1 Test Street,\nLondon\nN1' filename = 'opg' with set_config_values( notify_api, { 'TEMPLATE_PREVIEW_API_HOST': 'http://localhost/notifications-template-preview', 'TEMPLATE_PREVIEW_API_KEY': 'test-key' }): with requests_mock.Mocker() as request_mock: request_mock.post( 'http://localhost/notifications-template-preview/print.pdf', content=b'\x00\x01', headers={'X-pdf-page-count': page_count}, status_code=200) _, billable_units = get_letters_pdf(sample_letter_template, contact_block=contact_block, filename=filename, values=None) assert billable_units == expected_billable_units
def test_preview_letter_template_by_id_valid_file_type( notify_api, client, admin_request, sample_letter_notification): with set_config_values( notify_api, { 'TEMPLATE_PREVIEW_API_HOST': 'http://localhost/notifications-template-preview', 'TEMPLATE_PREVIEW_API_KEY': 'test-key' }): with requests_mock.Mocker() as request_mock: content = b'\x00\x01' mock_post = request_mock.post( 'http://localhost/notifications-template-preview/preview.pdf', content=content, headers={'X-pdf-page-count': '1'}, status_code=200) resp = admin_request.get( 'template.preview_letter_template_by_notification_id', service_id=sample_letter_notification.service_id, notification_id=sample_letter_notification.id, file_type='pdf') assert mock_post.last_request.json() assert base64.b64decode(resp['content']) == content
def test_preview_letter_template_by_id_template_preview_500( notify_api, client, admin_request, sample_letter_notification): with set_config_values( notify_api, { 'TEMPLATE_PREVIEW_API_HOST': 'http://localhost/notifications-template-preview', 'TEMPLATE_PREVIEW_API_KEY': 'test-key' }): import requests_mock with requests_mock.Mocker() as request_mock: content = b'\x00\x01' mock_post = request_mock.post( 'http://localhost/notifications-template-preview/preview.pdf', content=content, headers={'X-pdf-page-count': '1'}, status_code=404) resp = admin_request.get( 'template.preview_letter_template_by_notification_id', service_id=sample_letter_notification.service_id, notification_id=sample_letter_notification.id, file_type='pdf', _expected_status=500) assert mock_post.last_request.json() assert 'Status code: 404' in resp['message'] assert 'Error generating preview letter for {}'.format( sample_letter_notification.id) in resp['message']
def test_group_letters_splits_on_file_size_and_file_count(notify_api): letters = [ # ends under max file size but next file is too big {'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2}, # ends on exactly max number of files and file size {'Key': 'C.pdf', 'Size': 3}, {'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1}, # exactly max file size goes in next file {'Key': 'F.pdf', 'Size': 5}, # file size is within max but number of files reaches limit {'Key': 'G.pdf', 'Size': 1}, {'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1}, # whatever's left goes in last list {'Key': 'J.pdf', 'Size': 1}, ] with set_config_values(notify_api, { 'MAX_LETTER_PDF_ZIP_FILESIZE': 5, 'MAX_LETTER_PDF_COUNT_PER_ZIP': 3 }): x = group_letters(letters) assert next(x) == [{'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2}] assert next(x) == [{'Key': 'C.pdf', 'Size': 3}, {'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1}] assert next(x) == [{'Key': 'F.pdf', 'Size': 5}] assert next(x) == [{'Key': 'G.pdf', 'Size': 1}, {'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1}] assert next(x) == [{'Key': 'J.pdf', 'Size': 1}] # make sure iterator is exhausted assert next(x, None) is None
def test_create_fake_letter_response_file_calls_dvla_callback_on_development( notify_api, mocker): mocker.patch('app.celery.research_mode_tasks.file_exists', return_value=False) mocker.patch('app.celery.research_mode_tasks.s3upload') with set_config_values(notify_api, {'NOTIFY_ENVIRONMENT': 'development'}): with requests_mock.Mocker() as request_mock: request_mock.post( 'http://localhost:6011/notifications/letter/dvla', content=b'{}', status_code=200) create_fake_letter_response_file('random-ref') assert request_mock.last_request.json() == { "Type": "Notification", "MessageId": "some-message-id", "Message": ANY } assert json.loads(request_mock.last_request.json()['Message']) == { "Records": [{ "s3": { "object": { "key": dvla_response_file_matcher } } }] }
def test_get_letters_pdf_calculates_billing_units( notify_api, mocker, client, sample_letter_template, page_count, expected_billable_units, ): contact_block = "Mr Foo,\n1 Test Street,\nLondon\nN1" filename = "opg" with set_config_values( notify_api, { "TEMPLATE_PREVIEW_API_HOST": "http://localhost/notifications-template-preview", "TEMPLATE_PREVIEW_API_KEY": "test-key", }, ): with requests_mock.Mocker() as request_mock: request_mock.post( "http://localhost/notifications-template-preview/print.pdf", content=b"\x00\x01", headers={"X-pdf-page-count": page_count}, status_code=200, ) _, billable_units = get_letters_pdf( sample_letter_template, contact_block=contact_block, filename=filename, values=None, ) assert billable_units == expected_billable_units
def test_collate_letter_pdfs_to_be_sent(notify_api, sample_letter_template, mocker, time_to_run_task): with freeze_time("2020-02-17 18:00:00"): create_notification( template=sample_letter_template, status='created', reference='ref0', created_at=(datetime.now() - timedelta(hours=2)) ) create_notification( template=sample_letter_template, status='created', reference='ref1', created_at=(datetime.now() - timedelta(hours=3)) ) create_notification( template=sample_letter_template, status='created', reference='ref2', created_at=(datetime.now() - timedelta(days=2)) ) mocker.patch('app.celery.tasks.s3.head_s3_object', side_effect=[ {'ContentLength': 2}, {'ContentLength': 1}, {'ContentLength': 3}, ]) mock_celery = mocker.patch('app.celery.letters_pdf_tasks.notify_celery.send_task') with set_config_values(notify_api, {'MAX_LETTER_PDF_COUNT_PER_ZIP': 2}): with freeze_time(time_to_run_task): collate_letter_pdfs_to_be_sent() assert len(mock_celery.call_args_list) == 2 assert mock_celery.call_args_list[0] == call( name='zip-and-send-letter-pdfs', kwargs={ 'filenames_to_zip': [ '2020-02-16/NOTIFY.REF2.D.2.C.C.20200215180000.PDF', '2020-02-17/NOTIFY.REF1.D.2.C.C.20200217150000.PDF' ], 'upload_filename': 'NOTIFY.2020-02-17.001.k3x_WqC5KhB6e2DWv9Ma.ZIP' }, queue='process-ftp-tasks', compression='zlib' ) assert mock_celery.call_args_list[1] == call( name='zip-and-send-letter-pdfs', kwargs={ 'filenames_to_zip': [ '2020-02-17/NOTIFY.REF0.D.2.C.C.20200217160000.PDF' ], 'upload_filename': 'NOTIFY.2020-02-17.002.J85cUw-FWlKuAIOcwdLS.ZIP' }, queue='process-ftp-tasks', compression='zlib' )
def test_should_redirect_to_ui_and_clear_cookies( self, client, github_login_toggle_enabled, notify_api, cookie_config, github_data, db_session): with set_config_values(notify_api, cookie_config): client.get('/authorize') assert any(cookie.name == cookie_config['JWT_ACCESS_COOKIE_NAME'] for cookie in client.cookie_jar) with set_config_values(notify_api, cookie_config): response = client.get('/logout') assert response.status_code == 302 assert cookie_config['UI_HOST_NAME'] in response.location assert not any(cookie.name == cookie_config['JWT_ACCESS_COOKIE_NAME'] for cookie in client.cookie_jar)
def test_cronitor_does_nothing_if_cronitor_not_enabled(notify_api, rmock): with set_config_values(notify_api, { 'CRONITOR_ENABLED': False, 'CRONITOR_KEYS': {'hello': 'secret'} }): assert successful_task() == 1 assert rmock.called is False
def test_create_fake_letter_response_file_does_not_call_dvla_callback_on_preview( notify_api, mocker): mocker.patch('app.celery.research_mode_tasks.s3upload') with set_config_values(notify_api, {'NOTIFY_ENVIRONMENT': 'preview'}): with requests_mock.Mocker() as request_mock: create_fake_letter_response_file('example-ref') assert request_mock.last_request is None
def test_create_fake_letter_response_file_does_not_call_dvla_callback_on_preview(notify_api, mocker): mocker.patch("app.celery.research_mode_tasks.file_exists", return_value=False) mocker.patch("app.celery.research_mode_tasks.s3upload") with set_config_values(notify_api, {"NOTIFY_ENVIRONMENT": "preview"}): with requests_mock.Mocker() as request_mock: create_fake_letter_response_file("random-ref") assert request_mock.last_request is None
def test_cronitor_does_nothing_if_cronitor_not_enabled(notify_api, rmock): with set_config_values(notify_api, { "CRONITOR_ENABLED": False, "CRONITOR_KEYS": { "hello": "secret" } }): assert successful_task() == 1 assert rmock.called is False
def test_cronitor_doesnt_crash_if_request_fails(notify_api, rmock): rmock.get(RUN_LINK, exc=requests.exceptions.ConnectTimeout) rmock.get(COMPLETE_LINK, status_code=500) with set_config_values(notify_api, { 'CRONITOR_ENABLED': True, 'CRONITOR_KEYS': {'hello': 'secret'} }): assert successful_task() == 1 assert rmock.call_count == 2
def test_should_set_cors_headers(self, client, github_login_toggle_enabled, mocker, notify_api, cookie_config): mocker.patch('app.oauth.rest.verify_jwt_in_request', side_effect=None) with set_config_values( notify_api, {'UI_HOST_NAME': cookie_config['UI_HOST_NAME']}): response = client.get('/redeem-token') assert response.access_control_allow_credentials assert response.access_control_allow_origin == cookie_config[ 'UI_HOST_NAME']
def test_cronitor_does_nothing_if_name_not_recognised(notify_api, rmock, caplog): with set_config_values(notify_api, { 'CRONITOR_ENABLED': True, 'CRONITOR_KEYS': {'not-hello': 'other'} }): assert successful_task() == 1 if caplog.records: error_log = caplog.records[0] assert error_log.levelname == 'ERROR' assert error_log.msg == 'Cronitor enabled but task_name hello not found in environment' assert rmock.called is False
def test_create_fake_letter_response_file_calls_dvla_callback_on_development(notify_api, mocker): mocker.patch("app.celery.research_mode_tasks.file_exists", return_value=False) mocker.patch("app.celery.research_mode_tasks.s3upload") mock_task = mocker.patch("app.celery.research_mode_tasks.process_sns_results") with set_config_values(notify_api, {"NOTIFY_ENVIRONMENT": "development"}): some_ref = str(uuid.uuid4()) create_fake_letter_response_file(some_ref) mock_task.apply_async.assert_called_once_with(ANY, queue=QueueNames.RESEARCH_MODE) message = json.loads(mock_task.apply_async.call_args[0][0][0]) assert message["MessageId"] == some_ref
def test_cronitor_sends_run_and_complete(notify_api, rmock): rmock.get(RUN_LINK, status_code=200) rmock.get(COMPLETE_LINK, status_code=200) with set_config_values(notify_api, { 'CRONITOR_ENABLED': True, 'CRONITOR_KEYS': {'hello': 'secret'} }): assert successful_task() == 1 assert rmock.call_count == 2 assert rmock.request_history[0].url == RUN_LINK assert rmock.request_history[1].url == COMPLETE_LINK
def test_cronitor_sends_run_and_fail_if_exception(notify_api, rmock): rmock.get(RUN_LINK, status_code=200) rmock.get(FAIL_LINK, status_code=200) with set_config_values(notify_api, { 'CRONITOR_ENABLED': True, 'CRONITOR_KEYS': {'hello': 'secret'} }): with pytest.raises(ValueError): crashing_task() assert rmock.call_count == 2 assert rmock.request_history[0].url == RUN_LINK assert rmock.request_history[1].url == FAIL_LINK