Skip to content

Commit

Permalink
Create unitests for creating_full_email function.
Browse files Browse the repository at this point in the history
The minimum email length is checked. Local part minimum 2 characters + "@ mailinator.com" (15 characters) = 17 characters.
Check for maximum length (254 characters).
Check if there is a domain name.
Check whether there is a "com."
Check for the number of characters "@".
Check if there is a ". @".
Check if the first character is a letter. extsoft#47
In code_assesment.sh was added py.test for runing unitests.
In README.md was added information about py.test.
  • Loading branch information
GoshkaEgoshka committed Apr 5, 2019
1 parent ee3463e commit d2d23fd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ We use some tools to guarantee the quality of the code.
3. [flake8](http://flake8.pycqa.org/en/latest/) applies some style checks on the code.
4. [pydocstyle](http://www.pydocstyle.org/en/stable/) analyses the quality of docstrings
(executed via `flake8`).
5. [Mypy](https://mypy.readthedocs.io/en/latest/) checks static types.
5. [Mypy](https://mypy.readthedocs.io/en/latest/) checks static types.
6. [py.test](https://docs.pytest.org) runs unittests.

In order to run code assessment, you need to run `./code-assessment.sh` command and make sure
that there is no message like **_Code assessment is failed! Please fix errors!!!_**. If you face
Expand Down
2 changes: 1 addition & 1 deletion code-assessment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ black --check . || add_fail black
pylint oct suite.py || add_fail pylint
flake8 oct suite.py || add_fail flake8
mypy oct suite.py || add_fail mypy

py.test -v tests || add_fail py.test
if [[ ${#FAILURES[@]} -ne 0 ]]; then
cat <<RESULT
Expand Down
Empty file added tests/__init__.py
Empty file.
55 changes: 55 additions & 0 deletions tests/test_emailsGeneration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest
import re
from oct.tests.web.creating_emails import EmailsGeneration


class TestEmailsGeneration:
@pytest.fixture(scope="function", autouse=True)
def setup(self) -> None:
self.email = EmailsGeneration().creating_full_email()

def test_length_more_then_17(self) -> None:
assert len(self.email) > 17

def test_length_less_then_254(self) -> None:
assert len(self.email) < 254

def test_find_domain_name(self) -> None:
assert "@mailinator.com" in self.email

def test_absence_dot_dog(self) -> None:
assert ".@" not in self.email

def test_one_at_character(self) -> None:
dog_counter = 0
for iterator in self.email:
if iterator == "@":
dog_counter += 1
assert dog_counter == 1

def test_absence_com_dot(self) -> None:
assert "com." not in self.email

def test_first_symbol_isalpha(self) -> None:
assert self.email[0].isalpha()

def test_creating_emails_is_string(self) -> None:
assert isinstance(EmailsGeneration().creating_full_email(), str)

def test_emails_pattern(self) -> None:
random_email = EmailsGeneration().creating_full_email()
assert random_email == ((re.findall(r"\w{1,7}@\w+.\w+", random_email)).pop(0))

def test_email_contains_dog(self) -> None:
assert (EmailsGeneration().creating_full_email().count("@")) == 1

def test_length_first_part_of_email(self) -> None:
assert len((EmailsGeneration().creating_full_email().split("@")).pop(0)) == 7

def test_second_part_of_email(self) -> None:
assert len((EmailsGeneration().creating_full_email().split(".")).pop(1)) <= 4

def test_special_symbols_are_absent(self) -> None:
special_symbols = list(str("!$#%^&*()+=?/," "№;:?*[]{}|"))
for each_symbol in special_symbols:
assert each_symbol is not EmailsGeneration().creating_full_email()

0 comments on commit d2d23fd

Please sign in to comment.