Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
url-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
url-checker
Commits
24855ebb
Commit
24855ebb
authored
Dec 09, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename
parent
dcdb21ef
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
125 additions
and
122 deletions
+125
-122
README.md
README.md
+1
-1
setup.py
setup.py
+10
-10
surykatka_bot.py
surykatka_bot.py
+6
-6
surykatka_cli.py
surykatka_cli.py
+4
-5
surykatka_configuration.py
surykatka_configuration.py
+2
-2
surykatka_db.py
surykatka_db.py
+4
-0
surykatka_dns.py
surykatka_dns.py
+1
-1
surykatka_http.py
surykatka_http.py
+2
-2
surykatka_network.py
surykatka_network.py
+0
-0
surykatka_platform.py
surykatka_platform.py
+0
-0
surykatka_status.py
surykatka_status.py
+0
-0
test_surykatka_bot.py
test_surykatka_bot.py
+31
-31
test_surykatka_db.py
test_surykatka_db.py
+3
-3
test_surykatka_dns.py
test_surykatka_dns.py
+21
-21
test_surykatka_http.py
test_surykatka_http.py
+20
-20
test_surykatka_network.py
test_surykatka_network.py
+16
-16
test_surykatka_status.py
test_surykatka_status.py
+4
-4
No files found.
README.md
View file @
24855ebb
#
Url checker
#
surykatka
setup.py
View file @
24855ebb
...
...
@@ -21,21 +21,21 @@
from
setuptools
import
setup
setup
(
name
=
"
urlchecker
"
,
name
=
"
surykatka
"
,
version
=
"0.0.1"
,
license
=
"GPLv3+"
,
author
=
"Nexedi"
,
author_email
=
"romain@nexedi.com"
,
long_description
=
__doc__
,
py_modules
=
[
"
urlchecker
_bot"
,
"
urlchecker
_cli"
,
"
urlchecker
_configuration"
,
"
urlchecker
_dns"
,
"
urlchecker
_http"
,
"
urlchecker
_network"
,
"
urlchecker
_platform"
,
"
urlchecker
_status"
,
"
surykatka
_bot"
,
"
surykatka
_cli"
,
"
surykatka
_configuration"
,
"
surykatka
_dns"
,
"
surykatka
_http"
,
"
surykatka
_network"
,
"
surykatka
_platform"
,
"
surykatka
_status"
,
],
include_package_data
=
False
,
zip_safe
=
True
,
...
...
@@ -52,6 +52,6 @@ setup(
"dev"
:
[
"pytest"
,
"black"
,
"pyflakes"
,
"mock"
,
"httpretty"
]
},
entry_points
=
{
"console_scripts"
:
[
"
urlchecker=urlchecker_cli:runUrlChecker
"
]
"console_scripts"
:
[
"
surykatka=surykatka_cli:runSurykatka
"
]
},
)
urlchecker
_bot.py
→
surykatka
_bot.py
View file @
24855ebb
...
...
@@ -18,22 +18,22 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
time
from
urlchecker
_db
import
LogDB
from
urlchecker
_configuration
import
createConfiguration
,
logConfiguration
from
urlchecker
_status
import
logStatus
,
reportStatus
from
urlchecker
_dns
import
(
from
surykatka
_db
import
LogDB
from
surykatka
_configuration
import
createConfiguration
,
logConfiguration
from
surykatka
_status
import
logStatus
,
reportStatus
from
surykatka
_dns
import
(
getReachableResolverList
,
expandDomainList
,
getDomainIpDict
,
reportDnsQuery
,
)
from
urlchecker
_http
import
(
from
surykatka
_http
import
(
getRootUrl
,
getUrlHostname
,
checkHttpStatus
,
reportHttp
,
)
from
urlchecker
_network
import
isTcpPortOpen
,
reportNetwork
from
surykatka
_network
import
isTcpPortOpen
,
reportNetwork
import
json
import
email.utils
from
collections
import
OrderedDict
...
...
urlchecker
_cli.py
→
surykatka
_cli.py
View file @
24855ebb
...
...
@@ -19,10 +19,10 @@
import
click
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
(
"--run"
,
"-r"
,
...
...
@@ -55,7 +55,7 @@ from urlchecker_bot import create_bot
default
=
"plain"
,
show_default
=
True
,
)
def
run
UrlChecker
(
def
run
Surykatka
(
run
,
sqlite
,
nameserver
,
...
...
@@ -67,7 +67,6 @@ def runUrlChecker(
output
,
):
# click.echo("Running url checker bot")
mapping
=
{}
if
url
:
mapping
[
"URL"
]
=
url
...
...
@@ -88,4 +87,4 @@ def runUrlChecker(
if
__name__
==
"__main__"
:
sys
.
exit
(
run
UrlChecker
())
sys
.
exit
(
run
Surykatka
())
urlchecker
_configuration.py
→
surykatka
_configuration.py
View file @
24855ebb
...
...
@@ -22,11 +22,11 @@ import os
from
dns.resolver
import
get_default_resolver
CONFIG_SECTION
=
"
URLCHECKER
"
CONFIG_SECTION
=
"
SURYKATKA
"
def
createConfiguration
(
envvar
=
"
URLCHECKER
_SETTINGS"
,
cfgfile
=
None
,
mapping
=
None
envvar
=
"
SURYKATKA
_SETTINGS"
,
cfgfile
=
None
,
mapping
=
None
):
config
=
configparser
.
ConfigParser
(
empty_lines_in_values
=
False
)
# Default values
...
...
urlchecker
_db.py
→
surykatka
_db.py
View file @
24855ebb
...
...
@@ -56,6 +56,10 @@ class LogDB:
class
Meta
:
primary_key
=
peewee
.
CompositeKey
(
"status"
,
"parameter"
)
# indexes = (
# create a unique on from/to/date
# (('status', 'parameter'), True),
# )
# Store the configuration modification
class
PlatformChange
(
BaseModel
):
...
...
urlchecker
_dns.py
→
surykatka
_dns.py
View file @
24855ebb
...
...
@@ -18,7 +18,7 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
dns
from
urlchecker
_network
import
logNetwork
from
surykatka
_network
import
logNetwork
from
peewee
import
fn
URL_TO_CHECK
=
"example.org"
...
...
urlchecker
_http.py
→
surykatka
_http.py
View file @
24855ebb
...
...
@@ -38,9 +38,9 @@ def getRootUrl(url):
def
getUserAgent
(
version
):
return
"%s/%s (+%s)"
%
(
"
URLCHECKER
"
,
"
SURYKATKA
"
,
version
,
"https://lab.nexedi.com/
romain/url-checker
"
,
"https://lab.nexedi.com/
nexedi/surykatka
"
,
)
...
...
urlchecker
_network.py
→
surykatka
_network.py
View file @
24855ebb
File moved
urlchecker
_platform.py
→
surykatka
_platform.py
View file @
24855ebb
File moved
urlchecker
_status.py
→
surykatka
_status.py
View file @
24855ebb
File moved
test_
urlchecker
_bot.py
→
test_
surykatka
_bot.py
View file @
24855ebb
...
...
@@ -18,10 +18,10 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
unittest
from
urlchecker
_bot
import
WebBot
from
surykatka
_bot
import
WebBot
import
mock
from
test_
urlchecker
_dns
import
MockAnswer
import
urlchecker
_dns
from
test_
surykatka
_dns
import
MockAnswer
import
surykatka
_dns
def
checkNetworkChange
(
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
class
UrlChecker
BotTestCase
(
unittest
.
TestCase
):
class
Surykatka
BotTestCase
(
unittest
.
TestCase
):
def
test_emptyConfiguration
(
self
):
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
)
with
mock
.
patch
(
"
urlchecker
_configuration.get_default_resolver"
"
surykatka
_configuration.get_default_resolver"
)
as
mock_get_default_resolver
,
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_get_default_resolver
.
return_value
=
resolver
...
...
@@ -87,17 +87,17 @@ class UrlCheckerBotTestCase(unittest.TestCase):
def
test_oneNameserverOneDomainOneIp
(
self
):
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
)
with
mock
.
patch
(
"
urlchecker
_configuration.get_default_resolver"
"
surykatka
_configuration.get_default_resolver"
)
as
mock_get_default_resolver
,
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"
urlchecker
_network.socket.socket"
"
surykatka
_network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
"
urlchecker
_http.request"
"
surykatka
_http.request"
)
as
mock_request
:
mock_get_default_resolver
.
return_value
=
resolver
...
...
@@ -142,11 +142,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot
.
initDB
()
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"
urlchecker
_network.socket.socket"
"
surykatka
_network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
"
urlchecker
_http.request"
"
surykatka
_http.request"
)
as
mock_request
:
mock_query
.
return_value
=
[
MockAnswer
(
"1.2.3.4"
)]
...
...
@@ -194,11 +194,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot
.
initDB
()
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"
urlchecker
_network.socket.socket"
"
surykatka
_network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
"
urlchecker
_http.request"
"
surykatka
_http.request"
)
as
mock_request
:
mock_query
.
return_value
=
[
MockAnswer
(
"1.2.3.4"
)]
...
...
@@ -239,11 +239,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot
.
initDB
()
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"
urlchecker
_network.socket.socket"
"
surykatka
_network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
"
urlchecker
_http.request"
"
surykatka
_http.request"
)
as
mock_request
:
mock_query
.
return_value
=
[
...
...
@@ -295,11 +295,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot
.
initDB
()
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"
urlchecker
_network.socket.socket"
"
surykatka
_network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
"
urlchecker
_http.request"
"
surykatka
_http.request"
)
as
mock_request
:
mock_query
.
return_value
=
[
MockAnswer
(
"1.2.3.4"
)]
...
...
@@ -340,11 +340,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot
.
initDB
()
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"
urlchecker
_network.socket.socket"
"
surykatka
_network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
"
urlchecker
_http.request"
"
surykatka
_http.request"
)
as
mock_request
:
mock_query
.
return_value
=
[
MockAnswer
(
"1.2.3.4"
)]
...
...
@@ -383,11 +383,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
bot
.
initDB
()
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"
urlchecker
_network.socket.socket"
"
surykatka
_network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
"
urlchecker
_http.request"
"
surykatka
_http.request"
)
as
mock_request
:
mock_query
.
side_effect
=
[[
MockAnswer
(
"1.2.3.4"
)],
[]]
...
...
@@ -408,7 +408,7 @@ class UrlCheckerBotTestCase(unittest.TestCase):
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UrlChecker
BotTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
Surykatka
BotTestCase
))
return
suite
...
...
test_
urlchecker
_db.py
→
test_
surykatka
_db.py
View file @
24855ebb
...
...
@@ -18,10 +18,10 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
unittest
from
urlchecker
_db
import
LogDB
from
surykatka
_db
import
LogDB
class
UrlChecker
DBTestCase
(
unittest
.
TestCase
):
class
Surykatka
DBTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
db
=
LogDB
(
":memory:"
)
...
...
@@ -33,7 +33,7 @@ class UrlCheckerDBTestCase(unittest.TestCase):
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UrlChecker
DBTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
Surykatka
DBTestCase
))
return
suite
...
...
test_
urlchecker
_dns.py
→
test_
surykatka
_dns.py
View file @
24855ebb
...
...
@@ -18,10 +18,10 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
unittest
from
urlchecker
_db
import
LogDB
from
surykatka
_db
import
LogDB
import
peewee
import
urlchecker
_dns
from
urlchecker
_dns
import
(
import
surykatka
_dns
from
surykatka
_dns
import
(
expandDomainList
,
logDnsQuery
,
buildResolver
,
...
...
@@ -29,7 +29,7 @@ from urlchecker_dns import (
getReachableResolverList
,
getDomainIpDict
,
)
from
urlchecker
_status
import
logStatus
from
surykatka
_status
import
logStatus
import
mock
...
...
@@ -38,7 +38,7 @@ class MockAnswer(object):
self
.
address
=
address
class
UrlChecker
DNSTestCase
(
unittest
.
TestCase
):
class
Surykatka
DNSTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
db
=
LogDB
(
":memory:"
)
self
.
db
.
createTables
()
...
...
@@ -245,7 +245,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
...
...
@@ -286,11 +286,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
urlchecker
_dns
.
dns
.
resolver
.
NXDOMAIN
()
raise
surykatka
_dns
.
dns
.
resolver
.
NXDOMAIN
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -315,11 +315,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
urlchecker
_dns
.
dns
.
resolver
.
NoAnswer
()
raise
surykatka
_dns
.
dns
.
resolver
.
NoAnswer
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -344,11 +344,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
urlchecker
_dns
.
dns
.
exception
.
Timeout
()
raise
surykatka
_dns
.
dns
.
exception
.
Timeout
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -373,11 +373,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
urlchecker
_dns
.
dns
.
resolver
.
NoNameservers
()
raise
surykatka
_dns
.
dns
.
resolver
.
NoNameservers
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -405,7 +405,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
...
...
@@ -442,11 +442,11 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
urlchecker
_dns
.
dns
.
exception
.
Timeout
()
raise
surykatka
_dns
.
dns
.
exception
.
Timeout
()
mock_query
.
side_effect
=
sideEffect
...
...
@@ -484,7 +484,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
...
...
@@ -513,7 +513,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
side_effect
=
[
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
)],
...
...
@@ -546,7 +546,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"
urlchecker
_dns.dns.resolver.Resolver.query"
"
surykatka
_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
side_effect
=
[
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
)],
...
...
@@ -575,7 +575,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UrlChecker
DNSTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
Surykatka
DNSTestCase
))
return
suite
...
...
test_
urlchecker
_http.py
→
test_
surykatka
_http.py
View file @
24855ebb
...
...
@@ -18,9 +18,9 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
unittest
from
urlchecker
_db
import
LogDB
import
urlchecker
_http
from
urlchecker
_http
import
(
from
surykatka
_db
import
LogDB
import
surykatka
_http
from
surykatka
_http
import
(
getUrlHostname
,
getRootUrl
,
getUserAgent
,
...
...
@@ -28,13 +28,13 @@ from urlchecker_http import (
logHttpStatus
,
checkHttpStatus
,
)
from
urlchecker
_status
import
logStatus
from
surykatka
_status
import
logStatus
import
httpretty
import
mock
import
peewee
class
UrlChecker
HttpTestCase
(
unittest
.
TestCase
):
class
Surykatka
HttpTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
db
=
LogDB
(
":memory:"
)
self
.
db
.
createTables
()
...
...
@@ -60,7 +60,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
result
=
getUserAgent
(
"0.0.3"
)
assert
(
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):
################################################
def
test_request_arguments
(
self
):
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
)
assert
mock_request
.
call_count
==
1
mock_request
.
assert_called_with
(
...
...
@@ -77,7 +77,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
allow_redirects
=
False
,
headers
=
{
"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
,
timeout
=
2
,
...
...
@@ -98,7 +98,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
assert
last_request
.
headers
[
"Host"
]
==
"example.org"
assert
(
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
response
.
status_code
==
418
...
...
@@ -128,10 +128,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def
test_request_connectionError
(
self
):
url_to_proxy
=
"http://example.org/"
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
):
raise
urlchecker
_http
.
requests
.
exceptions
.
ConnectionError
()
raise
surykatka
_http
.
requests
.
exceptions
.
ConnectionError
()
mock_request
.
side_effect
=
sideEffect
response
=
request
(
url_to_proxy
)
...
...
@@ -141,10 +141,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def
test_request_timeout
(
self
):
url_to_proxy
=
"http://example.org/"
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
):
raise
urlchecker
_http
.
requests
.
exceptions
.
Timeout
()
raise
surykatka
_http
.
requests
.
exceptions
.
Timeout
()
mock_request
.
side_effect
=
sideEffect
response
=
request
(
url_to_proxy
)
...
...
@@ -154,10 +154,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def
test_request_tooManyRedirect
(
self
):
url_to_proxy
=
"http://example.org/"
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
):
raise
urlchecker
_http
.
requests
.
exceptions
.
TooManyRedirects
()
raise
surykatka
_http
.
requests
.
exceptions
.
TooManyRedirects
()
mock_request
.
side_effect
=
sideEffect
response
=
request
(
url_to_proxy
)
...
...
@@ -167,10 +167,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def
test_request_sslError
(
self
):
url_to_proxy
=
"http://example.org/"
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
):
raise
urlchecker
_http
.
requests
.
exceptions
.
SSLError
()
raise
surykatka
_http
.
requests
.
exceptions
.
SSLError
()
mock_request
.
side_effect
=
sideEffect
response
=
request
(
url_to_proxy
)
...
...
@@ -306,7 +306,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
assert
last_request
.
headers
[
"Host"
]
==
"example.org"
assert
(
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
...
...
@@ -322,7 +322,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
bot_version
=
2
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
)
assert
mock_request
.
call_count
==
1
...
...
@@ -362,7 +362,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UrlChecker
HttpTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
Surykatka
HttpTestCase
))
return
suite
...
...
test_
urlchecker
_network.py
→
test_
surykatka
_network.py
View file @
24855ebb
...
...
@@ -18,15 +18,15 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
unittest
from
urlchecker
_db
import
LogDB
import
urlchecker
_network
from
urlchecker
_network
import
logNetwork
,
isTcpPortOpen
from
urlchecker
_status
import
logStatus
from
surykatka
_db
import
LogDB
import
surykatka
_network
from
surykatka
_network
import
logNetwork
,
isTcpPortOpen
from
surykatka
_status
import
logStatus
import
mock
import
peewee
class
UrlChecker
NetworkTestCase
(
unittest
.
TestCase
):
class
Surykatka
NetworkTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
db
=
LogDB
(
":memory:"
)
self
.
db
.
createTables
()
...
...
@@ -189,7 +189,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port
=
1234
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
)
assert
mock_socket
.
call_count
==
1
...
...
@@ -214,7 +214,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port
=
1234
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
):
raise
ConnectionRefusedError
()
...
...
@@ -245,10 +245,10 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port
=
1234
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
):
raise
urlchecker
_network
.
socket
.
timeout
()
raise
surykatka
_network
.
socket
.
timeout
()
mock_socket
.
return_value
.
connect
.
side_effect
=
sideEffect
...
...
@@ -276,10 +276,10 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port
=
1234
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
):
raise
OSError
(
urlchecker
_network
.
errno
.
EHOSTUNREACH
,
"foo"
)
raise
OSError
(
surykatka
_network
.
errno
.
EHOSTUNREACH
,
"foo"
)
mock_socket
.
return_value
.
connect
.
side_effect
=
sideEffect
...
...
@@ -307,10 +307,10 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port
=
1234
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
):
raise
OSError
(
urlchecker
_network
.
errno
.
ENETUNREACH
,
"foo"
)
raise
OSError
(
surykatka
_network
.
errno
.
ENETUNREACH
,
"foo"
)
mock_socket
.
return_value
.
connect
.
side_effect
=
sideEffect
...
...
@@ -338,7 +338,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port
=
1234
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
):
raise
OSError
()
...
...
@@ -367,7 +367,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
port
=
1234
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
):
raise
Exception
()
...
...
@@ -394,7 +394,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UrlChecker
NetworkTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
Surykatka
NetworkTestCase
))
return
suite
...
...
test_
urlchecker
_status.py
→
test_
surykatka
_status.py
View file @
24855ebb
...
...
@@ -18,11 +18,11 @@
# See https://www.nexedi.com/licensing for rationale and options.
import
unittest
from
urlchecker
_db
import
LogDB
from
urlchecker
_status
import
logStatus
from
surykatka
_db
import
LogDB
from
surykatka
_status
import
logStatus
class
UrlChecker
StatusTestCase
(
unittest
.
TestCase
):
class
Surykatka
StatusTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
db
=
LogDB
(
":memory:"
)
self
.
db
.
createTables
()
...
...
@@ -45,7 +45,7 @@ class UrlCheckerStatusTestCase(unittest.TestCase):
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UrlChecker
StatusTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
Surykatka
StatusTestCase
))
return
suite
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment