Commit 15e0532a authored by Romain Courteaud's avatar Romain Courteaud

Organize code in subdirectory

parent 345d33ee
...@@ -6,14 +6,15 @@ ...@@ -6,14 +6,15 @@
python3 -m venv venv python3 -m venv venv
. venv/bin/activate . venv/bin/activate
pip install --upgrade --editable ".[dev]" pip install --upgrade --editable ".[dev]"
py.test
urlchecker -u URL urlchecker -u URL
``` ```
## Check the code ## Check the code
``` ```
pyflakes *py pyflakes src/surykatka/*py tests/*py
black -t py37 -l 79 *py black -t py37 -l 79 src/surykatka/*py tests/*py
``` ```
## SNI Support ## SNI Support
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
from setuptools import setup from setuptools import setup, find_packages
setup( setup(
name="surykatka", name="surykatka",
...@@ -27,17 +27,8 @@ setup( ...@@ -27,17 +27,8 @@ setup(
author="Nexedi", author="Nexedi",
author_email="romain@nexedi.com", author_email="romain@nexedi.com",
long_description=__doc__, long_description=__doc__,
py_modules=[ packages=find_packages("src"),
"surykatka_bot", package_dir={"": "src"},
"surykatka_cli",
"surykatka_configuration",
"surykatka_dns",
"surykatka_http",
"surykatka_network",
"surykatka_platform",
"surykatka_status",
"surykatka_db",
],
include_package_data=False, include_package_data=False,
zip_safe=True, zip_safe=True,
install_requires=[ install_requires=[
...@@ -53,6 +44,6 @@ setup( ...@@ -53,6 +44,6 @@ setup(
"dev": ["pytest", "black", "pyflakes", "mock", "httpretty"] "dev": ["pytest", "black", "pyflakes", "mock", "httpretty"]
}, },
entry_points={ entry_points={
"console_scripts": ["surykatka=surykatka_cli:runSurykatka "] "console_scripts": ["surykatka=surykatka.cli:runSurykatka "]
}, },
) )
...@@ -18,22 +18,17 @@ ...@@ -18,22 +18,17 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import time import time
from surykatka_db import LogDB from .db import LogDB
from surykatka_configuration import createConfiguration, logConfiguration from .configuration import createConfiguration, logConfiguration
from surykatka_status import logStatus, reportStatus from .status import logStatus, reportStatus
from surykatka_dns import ( from .dns import (
getReachableResolverList, getReachableResolverList,
expandDomainList, expandDomainList,
getDomainIpDict, getDomainIpDict,
reportDnsQuery, reportDnsQuery,
) )
from surykatka_http import ( from .http import getRootUrl, getUrlHostname, checkHttpStatus, reportHttp
getRootUrl, from .network import isTcpPortOpen, reportNetwork
getUrlHostname,
checkHttpStatus,
reportHttp,
)
from surykatka_network import isTcpPortOpen, reportNetwork
import json import json
import email.utils import email.utils
from collections import OrderedDict from collections import OrderedDict
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
import click import click
import sys import sys
from surykatka_bot import create_bot from .bot import create_bot
@click.command(short_help="Runs surykatka bot.") @click.command(short_help="Runs surykatka bot.")
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import dns import dns
from surykatka_network import logNetwork from .network import logNetwork
from peewee import fn from peewee import fn
URL_TO_CHECK = "example.org" URL_TO_CHECK = "example.org"
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import unittest import unittest
from surykatka_bot import WebBot from surykatka.bot import WebBot
import mock import mock
from test_surykatka_dns import MockAnswer from test_dns import MockAnswer
import surykatka_dns import surykatka.dns
def checkNetworkChange(bot, result_list): def checkNetworkChange(bot, result_list):
...@@ -58,13 +58,13 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -58,13 +58,13 @@ class SurykatkaBotTestCase(unittest.TestCase):
def test_emptyConfiguration(self): def test_emptyConfiguration(self):
resolver_ip = "192.168.0.254" resolver_ip = "192.168.0.254"
resolver = surykatka_dns.dns.resolver.Resolver(configure=False) resolver = surykatka.dns.dns.resolver.Resolver(configure=False)
resolver.nameservers.append(resolver_ip) resolver.nameservers.append(resolver_ip)
with mock.patch( with mock.patch(
"surykatka_configuration.get_default_resolver" "surykatka.configuration.get_default_resolver"
) as mock_get_default_resolver, mock.patch( ) as mock_get_default_resolver, mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
mock_get_default_resolver.return_value = resolver mock_get_default_resolver.return_value = resolver
...@@ -87,17 +87,17 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -87,17 +87,17 @@ class SurykatkaBotTestCase(unittest.TestCase):
def test_oneNameserverOneDomainOneIp(self): def test_oneNameserverOneDomainOneIp(self):
resolver_ip = "127.0.0.1" resolver_ip = "127.0.0.1"
resolver = surykatka_dns.dns.resolver.Resolver(configure=False) resolver = surykatka.dns.dns.resolver.Resolver(configure=False)
resolver.nameservers.append(resolver_ip) resolver.nameservers.append(resolver_ip)
with mock.patch( with mock.patch(
"surykatka_configuration.get_default_resolver" "surykatka.configuration.get_default_resolver"
) as mock_get_default_resolver, mock.patch( ) as mock_get_default_resolver, mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"surykatka_network.socket.socket" "surykatka.network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"surykatka_http.request" "surykatka.http.request"
) as mock_request: ) as mock_request:
mock_get_default_resolver.return_value = resolver mock_get_default_resolver.return_value = resolver
...@@ -142,11 +142,11 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -142,11 +142,11 @@ class SurykatkaBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"surykatka_network.socket.socket" "surykatka.network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"surykatka_http.request" "surykatka.http.request"
) as mock_request: ) as mock_request:
mock_query.return_value = [MockAnswer("1.2.3.4")] mock_query.return_value = [MockAnswer("1.2.3.4")]
...@@ -194,11 +194,11 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -194,11 +194,11 @@ class SurykatkaBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"surykatka_network.socket.socket" "surykatka.network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"surykatka_http.request" "surykatka.http.request"
) as mock_request: ) as mock_request:
mock_query.return_value = [MockAnswer("1.2.3.4")] mock_query.return_value = [MockAnswer("1.2.3.4")]
...@@ -239,11 +239,11 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -239,11 +239,11 @@ class SurykatkaBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"surykatka_network.socket.socket" "surykatka.network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"surykatka_http.request" "surykatka.http.request"
) as mock_request: ) as mock_request:
mock_query.return_value = [ mock_query.return_value = [
...@@ -295,11 +295,11 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -295,11 +295,11 @@ class SurykatkaBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"surykatka_network.socket.socket" "surykatka.network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"surykatka_http.request" "surykatka.http.request"
) as mock_request: ) as mock_request:
mock_query.return_value = [MockAnswer("1.2.3.4")] mock_query.return_value = [MockAnswer("1.2.3.4")]
...@@ -340,11 +340,11 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -340,11 +340,11 @@ class SurykatkaBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"surykatka_network.socket.socket" "surykatka.network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"surykatka_http.request" "surykatka.http.request"
) as mock_request: ) as mock_request:
mock_query.return_value = [MockAnswer("1.2.3.4")] mock_query.return_value = [MockAnswer("1.2.3.4")]
...@@ -383,11 +383,11 @@ class SurykatkaBotTestCase(unittest.TestCase): ...@@ -383,11 +383,11 @@ class SurykatkaBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"surykatka_network.socket.socket" "surykatka.network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"surykatka_http.request" "surykatka.http.request"
) as mock_request: ) as mock_request:
mock_query.side_effect = [[MockAnswer("1.2.3.4")], []] mock_query.side_effect = [[MockAnswer("1.2.3.4")], []]
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import unittest import unittest
from surykatka_db import LogDB from surykatka.db import LogDB
class SurykatkaDBTestCase(unittest.TestCase): class SurykatkaDBTestCase(unittest.TestCase):
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import unittest import unittest
from surykatka_db import LogDB from surykatka.db import LogDB
import peewee import peewee
import surykatka_dns import surykatka.dns
from surykatka_dns import ( from surykatka.dns import (
expandDomainList, expandDomainList,
logDnsQuery, logDnsQuery,
buildResolver, buildResolver,
...@@ -29,7 +29,7 @@ from surykatka_dns import ( ...@@ -29,7 +29,7 @@ from surykatka_dns import (
getReachableResolverList, getReachableResolverList,
getDomainIpDict, getDomainIpDict,
) )
from surykatka_status import logStatus from surykatka.status import logStatus
import mock import mock
...@@ -245,7 +245,7 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -245,7 +245,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
mock_query.return_value = [ mock_query.return_value = [
MockAnswer("4.3.2.1"), MockAnswer("4.3.2.1"),
...@@ -286,11 +286,11 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -286,11 +286,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_dns.dns.resolver.NXDOMAIN() raise surykatka.dns.dns.resolver.NXDOMAIN()
mock_query.side_effect = sideEffect mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype) result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
...@@ -315,11 +315,11 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -315,11 +315,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_dns.dns.resolver.NoAnswer() raise surykatka.dns.dns.resolver.NoAnswer()
mock_query.side_effect = sideEffect mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype) result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
...@@ -344,11 +344,11 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -344,11 +344,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_dns.dns.exception.Timeout() raise surykatka.dns.dns.exception.Timeout()
mock_query.side_effect = sideEffect mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype) result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
...@@ -373,11 +373,11 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -373,11 +373,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_dns.dns.resolver.NoNameservers() raise surykatka.dns.dns.resolver.NoNameservers()
mock_query.side_effect = sideEffect mock_query.side_effect = sideEffect
result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype) result = queryDNS(self.db, status_id, resolver_ip, domain, rdtype)
...@@ -405,7 +405,7 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -405,7 +405,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
mock_query.return_value = [ mock_query.return_value = [
MockAnswer("4.3.2.1"), MockAnswer("4.3.2.1"),
...@@ -442,11 +442,11 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -442,11 +442,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_dns.dns.exception.Timeout() raise surykatka.dns.dns.exception.Timeout()
mock_query.side_effect = sideEffect mock_query.side_effect = sideEffect
...@@ -484,7 +484,7 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -484,7 +484,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
mock_query.return_value = [ mock_query.return_value = [
MockAnswer("4.3.2.1"), MockAnswer("4.3.2.1"),
...@@ -513,7 +513,7 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -513,7 +513,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
mock_query.side_effect = [ mock_query.side_effect = [
[MockAnswer("4.3.2.1"), MockAnswer("1.2.3.4")], [MockAnswer("4.3.2.1"), MockAnswer("1.2.3.4")],
...@@ -546,7 +546,7 @@ class SurykatkaDNSTestCase(unittest.TestCase): ...@@ -546,7 +546,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"surykatka_dns.dns.resolver.Resolver.query" "surykatka.dns.dns.resolver.Resolver.query"
) as mock_query: ) as mock_query:
mock_query.side_effect = [ mock_query.side_effect = [
[MockAnswer("4.3.2.1"), MockAnswer("1.2.3.4")], [MockAnswer("4.3.2.1"), MockAnswer("1.2.3.4")],
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import unittest import unittest
from surykatka_db import LogDB from surykatka.db import LogDB
import surykatka_http import surykatka.http
from surykatka_http import ( from surykatka.http import (
getUrlHostname, getUrlHostname,
getRootUrl, getRootUrl,
getUserAgent, getUserAgent,
...@@ -28,7 +28,7 @@ from surykatka_http import ( ...@@ -28,7 +28,7 @@ from surykatka_http import (
logHttpStatus, logHttpStatus,
checkHttpStatus, checkHttpStatus,
) )
from surykatka_status import logStatus from surykatka.status import logStatus
import httpretty import httpretty
import mock import mock
import peewee import peewee
...@@ -68,7 +68,7 @@ class SurykatkaHttpTestCase(unittest.TestCase): ...@@ -68,7 +68,7 @@ class SurykatkaHttpTestCase(unittest.TestCase):
################################################ ################################################
def test_request_arguments(self): def test_request_arguments(self):
url_to_proxy = "http://example.org/" url_to_proxy = "http://example.org/"
with mock.patch("surykatka_http.requests.request") as mock_request: with mock.patch("surykatka.http.requests.request") as mock_request:
request(url_to_proxy) request(url_to_proxy)
assert mock_request.call_count == 1 assert mock_request.call_count == 1
mock_request.assert_called_with( mock_request.assert_called_with(
...@@ -128,10 +128,10 @@ class SurykatkaHttpTestCase(unittest.TestCase): ...@@ -128,10 +128,10 @@ class SurykatkaHttpTestCase(unittest.TestCase):
def test_request_connectionError(self): def test_request_connectionError(self):
url_to_proxy = "http://example.org/" url_to_proxy = "http://example.org/"
httpretty.register_uri(httpretty.GET, url_to_proxy) httpretty.register_uri(httpretty.GET, url_to_proxy)
with mock.patch("surykatka_http.requests.request") as mock_request: with mock.patch("surykatka.http.requests.request") as mock_request:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_http.requests.exceptions.ConnectionError() raise surykatka.http.requests.exceptions.ConnectionError()
mock_request.side_effect = sideEffect mock_request.side_effect = sideEffect
response = request(url_to_proxy) response = request(url_to_proxy)
...@@ -141,10 +141,10 @@ class SurykatkaHttpTestCase(unittest.TestCase): ...@@ -141,10 +141,10 @@ class SurykatkaHttpTestCase(unittest.TestCase):
def test_request_timeout(self): def test_request_timeout(self):
url_to_proxy = "http://example.org/" url_to_proxy = "http://example.org/"
httpretty.register_uri(httpretty.GET, url_to_proxy) httpretty.register_uri(httpretty.GET, url_to_proxy)
with mock.patch("surykatka_http.requests.request") as mock_request: with mock.patch("surykatka.http.requests.request") as mock_request:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_http.requests.exceptions.Timeout() raise surykatka.http.requests.exceptions.Timeout()
mock_request.side_effect = sideEffect mock_request.side_effect = sideEffect
response = request(url_to_proxy) response = request(url_to_proxy)
...@@ -154,10 +154,10 @@ class SurykatkaHttpTestCase(unittest.TestCase): ...@@ -154,10 +154,10 @@ class SurykatkaHttpTestCase(unittest.TestCase):
def test_request_tooManyRedirect(self): def test_request_tooManyRedirect(self):
url_to_proxy = "http://example.org/" url_to_proxy = "http://example.org/"
httpretty.register_uri(httpretty.GET, url_to_proxy) httpretty.register_uri(httpretty.GET, url_to_proxy)
with mock.patch("surykatka_http.requests.request") as mock_request: with mock.patch("surykatka.http.requests.request") as mock_request:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_http.requests.exceptions.TooManyRedirects() raise surykatka.http.requests.exceptions.TooManyRedirects()
mock_request.side_effect = sideEffect mock_request.side_effect = sideEffect
response = request(url_to_proxy) response = request(url_to_proxy)
...@@ -167,10 +167,10 @@ class SurykatkaHttpTestCase(unittest.TestCase): ...@@ -167,10 +167,10 @@ class SurykatkaHttpTestCase(unittest.TestCase):
def test_request_sslError(self): def test_request_sslError(self):
url_to_proxy = "http://example.org/" url_to_proxy = "http://example.org/"
httpretty.register_uri(httpretty.GET, url_to_proxy) httpretty.register_uri(httpretty.GET, url_to_proxy)
with mock.patch("surykatka_http.requests.request") as mock_request: with mock.patch("surykatka.http.requests.request") as mock_request:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_http.requests.exceptions.SSLError() raise surykatka.http.requests.exceptions.SSLError()
mock_request.side_effect = sideEffect mock_request.side_effect = sideEffect
response = request(url_to_proxy) response = request(url_to_proxy)
...@@ -322,7 +322,7 @@ class SurykatkaHttpTestCase(unittest.TestCase): ...@@ -322,7 +322,7 @@ class SurykatkaHttpTestCase(unittest.TestCase):
bot_version = 2 bot_version = 2
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_http.request") as mock_request: with mock.patch("surykatka.http.request") as mock_request:
checkHttpStatus(self.db, status_id, url, ip, bot_version) checkHttpStatus(self.db, status_id, url, ip, bot_version)
assert mock_request.call_count == 1 assert mock_request.call_count == 1
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import unittest import unittest
from surykatka_db import LogDB from surykatka.db import LogDB
import surykatka_network import surykatka.network
from surykatka_network import logNetwork, isTcpPortOpen from surykatka.network import logNetwork, isTcpPortOpen
from surykatka_status import logStatus from surykatka.status import logStatus
import mock import mock
import peewee import peewee
...@@ -189,7 +189,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase): ...@@ -189,7 +189,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_network.socket.socket") as mock_socket: with mock.patch("surykatka.network.socket.socket") as mock_socket:
result = isTcpPortOpen(self.db, ip, port, status_id) result = isTcpPortOpen(self.db, ip, port, status_id)
assert mock_socket.call_count == 1 assert mock_socket.call_count == 1
...@@ -214,7 +214,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase): ...@@ -214,7 +214,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_network.socket.socket") as mock_socket: with mock.patch("surykatka.network.socket.socket") as mock_socket:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise ConnectionRefusedError() raise ConnectionRefusedError()
...@@ -245,10 +245,10 @@ class SurykatkaNetworkTestCase(unittest.TestCase): ...@@ -245,10 +245,10 @@ class SurykatkaNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_network.socket.socket") as mock_socket: with mock.patch("surykatka.network.socket.socket") as mock_socket:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise surykatka_network.socket.timeout() raise surykatka.network.socket.timeout()
mock_socket.return_value.connect.side_effect = sideEffect mock_socket.return_value.connect.side_effect = sideEffect
...@@ -276,10 +276,10 @@ class SurykatkaNetworkTestCase(unittest.TestCase): ...@@ -276,10 +276,10 @@ class SurykatkaNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_network.socket.socket") as mock_socket: with mock.patch("surykatka.network.socket.socket") as mock_socket:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise OSError(surykatka_network.errno.EHOSTUNREACH, "foo") raise OSError(surykatka.network.errno.EHOSTUNREACH, "foo")
mock_socket.return_value.connect.side_effect = sideEffect mock_socket.return_value.connect.side_effect = sideEffect
...@@ -307,10 +307,10 @@ class SurykatkaNetworkTestCase(unittest.TestCase): ...@@ -307,10 +307,10 @@ class SurykatkaNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_network.socket.socket") as mock_socket: with mock.patch("surykatka.network.socket.socket") as mock_socket:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise OSError(surykatka_network.errno.ENETUNREACH, "foo") raise OSError(surykatka.network.errno.ENETUNREACH, "foo")
mock_socket.return_value.connect.side_effect = sideEffect mock_socket.return_value.connect.side_effect = sideEffect
...@@ -338,7 +338,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase): ...@@ -338,7 +338,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_network.socket.socket") as mock_socket: with mock.patch("surykatka.network.socket.socket") as mock_socket:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise OSError() raise OSError()
...@@ -367,7 +367,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase): ...@@ -367,7 +367,7 @@ class SurykatkaNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("surykatka_network.socket.socket") as mock_socket: with mock.patch("surykatka.network.socket.socket") as mock_socket:
def sideEffect(*args, **kw): def sideEffect(*args, **kw):
raise Exception() raise Exception()
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
import unittest import unittest
from surykatka_db import LogDB from surykatka.db import LogDB
from surykatka_status import logStatus from surykatka.status import logStatus
class SurykatkaStatusTestCase(unittest.TestCase): class SurykatkaStatusTestCase(unittest.TestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment