Skip to content

Email generator fix and tests #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scripts/convert/email_generator/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def run(self, *args, **kwargs) -> ScriptResponse.success or ScriptResponse.error
tm = time()
email_gen = EmailGenerator()
username = kwargs.get("username")
if username is None:
if not username:
raise KeyError("EmailGenerator can't work without username!")
result = email_gen.generate(username)
except Exception as err:
Expand Down
37 changes: 37 additions & 0 deletions src/scripts/convert/email_generator/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
from .module import Runner
from unittest import TestCase


class TestEmailGenerator(TestCase):
def setUp(self) -> None:
"""
Setup Runner before each test function
:return: None
"""
self.runner = Runner()

def test_create_runner(self):
"""
Test creation of the class instance
:return: None
"""
self.assertIsNotNone(self.runner)
self.assertIsInstance(self.runner, Runner)

def test_fail_false_argument(self):
"""
Test failing on false arguments
:return: False
"""
result = self.runner.run(username="")
self.assertEqual(result.get("status"), "error")

def test_pass_true_argument(self):
"""
Test passing on true arguments
:return: True
"""
result = self.runner.run(username="john.doe")
self.assertEqual(result.get("status"), "success")
self.assertIsNotNone(result.get("result"))