|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import logging |
| 15 | + |
| 16 | +from error.error_handling import ErrorHandler |
| 17 | +from error.error_handling_test import MockErrorNotifier |
| 18 | +from models.execution import Batch, DestinationType, Destination, Source, SourceType, Execution, AccountConfig |
| 19 | +from uploaders import utils |
| 20 | +from uploaders.uploaders import MegalistaUploader |
| 21 | + |
| 22 | +error_message = 'Test error message' |
| 23 | + |
| 24 | + |
| 25 | +class MockUploader(MegalistaUploader): |
| 26 | + def __init__(self, error_handler: ErrorHandler): |
| 27 | + super().__init__(error_handler) |
| 28 | + |
| 29 | + @utils.safe_process(logger=logging.getLogger('megalista.UtilsTest')) |
| 30 | + def process(self, batch: Batch, **kwargs): |
| 31 | + self._add_error(batch.execution, error_message) |
| 32 | + |
| 33 | + |
| 34 | +def test_email_sending_on_safe_process(): |
| 35 | + notifier = MockErrorNotifier() |
| 36 | + uploader = MockUploader(ErrorHandler(DestinationType.ADS_OFFLINE_CONVERSION, notifier)) |
| 37 | + |
| 38 | + destination = Destination( |
| 39 | + 'dest1', DestinationType.ADS_OFFLINE_CONVERSION, ['user_list']) |
| 40 | + source = Source('orig1', SourceType.BIG_QUERY, ['dt1', 'buyers']) |
| 41 | + execution = Execution(AccountConfig('123-45567-890', False, 'ga_account_id', '', ''), source, destination) |
| 42 | + uploader.process(Batch(execution, [{}])) |
| 43 | + uploader.finish_bundle() |
| 44 | + |
| 45 | + assert notifier.were_errors_sent |
| 46 | + assert notifier.errors_sent == {execution: error_message} |
0 commit comments