generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Felix Zailskas <[email protected]>
- Loading branch information
1 parent
64a23ba
commit 108a57b
Showing
2 changed files
with
53 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# SPDX-License-Identifier: MIT | ||
# SPDX-FileCopyrightText: 2024 Felix Zailskas <[email protected]> | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": [ | ||
# "[email protected]", | ||
# "invalid_email", | ||
# "[email protected]", | ||
# ] | ||
# } | ||
# 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": [ | ||
"[email protected]", | ||
"invalid_email", | ||
"[email protected]", | ||
], | ||
} | ||
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() |