Skip to content

Commit

Permalink
Added simple execution test
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Zailskas <[email protected]>
  • Loading branch information
felix-zailskas committed Feb 5, 2024
1 parent 64a23ba commit 108a57b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 48 deletions.
16 changes: 16 additions & 0 deletions tests/__init__.py
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)
85 changes: 37 additions & 48 deletions tests/steps/test_analyze_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 108a57b

Please sign in to comment.