Skip to content

Commit

Permalink
Add module tests and add new stage in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldat committed Sep 11, 2023
1 parent d1389ca commit bab3687
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/deploy-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
sudo apt install pycodestyle pylint
sudo apt install pycodestyle pylint pytest
pip install -r py-requirements.txt
- name: Analysing the code with pycodestyle
run: |
pycodestyle src/**/*.py
- name: Analysing the code with pylint
run: |
pylint src/**/*.py
- name: Run Module tests
run: |
python3 -m pytest -sr tests/test_c*.py
deploy:
runs-on: ubuntu-latest
needs: test
Expand Down
57 changes: 57 additions & 0 deletions tests/test_clickjacking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import sys
import pytest

sys.path.insert(
0,
'src'
)

from clickjacking.clickjacking import ClickJacking

@pytest.fixture
def clickjacking_false():
return ClickJacking.click_jacking('https://google.com')

@pytest.fixture
def clickjacking_true():
return ClickJacking.click_jacking('https://www.gosuslugi.ru')

@pytest.fixture
def clickjacking_uppercase_url_false():
return ClickJacking.click_jacking('HTTPS://WWW.GOOGLE.COM')

@pytest.fixture
def clickjacking_uppercase_url_true():
return ClickJacking.click_jacking('HTTPS://WWW.GOSUSLUGI.RU')

@pytest.fixture
def clickjacking_without_prefix_false():
return ClickJacking.click_jacking('google.com')

@pytest.fixture
def clickjacking_without_prefix_true():
return ClickJacking.click_jacking('gosuslugi.ru')

def test_clickjacking_false(clickjacking_false):
assert clickjacking_false == False

def test_clickjacking_true(clickjacking_true):
assert clickjacking_true == True

def test_clickjacking_uppercase_url_false(clickjacking_uppercase_url_false):
assert clickjacking_uppercase_url_false == False

def test_clickjacking_uppercase_url_true(clickjacking_uppercase_url_true):
assert clickjacking_uppercase_url_true == True

def test_clickjacking_without_prefix_false(clickjacking_without_prefix_false):
assert clickjacking_without_prefix_false == False

def test_clickjacking_without_prefix_true(clickjacking_without_prefix_true):
assert clickjacking_without_prefix_true == True

def test_not_string_value():
try:
ClickJacking.click_jacking(123)
except BaseException as ex:
assert str(ex) == 'Target must be a string not <class \'int\'>. Got target: 123'
28 changes: 28 additions & 0 deletions tests/test_dns_lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import pytest

sys.path.insert(
0,
'src'
)

from dns_lookup.dns_lookup import DnsLookup

@pytest.fixture
def dns_lookup_record_type_mx():
return DnsLookup.dns_lookup('google.com', 'MX')

def test_dns_lookup_record_type_cname():
try:
DnsLookup.dns_lookup('google.com', 'CNAME')
except BaseException as ex:
assert str(ex) == 'Error occurred: The DNS response does not contain an answer to the question: google.com. IN CNAME'

def test_dns_lookup_record_type_mx(dns_lookup_record_type_mx):
assert dns_lookup_record_type_mx == ['10 smtp.google.com.']

def test_not_string_value():
try:
DnsLookup.dns_lookup(123)
except BaseException as ex:
assert str(ex) == 'Target must be a string not <class \'int\'>. Got target: 123'
21 changes: 21 additions & 0 deletions tests/test_exec_shell_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import sys
import pytest

sys.path.insert(
0,
'src'
)

from exec_shell_command.exec_shell_command import exec_shell_command

@pytest.fixture
def exec_pwd():
return exec_shell_command('pwd').removesuffix('\n')

def test_exec_correct_command(exec_pwd):
assert exec_pwd == os.getcwd()

def test_exec_incorrect_command():
with pytest.raises(ValueError):
exec_shell_command('pweed')
18 changes: 18 additions & 0 deletions tests/test_get_hostname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
import socket
import pytest

sys.path.insert(
0,
'src'
)

from ip.ip import GetHostname

@pytest.fixture
def get_hostname():
return GetHostname.get_hostname_ip()

def test_get_hostname(get_hostname):
hostname, _ = get_hostname
assert hostname == socket.gethostname()
31 changes: 31 additions & 0 deletions tests/test_http_headers_grabber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys
import pytest

sys.path.insert(
0,
'src'
)

from http_headers_grabber.http_headers_grabber import HttpHeadersGrabber

@pytest.fixture
def http_headers_grabber_available():
return HttpHeadersGrabber.http_headers_grabber('https://google.com')

@pytest.fixture
def http_headers_grabber_witout_preffix():
return HttpHeadersGrabber.http_headers_grabber('google.com')

def test_http_headers_grabber_available(http_headers_grabber_available):
assert dict(http_headers_grabber_available)['X-Frame-Options'] == 'SAMEORIGIN'
assert dict(http_headers_grabber_available)['Content-Encoding'] == 'gzip'

def test_http_headers_grabber_witout_preffix(http_headers_grabber_witout_preffix):
assert dict(http_headers_grabber_witout_preffix)['X-Frame-Options'] == 'SAMEORIGIN'
assert dict(http_headers_grabber_witout_preffix)['Content-Encoding'] == 'gzip'

def test_http_headers_grabber_invalid_url_type():
try:
return HttpHeadersGrabber.http_headers_grabber(123)
except BaseException as ex:
assert str(ex) == 'Target must be a string not <class \'int\'>. Got target: 123'

0 comments on commit bab3687

Please sign in to comment.