From 108a57b7009b5918a154980df724e9cf77597ad5 Mon Sep 17 00:00:00 2001 From: Felix Zailskas Date: Mon, 5 Feb 2024 19:16:41 +0100 Subject: [PATCH] Added simple execution test Signed-off-by: Felix Zailskas --- tests/__init__.py | 16 ++++++ tests/steps/test_analyze_emails.py | 85 +++++++++++++----------------- 2 files changed, 53 insertions(+), 48 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..c93c73d --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: 2024 Felix Zailskas + +import pandas as pd + + +def mock_hash_check( + self, + lead_data: pd.Series, + data_fill_function: callable, + step_name: str, + fields_tofill: list[str], + *args, + **kwargs, +): + return data_fill_function(*args, **kwargs) diff --git a/tests/steps/test_analyze_emails.py b/tests/steps/test_analyze_emails.py index 7136c73..2718bdc 100644 --- a/tests/steps/test_analyze_emails.py +++ b/tests/steps/test_analyze_emails.py @@ -6,31 +6,13 @@ import pandas as pd -import bdc.steps.helpers.generate_hash_leads from bdc.steps.analyze_emails import ( AnalyzeEmails, analyze_email_account, extract_custom_domain, ) - - -def get_mock_lead_hash_generator(): - class MockLeadHashGenerator: - def hash_lead(self, lead_data): - return "" - - def hash_check( - self, - lead_data: pd.Series, - data_fill_function: callable, - step_name: str, - fields_tofill: list[str], - *args, - **kwargs, - ): - return data_fill_function(*args, **kwargs) - - return MockLeadHashGenerator() +from bdc.steps.helpers.generate_hash_leads import LeadHashGenerator +from tests import mock_hash_check class TestExtractCustomDomain(unittest.TestCase): @@ -101,34 +83,41 @@ def test_missing_names(self): self.assertTrue(result.equals(expected)) -# class TestStepExecution(unittest.TestCase): -# step: AnalyzeEmails - -# def setUp(self): -# lead_data = { -# "First Name": ["John"] * 3, -# "Last Name": ["Doe"] * 3, -# "Email": [ -# "john.doe@john.com", -# "invalid_email", -# "john@yahoo.com", -# ] -# } -# self.step = AnalyzeEmails(force_refresh=True) -# self.step.df = pd.DataFrame(lead_data) - -# @patch("bdc.steps.helpers.get_lead_hash_generator") -# def test_run_method(self, mock_get_lead_hash_generator): - -# # Mock the hash_check method -# mock_get_lead_hash_generator.return_value = get_mock_lead_hash_generator() - -# # Call the run method -# result = self.step.run() -# assert type(result) is pd.DataFrame -# assert ["First Name", "Last Name", "Email", "domain", "email_valid", "first_name_in_account", -# "last_name_in_account",] in result.columns.to_list() -# assert result["domain"].to_list() == ["john.com", None, None] +class TestStepExecution(unittest.TestCase): + step: AnalyzeEmails + + def setUp(self): + lead_data = { + "First Name": ["John"] * 3, + "Last Name": ["Doe"] * 3, + "Email": [ + "john.doe@john.com", + "invalid_email", + "john@yahoo.com", + ], + } + self.step = AnalyzeEmails(force_refresh=True) + self.step.df = pd.DataFrame(lead_data) + + @patch.object(LeadHashGenerator, "hash_check", mock_hash_check) + def test_run_method(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", + "Email", + "domain", + "email_valid", + "first_name_in_account", + "last_name_in_account", + ] + ) + assert result["domain"].to_list() == ["john.com", None, None] + if __name__ == "__main__": unittest.main()