From 3656c40fae0d941cb038f7c1e295938837525374 Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Sat, 6 May 2023 01:12:16 -0300 Subject: [PATCH 1/9] test: add test with None values on invitation --- inb/tests/test_invitation_status.py | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/inb/tests/test_invitation_status.py b/inb/tests/test_invitation_status.py index 8d1bdbee..44435e19 100644 --- a/inb/tests/test_invitation_status.py +++ b/inb/tests/test_invitation_status.py @@ -43,6 +43,22 @@ def test_person_properties(person): assert person.profileid == 'john-smith' assert person.profileurl == 'https://www.linkedin.com/in/john-smith' +@pytest.fixture() +def person_with_missing_fields(): + return status.Person(name='John Smith', + occupation=None, # This can happen when a user doesn't have occupation on the profile + location='San Francisco, CA', + profileid='john-smith', + profileurl='https://www.linkedin.com/in/john-smith') + +def test_person_properties_with_missing_fields(person_with_missing_fields): + assert person_with_missing_fields.name == 'John Smith' + assert person_with_missing_fields.occupation == None + assert person_with_missing_fields.location == 'San Francisco, CA' + assert person_with_missing_fields.profileid == 'john-smith' + assert person_with_missing_fields.profileurl == 'https://www.linkedin.com/in/john-smith' + +# def test_ def test_invitation_set_invitation_fields_success(invitation): invitation.set_invitation_fields( @@ -112,6 +128,32 @@ def test_invitation_send_status_to_console(invitation): mock.call('', sys.stdout, True, True) ]) +def test_invitation_send_status_to_console_with_empty_values(invitation): + status._SUCCESS_RATE = 0 + status._FAILURE_RATE = 0 + + invitation.set_invitation_fields( + name='John Smith', + occupation=None, # This can happen when a user doesn't have occupation on the profile + location=None, # This can happen when a user doesn't have location on the profile + profileid='john-smith', + profileurl='https://www.linkedin.com/in/john-smith', + status='sent', + elapsed_time=10.0) + + expected_output = (' ✔ John Smith\n' + ' \n' + ' \n' + ' Success: 1 Failure: 0 Elapsed time: 10.0s\n') + + with mock.patch('click.echo') as mk_click_echo: + invitation._send_status_to_console() + mk_click_echo.assert_has_calls([ + mock.call('', sys.stdout, True, True), + mock.call(expected_output, sys.stdout, True, True), + mock.call('', sys.stdout, True, True) + ]) + @pytest.fixture def mock_sleep(): From 369148ff265880acfff668a1daf38ede8c2d1ad9 Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Sat, 6 May 2023 01:12:43 -0300 Subject: [PATCH 2/9] feat: print empty line when the value is None --- inb/api/invitation/status.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/inb/api/invitation/status.py b/inb/api/invitation/status.py index 14de18d8..41ee1393 100644 --- a/inb/api/invitation/status.py +++ b/inb/api/invitation/status.py @@ -117,8 +117,14 @@ def _replace_template_var_with_template_value( the template variables. """ for replace_template_var_with_value_pair in replace_template_var_with: - message_template = message_template.replace( - *replace_template_var_with_value_pair) + # fallback to when of the tuple items be None + if replace_template_var_with_value_pair[1] is not None: + message_template = message_template.replace( + *replace_template_var_with_value_pair) + else: + # fill with an empty line + message_template = message_template.replace( + replace_template_var_with_value_pair[0], '') return message_template def _fill_search_message_template(self) -> str: From 6fe1309362f827c6b5b0e09a9c2b88c91d977214 Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Sat, 6 May 2023 01:15:06 -0300 Subject: [PATCH 3/9] style: handle pylint issue --- inb/tests/test_invitation_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inb/tests/test_invitation_status.py b/inb/tests/test_invitation_status.py index 44435e19..71ebbe3d 100644 --- a/inb/tests/test_invitation_status.py +++ b/inb/tests/test_invitation_status.py @@ -53,7 +53,7 @@ def person_with_missing_fields(): def test_person_properties_with_missing_fields(person_with_missing_fields): assert person_with_missing_fields.name == 'John Smith' - assert person_with_missing_fields.occupation == None + assert person_with_missing_fields.occupation is None assert person_with_missing_fields.location == 'San Francisco, CA' assert person_with_missing_fields.profileid == 'john-smith' assert person_with_missing_fields.profileurl == 'https://www.linkedin.com/in/john-smith' From 1a04054f0595a087f327a3044cf1dffb62ddc1b1 Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Sat, 6 May 2023 01:18:24 -0300 Subject: [PATCH 4/9] style: handle pylint issues --- inb/tests/test_invitation_status.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/inb/tests/test_invitation_status.py b/inb/tests/test_invitation_status.py index 71ebbe3d..e37e2eb1 100644 --- a/inb/tests/test_invitation_status.py +++ b/inb/tests/test_invitation_status.py @@ -46,7 +46,7 @@ def test_person_properties(person): @pytest.fixture() def person_with_missing_fields(): return status.Person(name='John Smith', - occupation=None, # This can happen when a user doesn't have occupation on the profile + occupation=None, location='San Francisco, CA', profileid='john-smith', profileurl='https://www.linkedin.com/in/john-smith') @@ -56,7 +56,6 @@ def test_person_properties_with_missing_fields(person_with_missing_fields): assert person_with_missing_fields.occupation is None assert person_with_missing_fields.location == 'San Francisco, CA' assert person_with_missing_fields.profileid == 'john-smith' - assert person_with_missing_fields.profileurl == 'https://www.linkedin.com/in/john-smith' # def test_ @@ -134,18 +133,18 @@ def test_invitation_send_status_to_console_with_empty_values(invitation): invitation.set_invitation_fields( name='John Smith', - occupation=None, # This can happen when a user doesn't have occupation on the profile - location=None, # This can happen when a user doesn't have location on the profile + occupation=None, + location=None, profileid='john-smith', profileurl='https://www.linkedin.com/in/john-smith', status='sent', elapsed_time=10.0) - + expected_output = (' ✔ John Smith\n' ' \n' ' \n' ' Success: 1 Failure: 0 Elapsed time: 10.0s\n') - + with mock.patch('click.echo') as mk_click_echo: invitation._send_status_to_console() mk_click_echo.assert_has_calls([ From 2e09807139603275cbea6ca8c12a8fb6f7ca2a37 Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Sat, 6 May 2023 01:18:46 -0300 Subject: [PATCH 5/9] test: remove unnecessary test --- inb/tests/test_invitation_status.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/inb/tests/test_invitation_status.py b/inb/tests/test_invitation_status.py index e37e2eb1..b1f9ca6a 100644 --- a/inb/tests/test_invitation_status.py +++ b/inb/tests/test_invitation_status.py @@ -43,22 +43,6 @@ def test_person_properties(person): assert person.profileid == 'john-smith' assert person.profileurl == 'https://www.linkedin.com/in/john-smith' -@pytest.fixture() -def person_with_missing_fields(): - return status.Person(name='John Smith', - occupation=None, - location='San Francisco, CA', - profileid='john-smith', - profileurl='https://www.linkedin.com/in/john-smith') - -def test_person_properties_with_missing_fields(person_with_missing_fields): - assert person_with_missing_fields.name == 'John Smith' - assert person_with_missing_fields.occupation is None - assert person_with_missing_fields.location == 'San Francisco, CA' - assert person_with_missing_fields.profileid == 'john-smith' - -# def test_ - def test_invitation_set_invitation_fields_success(invitation): invitation.set_invitation_fields( name='John Smith', From 2c216c99945436cef201628b7cc3fece79325d3c Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Sat, 6 May 2023 01:21:05 -0300 Subject: [PATCH 6/9] style: keep implementation on the standard --- inb/tests/test_invitation_status.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inb/tests/test_invitation_status.py b/inb/tests/test_invitation_status.py index b1f9ca6a..784d2277 100644 --- a/inb/tests/test_invitation_status.py +++ b/inb/tests/test_invitation_status.py @@ -43,6 +43,7 @@ def test_person_properties(person): assert person.profileid == 'john-smith' assert person.profileurl == 'https://www.linkedin.com/in/john-smith' + def test_invitation_set_invitation_fields_success(invitation): invitation.set_invitation_fields( name='John Smith', @@ -111,6 +112,7 @@ def test_invitation_send_status_to_console(invitation): mock.call('', sys.stdout, True, True) ]) + def test_invitation_send_status_to_console_with_empty_values(invitation): status._SUCCESS_RATE = 0 status._FAILURE_RATE = 0 From a092c10b9b6486e893088baff81c54e4632cd32a Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Sat, 6 May 2023 02:28:44 -0300 Subject: [PATCH 7/9] docs: improve comments --- inb/api/invitation/status.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inb/api/invitation/status.py b/inb/api/invitation/status.py index 41ee1393..1ac5cc16 100644 --- a/inb/api/invitation/status.py +++ b/inb/api/invitation/status.py @@ -117,12 +117,13 @@ def _replace_template_var_with_template_value( the template variables. """ for replace_template_var_with_value_pair in replace_template_var_with: - # fallback to when of the tuple items be None + # if the value to be replaced is not None if replace_template_var_with_value_pair[1] is not None: + # then, replace the template variable with the value message_template = message_template.replace( *replace_template_var_with_value_pair) else: - # fill with an empty line + # provide an empty string as the valid value message_template = message_template.replace( replace_template_var_with_value_pair[0], '') return message_template From bc48288be8b0cb0c3f0d9278ff7b03d10c1d2a09 Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Mon, 8 May 2023 17:12:46 -0300 Subject: [PATCH 8/9] feat: use NaN to replace empty value --- inb/api/invitation/status.py | 14 ++++++-------- inb/tests/test_invitation_status.py | 6 +++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/inb/api/invitation/status.py b/inb/api/invitation/status.py index 1ac5cc16..cfe4cb14 100644 --- a/inb/api/invitation/status.py +++ b/inb/api/invitation/status.py @@ -117,15 +117,13 @@ def _replace_template_var_with_template_value( the template variables. """ for replace_template_var_with_value_pair in replace_template_var_with: - # if the value to be replaced is not None - if replace_template_var_with_value_pair[1] is not None: - # then, replace the template variable with the value - message_template = message_template.replace( - *replace_template_var_with_value_pair) + template_var = replace_template_var_with_value_pair[0] + template_value = replace_template_var_with_value_pair[1] + + if template_value is not None: + message_template = message_template.replace(template_var, template_value) else: - # provide an empty string as the valid value - message_template = message_template.replace( - replace_template_var_with_value_pair[0], '') + message_template = message_template.replace(template_var, 'NaN') return message_template def _fill_search_message_template(self) -> str: diff --git a/inb/tests/test_invitation_status.py b/inb/tests/test_invitation_status.py index 784d2277..ff4f94f6 100644 --- a/inb/tests/test_invitation_status.py +++ b/inb/tests/test_invitation_status.py @@ -127,9 +127,9 @@ def test_invitation_send_status_to_console_with_empty_values(invitation): elapsed_time=10.0) expected_output = (' ✔ John Smith\n' - ' \n' - ' \n' - ' Success: 1 Failure: 0 Elapsed time: 10.0s\n') + ' NaN\n' + ' NaN\n' + ' Success: 1 Failure: 0 Elapsed time: 10.0s\n') with mock.patch('click.echo') as mk_click_echo: invitation._send_status_to_console() From 69ee9d482024f6bb6de6311b7c76d8c0d845172e Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Mon, 8 May 2023 17:14:01 -0300 Subject: [PATCH 9/9] style: fix pylint issue --- inb/api/invitation/status.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inb/api/invitation/status.py b/inb/api/invitation/status.py index cfe4cb14..3c55c43f 100644 --- a/inb/api/invitation/status.py +++ b/inb/api/invitation/status.py @@ -121,7 +121,8 @@ def _replace_template_var_with_template_value( template_value = replace_template_var_with_value_pair[1] if template_value is not None: - message_template = message_template.replace(template_var, template_value) + message_template = message_template.replace( + template_var, template_value) else: message_template = message_template.replace(template_var, 'NaN') return message_template