Skip to content

Commit

Permalink
Added test for empty email and spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
idomic committed Apr 27, 2022
1 parent 79264de commit f1c68dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/ploomber/cli/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,24 @@ def _email_input():
settings = UserSettings()
if not settings.user_email:
email = _get_input(
"Our users enjoy updates, support and unique content "
"\nOur users enjoy updates, support and unique content "
"through email, please add your email, if you'd like "
"to register (type email): ")
"to register (type email): \n")
_email_validation(email)


def _email_validation(email):
pattern = r"[^@]+@[^@]+\.[^@]+"
settings = UserSettings()
if re.match(pattern, email):
# Save in conf file
settings = UserSettings()
settings.user_email = email

# Call API
_email_registry(email)
else:
# Save in conf file
settings.user_email = 'empty_email'


def _email_registry(email):
Expand Down
2 changes: 1 addition & 1 deletion src/ploomber/cli/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def list(self):
tw.write('\nTo run these examples in free, hosted '
f'environment, see instructions at: {_URL}')
tw.write('\nTo download: ploomber examples -n name -o path\n')
tw.write('Example: ploomber examples -n templates/ml-basic -o ml\n')
tw.write('Example: ploomber examples -n templates/ml-basic -o ml\n\n')


@command_endpoint
Expand Down
5 changes: 3 additions & 2 deletions tests/cli/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,10 @@ def test_email_call_on_examples(tmp_directory, monkeypatch):
email_mock.assert_called_once()


def test_email_called_once(tmp_directory, monkeypatch):
@pytest.mark.parametrize('user_email', ['email@ploomber.io', ''])
def test_email_called_once(tmp_directory, monkeypatch, user_email):
monkeypatch.setattr(telemetry, 'DEFAULT_HOME_DIR', '.')
email_mock = Mock(return_value='email@ploomber.io')
email_mock = Mock(return_value=user_email)
api_mock = Mock()
monkeypatch.setattr(cloud, '_get_input', email_mock)
monkeypatch.setattr(cloud, '_email_registry', api_mock)
Expand Down

0 comments on commit f1c68dd

Please sign in to comment.