From 6dcd084658f74cb450549a213e468424618df1d6 Mon Sep 17 00:00:00 2001 From: Felix Zailskas Date: Tue, 6 Feb 2024 09:49:18 +0100 Subject: [PATCH] Added test case for phone numbers Signed-off-by: Felix Zailskas --- tests/steps/test_hash_generator.py | 2 +- tests/steps/test_preprocess_phonenumbers.py | 114 ++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 tests/steps/test_preprocess_phonenumbers.py diff --git a/tests/steps/test_hash_generator.py b/tests/steps/test_hash_generator.py index 01f8a24..f9b7b56 100644 --- a/tests/steps/test_hash_generator.py +++ b/tests/steps/test_hash_generator.py @@ -9,7 +9,7 @@ from bdc.steps.hash_generator import HashGenerator -class YourClassTests(unittest.TestCase): +class TestStepExecution(unittest.TestCase): def setUp(self): self.lead_data = { "First Name": ["John"], diff --git a/tests/steps/test_preprocess_phonenumbers.py b/tests/steps/test_preprocess_phonenumbers.py new file mode 100644 index 0000000..f4f529b --- /dev/null +++ b/tests/steps/test_preprocess_phonenumbers.py @@ -0,0 +1,114 @@ +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: 2024 Felix Zailskas + +import unittest +from unittest.mock import patch + +import pandas as pd + +from bdc.steps.helpers.generate_hash_leads import LeadHashGenerator +from bdc.steps.preprocess_phonenumbers import PreprocessPhonenumbers +from tests import mock_hash_check + + +class TestStepExecution(unittest.TestCase): + def setUp(self): + self.lead_data = { + "First Name": ["John"] * 7, + "Last Name": ["Doe"] * 7, + "Phone": [ + "4930183992170", + "invalid_phone", + "442087599036", + "3197010281402", + "436601359011", + "33757056600", + "495111233421", + ], + } + self.step = PreprocessPhonenumbers(force_refresh=True) + self.step.df = pd.DataFrame(self.lead_data) + self.formatted_gt = [ + "+49 30 183992170", + "", + "+44 20 8759 9036", + "+31 970 102 81402", + "+43 660 1359011", + "+33 7 57 05 66 00", + "+49 511 1233421", + ] + self.country_gt = [ + "Germany", + "", + "United Kingdom", + "Netherlands", + "Austria", + "France", + "Germany", + ] + self.area_gt = [ + "Berlin", + "", + "London", + "", + "", + "", + "Hannover", + ] + self.valid_gt = [ + True, + False, + True, + True, + True, + True, + True, + ] + self.possible_gt = [ + True, + False, + True, + True, + True, + True, + True, + ] + + @patch.object(LeadHashGenerator, "hash_check", mock_hash_check) + def test_hash_lead(self): + result = self.step.run() + + assert type(result) is pd.DataFrame + columns = result.columns.to_list() + assert all( + col in columns + for col in [ + "First Name", + "Last Name", + "Phone", + "number_formatted", + "number_country", + "number_area", + "number_valid", + "number_possible", + ] + ) + # test formatted number + for test, gt in zip(result["number_formatted"].to_list(), self.formatted_gt): + self.assertEqual(test, gt) + # test country + for test, gt in zip(result["number_country"].to_list(), self.country_gt): + self.assertEqual(test, gt) + # test area + for test, gt in zip(result["number_area"].to_list(), self.area_gt): + self.assertEqual(test, gt) + # test valid + for test, gt in zip(result["number_valid"].to_list(), self.valid_gt): + self.assertEqual(test, gt) + # test possible + for test, gt in zip(result["number_possible"].to_list(), self.possible_gt): + self.assertEqual(test, gt) + + +if __name__ == "__main__": + unittest.main()