Skip to content

Commit

Permalink
Implement Unit Tests
Browse files Browse the repository at this point in the history
- Adds tests folder under 'modules'.
- Creates test files for modules.
- Implements checker passing test cases.

See Issue: MikeMeliz#16
  • Loading branch information
the-siegfried committed Jul 3, 2022
1 parent 3571797 commit d3d4a64
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Empty file added modules/tests/__init__.py
Empty file.
69 changes: 69 additions & 0 deletions modules/tests/test_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os.path
import unittest

from ..checker import extract_domain
from ..checker import folder
from ..checker import url_canon


class TestCheckFunctions(unittest.TestCase):
@classmethod
def setUp(cls) -> None:
pass

@classmethod
def tearDownClass(cls):
""" Test Suite Teardown. """
# Remove test folder.
os.rmdir('torcrawl')

def test_url_canon_001(self):
""" url_canon unit test.
Returns true if the function successfully performs URL normalisation.
"""
url = 'torcrawl.com'
expected = 'http://www.torcrawl.com'
result = url_canon(url, False)
self.assertEqual(expected, result,
f'Test Fail:: expected = {expected}, got {result}')

def test_url_canon_002(self):
""" url_canon unit test.
Returns true if the function successfully performs URL normalisation.
"""
url = 'www.torcrawl.com'
expected = 'http://www.torcrawl.com'
result = url_canon(url, False)
self.assertEqual(expected, result,
f'Test Fail:: expected = {expected}, got {result}')

def test_extract_domain_001(self):
""" extract_domain test.
Returns true if correct domain is returned.
"""
url = 'http://www.torcrawl.com/test/domain-extract/api?id=001'
expected = 'www.torcrawl.com'
result = extract_domain(url, True)
self.assertEqual(expected, result,
f'Test Fail:: expected = {expected}, got {result}')

def test_extract_domain_002(self):
""" extract_domain test.
Returns true if correct domain is returned.
"""
url = 'http://www.torcrawl.com/test/domain-extract/api?id=002'
expected = 'http://www.torcrawl.com'
result = extract_domain(url, False)
self.assertEqual(expected, result,
f'Test Fail:: expected = {expected}, got {result}')

def test_folder_creation(self):
""" folder creation test.
Returns true if folder is successfully created.
"""
_input = 'torcrawl'
result = folder(_input, False)
self.assertTrue(os.path.exists(result),
f'Test Fail:: could not find folder {_input}')


Empty file added modules/tests/test_crawler.py
Empty file.
Empty file added modules/tests/test_extractor.py
Empty file.

0 comments on commit d3d4a64

Please sign in to comment.