Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 8eb4259

Browse files
author
Antônio Moreira
committed
Test email error handling in safe_process
Change-Id: I9bda9e62c66ebcfcf411e17882f1348e9790431c
1 parent 83fcde9 commit 8eb4259

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

megalista_dataflow/error/error_handling_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_single_error_per_execution():
5353
error_handler.add_error(second_execution, 'Error for second execution, fist input')
5454

5555
returned_errors = error_handler.errors
56-
assert len(returned_errors) is 2
56+
assert len(returned_errors) == 2
5757
assert returned_errors.keys() == {first_execution, second_execution}
5858

5959

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)