Commit 24855ebb authored by Romain Courteaud's avatar Romain Courteaud

Rename

parent dcdb21ef
# Url checker # surykatka
...@@ -21,21 +21,21 @@ ...@@ -21,21 +21,21 @@
from setuptools import setup from setuptools import setup
setup( setup(
name="urlchecker", name="surykatka",
version="0.0.1", version="0.0.1",
license="GPLv3+", license="GPLv3+",
author="Nexedi", author="Nexedi",
author_email="romain@nexedi.com", author_email="romain@nexedi.com",
long_description=__doc__, long_description=__doc__,
py_modules=[ py_modules=[
"urlchecker_bot", "surykatka_bot",
"urlchecker_cli", "surykatka_cli",
"urlchecker_configuration", "surykatka_configuration",
"urlchecker_dns", "surykatka_dns",
"urlchecker_http", "surykatka_http",
"urlchecker_network", "surykatka_network",
"urlchecker_platform", "surykatka_platform",
"urlchecker_status", "surykatka_status",
], ],
include_package_data=False, include_package_data=False,
zip_safe=True, zip_safe=True,
...@@ -52,6 +52,6 @@ setup( ...@@ -52,6 +52,6 @@ setup(
"dev": ["pytest", "black", "pyflakes", "mock", "httpretty"] "dev": ["pytest", "black", "pyflakes", "mock", "httpretty"]
}, },
entry_points={ entry_points={
"console_scripts": ["urlchecker=urlchecker_cli:runUrlChecker "] "console_scripts": ["surykatka=surykatka_cli:runSurykatka "]
}, },
) )
...@@ -18,22 +18,22 @@ ...@@ -18,22 +18,22 @@
# 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 urlchecker_db import LogDB from surykatka_db import LogDB
from urlchecker_configuration import createConfiguration, logConfiguration from surykatka_configuration import createConfiguration, logConfiguration
from urlchecker_status import logStatus, reportStatus from surykatka_status import logStatus, reportStatus
from urlchecker_dns import ( from surykatka_dns import (
getReachableResolverList, getReachableResolverList,
expandDomainList, expandDomainList,
getDomainIpDict, getDomainIpDict,
reportDnsQuery, reportDnsQuery,
) )
from urlchecker_http import ( from surykatka_http import (
getRootUrl, getRootUrl,
getUrlHostname, getUrlHostname,
checkHttpStatus, checkHttpStatus,
reportHttp, reportHttp,
) )
from urlchecker_network import isTcpPortOpen, reportNetwork 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,10 +19,10 @@ ...@@ -19,10 +19,10 @@
import click import click
import sys import sys
from urlchecker_bot import create_bot from surykatka_bot import create_bot
@click.command(short_help="Runs url checker bot.") @click.command(short_help="Runs surykatka bot.")
@click.option( @click.option(
"--run", "--run",
"-r", "-r",
...@@ -55,7 +55,7 @@ from urlchecker_bot import create_bot ...@@ -55,7 +55,7 @@ from urlchecker_bot import create_bot
default="plain", default="plain",
show_default=True, show_default=True,
) )
def runUrlChecker( def runSurykatka(
run, run,
sqlite, sqlite,
nameserver, nameserver,
...@@ -67,7 +67,6 @@ def runUrlChecker( ...@@ -67,7 +67,6 @@ def runUrlChecker(
output, output,
): ):
# click.echo("Running url checker bot")
mapping = {} mapping = {}
if url: if url:
mapping["URL"] = url mapping["URL"] = url
...@@ -88,4 +87,4 @@ def runUrlChecker( ...@@ -88,4 +87,4 @@ def runUrlChecker(
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(runUrlChecker()) sys.exit(runSurykatka())
...@@ -22,11 +22,11 @@ import os ...@@ -22,11 +22,11 @@ import os
from dns.resolver import get_default_resolver from dns.resolver import get_default_resolver
CONFIG_SECTION = "URLCHECKER" CONFIG_SECTION = "SURYKATKA"
def createConfiguration( def createConfiguration(
envvar="URLCHECKER_SETTINGS", cfgfile=None, mapping=None envvar="SURYKATKA_SETTINGS", cfgfile=None, mapping=None
): ):
config = configparser.ConfigParser(empty_lines_in_values=False) config = configparser.ConfigParser(empty_lines_in_values=False)
# Default values # Default values
......
...@@ -56,6 +56,10 @@ class LogDB: ...@@ -56,6 +56,10 @@ class LogDB:
class Meta: class Meta:
primary_key = peewee.CompositeKey("status", "parameter") primary_key = peewee.CompositeKey("status", "parameter")
# indexes = (
# create a unique on from/to/date
# (('status', 'parameter'), True),
# )
# Store the configuration modification # Store the configuration modification
class PlatformChange(BaseModel): class PlatformChange(BaseModel):
......
...@@ -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 urlchecker_network import logNetwork from surykatka_network import logNetwork
from peewee import fn from peewee import fn
URL_TO_CHECK = "example.org" URL_TO_CHECK = "example.org"
......
...@@ -38,9 +38,9 @@ def getRootUrl(url): ...@@ -38,9 +38,9 @@ def getRootUrl(url):
def getUserAgent(version): def getUserAgent(version):
return "%s/%s (+%s)" % ( return "%s/%s (+%s)" % (
"URLCHECKER", "SURYKATKA",
version, version,
"https://lab.nexedi.com/romain/url-checker", "https://lab.nexedi.com/nexedi/surykatka",
) )
......
...@@ -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 urlchecker_bot import WebBot from surykatka_bot import WebBot
import mock import mock
from test_urlchecker_dns import MockAnswer from test_surykatka_dns import MockAnswer
import urlchecker_dns import surykatka_dns
def checkNetworkChange(bot, result_list): def checkNetworkChange(bot, result_list):
...@@ -54,17 +54,17 @@ def checkDnsChange(bot, result_list): ...@@ -54,17 +54,17 @@ def checkDnsChange(bot, result_list):
assert [(x.resolver_ip, x.domain) for x in select_list] == result_list assert [(x.resolver_ip, x.domain) for x in select_list] == result_list
class UrlCheckerBotTestCase(unittest.TestCase): 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 = urlchecker_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(
"urlchecker_configuration.get_default_resolver" "surykatka_configuration.get_default_resolver"
) as mock_get_default_resolver, mock.patch( ) as mock_get_default_resolver, mock.patch(
"urlchecker_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 UrlCheckerBotTestCase(unittest.TestCase): ...@@ -87,17 +87,17 @@ class UrlCheckerBotTestCase(unittest.TestCase):
def test_oneNameserverOneDomainOneIp(self): def test_oneNameserverOneDomainOneIp(self):
resolver_ip = "127.0.0.1" resolver_ip = "127.0.0.1"
resolver = urlchecker_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(
"urlchecker_configuration.get_default_resolver" "surykatka_configuration.get_default_resolver"
) as mock_get_default_resolver, mock.patch( ) as mock_get_default_resolver, mock.patch(
"urlchecker_dns.dns.resolver.Resolver.query" "surykatka_dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"urlchecker_network.socket.socket" "surykatka_network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"urlchecker_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 UrlCheckerBotTestCase(unittest.TestCase): ...@@ -142,11 +142,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"urlchecker_dns.dns.resolver.Resolver.query" "surykatka_dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"urlchecker_network.socket.socket" "surykatka_network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"urlchecker_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 UrlCheckerBotTestCase(unittest.TestCase): ...@@ -194,11 +194,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"urlchecker_dns.dns.resolver.Resolver.query" "surykatka_dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"urlchecker_network.socket.socket" "surykatka_network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"urlchecker_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 UrlCheckerBotTestCase(unittest.TestCase): ...@@ -239,11 +239,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"urlchecker_dns.dns.resolver.Resolver.query" "surykatka_dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"urlchecker_network.socket.socket" "surykatka_network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"urlchecker_http.request" "surykatka_http.request"
) as mock_request: ) as mock_request:
mock_query.return_value = [ mock_query.return_value = [
...@@ -295,11 +295,11 @@ class UrlCheckerBotTestCase(unittest.TestCase): ...@@ -295,11 +295,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"urlchecker_dns.dns.resolver.Resolver.query" "surykatka_dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"urlchecker_network.socket.socket" "surykatka_network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"urlchecker_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 UrlCheckerBotTestCase(unittest.TestCase): ...@@ -340,11 +340,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"urlchecker_dns.dns.resolver.Resolver.query" "surykatka_dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"urlchecker_network.socket.socket" "surykatka_network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"urlchecker_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 UrlCheckerBotTestCase(unittest.TestCase): ...@@ -383,11 +383,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot.initDB() bot.initDB()
with mock.patch( with mock.patch(
"urlchecker_dns.dns.resolver.Resolver.query" "surykatka_dns.dns.resolver.Resolver.query"
) as mock_query, mock.patch( ) as mock_query, mock.patch(
"urlchecker_network.socket.socket" "surykatka_network.socket.socket"
) as mock_socket, mock.patch( ) as mock_socket, mock.patch(
"urlchecker_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")], []]
...@@ -408,7 +408,7 @@ class UrlCheckerBotTestCase(unittest.TestCase): ...@@ -408,7 +408,7 @@ class UrlCheckerBotTestCase(unittest.TestCase):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UrlCheckerBotTestCase)) suite.addTest(unittest.makeSuite(SurykatkaBotTestCase))
return suite return suite
......
...@@ -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 urlchecker_db import LogDB from surykatka_db import LogDB
class UrlCheckerDBTestCase(unittest.TestCase): class SurykatkaDBTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.db = LogDB(":memory:") self.db = LogDB(":memory:")
...@@ -33,7 +33,7 @@ class UrlCheckerDBTestCase(unittest.TestCase): ...@@ -33,7 +33,7 @@ class UrlCheckerDBTestCase(unittest.TestCase):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UrlCheckerDBTestCase)) suite.addTest(unittest.makeSuite(SurykatkaDBTestCase))
return suite return suite
......
...@@ -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 urlchecker_db import LogDB from surykatka_db import LogDB
import peewee import peewee
import urlchecker_dns import surykatka_dns
from urlchecker_dns import ( from surykatka_dns import (
expandDomainList, expandDomainList,
logDnsQuery, logDnsQuery,
buildResolver, buildResolver,
...@@ -29,7 +29,7 @@ from urlchecker_dns import ( ...@@ -29,7 +29,7 @@ from urlchecker_dns import (
getReachableResolverList, getReachableResolverList,
getDomainIpDict, getDomainIpDict,
) )
from urlchecker_status import logStatus from surykatka_status import logStatus
import mock import mock
...@@ -38,7 +38,7 @@ class MockAnswer(object): ...@@ -38,7 +38,7 @@ class MockAnswer(object):
self.address = address self.address = address
class UrlCheckerDNSTestCase(unittest.TestCase): class SurykatkaDNSTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.db = LogDB(":memory:") self.db = LogDB(":memory:")
self.db.createTables() self.db.createTables()
...@@ -245,7 +245,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -245,7 +245,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -286,11 +286,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -315,11 +315,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -344,11 +344,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -373,11 +373,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -405,7 +405,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -442,11 +442,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -484,7 +484,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -513,7 +513,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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 UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -546,7 +546,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch( with mock.patch(
"urlchecker_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")],
...@@ -575,7 +575,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase): ...@@ -575,7 +575,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UrlCheckerDNSTestCase)) suite.addTest(unittest.makeSuite(SurykatkaDNSTestCase))
return suite return suite
......
...@@ -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 urlchecker_db import LogDB from surykatka_db import LogDB
import urlchecker_http import surykatka_http
from urlchecker_http import ( from surykatka_http import (
getUrlHostname, getUrlHostname,
getRootUrl, getRootUrl,
getUserAgent, getUserAgent,
...@@ -28,13 +28,13 @@ from urlchecker_http import ( ...@@ -28,13 +28,13 @@ from urlchecker_http import (
logHttpStatus, logHttpStatus,
checkHttpStatus, checkHttpStatus,
) )
from urlchecker_status import logStatus from surykatka_status import logStatus
import httpretty import httpretty
import mock import mock
import peewee import peewee
class UrlCheckerHttpTestCase(unittest.TestCase): class SurykatkaHttpTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.db = LogDB(":memory:") self.db = LogDB(":memory:")
self.db.createTables() self.db.createTables()
...@@ -60,7 +60,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -60,7 +60,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
result = getUserAgent("0.0.3") result = getUserAgent("0.0.3")
assert ( assert (
result result
== "URLCHECKER/0.0.3 (+https://lab.nexedi.com/romain/url-checker)" == "SURYKATKA/0.0.3 (+https://lab.nexedi.com/nexedi/surykatka)"
) )
################################################ ################################################
...@@ -68,7 +68,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -68,7 +68,7 @@ class UrlCheckerHttpTestCase(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("urlchecker_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(
...@@ -77,7 +77,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -77,7 +77,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
allow_redirects=False, allow_redirects=False,
headers={ headers={
"Accept": "text/html;q=0.9,*/*;q=0.8", "Accept": "text/html;q=0.9,*/*;q=0.8",
"User-Agent": "URLCHECKER/0 (+https://lab.nexedi.com/romain/url-checker)", "User-Agent": "SURYKATKA/0 (+https://lab.nexedi.com/nexedi/surykatka)",
}, },
stream=False, stream=False,
timeout=2, timeout=2,
...@@ -98,7 +98,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -98,7 +98,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
assert last_request.headers["Host"] == "example.org" assert last_request.headers["Host"] == "example.org"
assert ( assert (
last_request.headers["User-Agent"] last_request.headers["User-Agent"]
== "URLCHECKER/0 (+https://lab.nexedi.com/romain/url-checker)" == "SURYKATKA/0 (+https://lab.nexedi.com/nexedi/surykatka)"
) )
assert len(last_request.body) == 0 assert len(last_request.body) == 0
assert response.status_code == 418 assert response.status_code == 418
...@@ -128,10 +128,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -128,10 +128,10 @@ class UrlCheckerHttpTestCase(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("urlchecker_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 urlchecker_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 UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -141,10 +141,10 @@ class UrlCheckerHttpTestCase(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("urlchecker_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 urlchecker_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 UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -154,10 +154,10 @@ class UrlCheckerHttpTestCase(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("urlchecker_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 urlchecker_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 UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -167,10 +167,10 @@ class UrlCheckerHttpTestCase(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("urlchecker_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 urlchecker_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)
...@@ -306,7 +306,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -306,7 +306,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
assert last_request.headers["Host"] == "example.org" assert last_request.headers["Host"] == "example.org"
assert ( assert (
last_request.headers["User-Agent"] last_request.headers["User-Agent"]
== "URLCHECKER/1 (+https://lab.nexedi.com/romain/url-checker)" == "SURYKATKA/1 (+https://lab.nexedi.com/nexedi/surykatka)"
) )
assert len(last_request.body) == 0 assert len(last_request.body) == 0
...@@ -322,7 +322,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -322,7 +322,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
bot_version = 2 bot_version = 2
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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
...@@ -362,7 +362,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase): ...@@ -362,7 +362,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UrlCheckerHttpTestCase)) suite.addTest(unittest.makeSuite(SurykatkaHttpTestCase))
return suite return suite
......
...@@ -18,15 +18,15 @@ ...@@ -18,15 +18,15 @@
# 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 urlchecker_db import LogDB from surykatka_db import LogDB
import urlchecker_network import surykatka_network
from urlchecker_network import logNetwork, isTcpPortOpen from surykatka_network import logNetwork, isTcpPortOpen
from urlchecker_status import logStatus from surykatka_status import logStatus
import mock import mock
import peewee import peewee
class UrlCheckerNetworkTestCase(unittest.TestCase): class SurykatkaNetworkTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.db = LogDB(":memory:") self.db = LogDB(":memory:")
self.db.createTables() self.db.createTables()
...@@ -189,7 +189,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -189,7 +189,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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 UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -214,7 +214,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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 UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -245,10 +245,10 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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 urlchecker_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 UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -276,10 +276,10 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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(urlchecker_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 UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -307,10 +307,10 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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(urlchecker_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 UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -338,7 +338,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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 UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -367,7 +367,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port = 1234 port = 1234
status_id = logStatus(self.db, "foo") status_id = logStatus(self.db, "foo")
with mock.patch("urlchecker_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()
...@@ -394,7 +394,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase): ...@@ -394,7 +394,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UrlCheckerNetworkTestCase)) suite.addTest(unittest.makeSuite(SurykatkaNetworkTestCase))
return suite return suite
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
# 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 urlchecker_db import LogDB from surykatka_db import LogDB
from urlchecker_status import logStatus from surykatka_status import logStatus
class UrlCheckerStatusTestCase(unittest.TestCase): class SurykatkaStatusTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.db = LogDB(":memory:") self.db = LogDB(":memory:")
self.db.createTables() self.db.createTables()
...@@ -45,7 +45,7 @@ class UrlCheckerStatusTestCase(unittest.TestCase): ...@@ -45,7 +45,7 @@ class UrlCheckerStatusTestCase(unittest.TestCase):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UrlCheckerStatusTestCase)) suite.addTest(unittest.makeSuite(SurykatkaStatusTestCase))
return suite return suite
......
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