Skip to content

Commit

Permalink
Merge pull request sundowndev#175 from sundowndev/test/banner
Browse files Browse the repository at this point in the history
test(lib): banner & format
  • Loading branch information
sundowndev authored Dec 20, 2019
2 parents 6c10947 + 9e20cc0 commit 9068ab3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python -m black --config black.config.toml lib scanners tests --check
- name: Test
run: |
python -m green tests/**/*.py --run-coverage
python -m green tests/**/*.py --run-coverage -vvv
- name: Generate examples
run: |
bash ./examples/generate.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/
.vscode/
config.py
geckodriver.log
.coverage
Empty file added tests/__init__.py
Empty file.
11 changes: 9 additions & 2 deletions tests/lib/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
# @author : Raphael Cerveaux (sundowndev)

import unittest
from unittest.mock import patch

from lib.banner import banner, __version__


class TestAnswer(unittest.TestCase):
def test_type(self):
class TestBanner(unittest.TestCase):
def test_version(self):
self.assertIs(type(__version__), type("str"))

@patch("builtins.print")
def test_banner(self, printMock):
banner()

self.assertEqual(printMock.call_count, 9)
54 changes: 54 additions & 0 deletions tests/lib/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
#
# @name : PhoneInfoga - Phone numbers OSINT tool
# @url : https://github.com/sundowndev
# @author : Raphael Cerveaux (sundowndev)

import unittest
from unittest.mock import patch

from lib.format import formatNumber, replaceVariables


class TestFormat(unittest.TestCase):
"""
We want to be sure re.sub is imported and called
"""

@patch("re.sub")
def test_formatNumberCallingSub(self, subMock):
subMock.return_value = ""

result = formatNumber("000")

subMock.assert_called_with("(?:\+)?(?:[^[0-9]*)", "", "000")
self.assertEqual(result, "")

"""
We verify the function formats the number the right way
"""

def test_formatNumber(self):
self.assertEqual(formatNumber("+33 81495357"), "3381495357")
self.assertEqual(formatNumber("0 81 49 53 57"), "081495357")
self.assertEqual(formatNumber("+1 555-444-888"), "1555444888")

def test_replaceVariables(self):
number = {
"input": "+33651580074",
"default": "33651580074",
"local": "651580074",
"international": "+33 6 51 58 00 74",
"country": "France",
"countryCode": "+33",
"countryIsoCode": "FR",
"location": "France",
"carrier": "",
}

self.assertEqual(replaceVariables("test $n", number), "test 33651580074")
self.assertEqual(
replaceVariables("test $i", number), "test +33 6 51 58 00 74"
)
self.assertEqual(replaceVariables("test $l", number), "test 6 51 58 00 74")

0 comments on commit 9068ab3

Please sign in to comment.