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
15e0532a
Commit
15e0532a
authored
Dec 10, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Organize code in subdirectory
parent
345d33ee
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
94 additions
and
107 deletions
+94
-107
CONTRIBUTE.md
CONTRIBUTE.md
+3
-2
setup.py
setup.py
+4
-13
src/surykatka/__init__.py
src/surykatka/__init__.py
+0
-0
src/surykatka/bot.py
src/surykatka/bot.py
+6
-11
src/surykatka/cli.py
src/surykatka/cli.py
+1
-1
src/surykatka/configuration.py
src/surykatka/configuration.py
+0
-0
src/surykatka/db.py
src/surykatka/db.py
+0
-0
src/surykatka/dns.py
src/surykatka/dns.py
+1
-1
src/surykatka/http.py
src/surykatka/http.py
+0
-0
src/surykatka/network.py
src/surykatka/network.py
+0
-0
src/surykatka/platform.py
src/surykatka/platform.py
+0
-0
src/surykatka/status.py
src/surykatka/status.py
+0
-0
tests/test_bot.py
tests/test_bot.py
+29
-29
tests/test_db.py
tests/test_db.py
+1
-1
tests/test_dns.py
tests/test_dns.py
+19
-19
tests/test_http.py
tests/test_http.py
+14
-14
tests/test_network.py
tests/test_network.py
+14
-14
tests/test_status.py
tests/test_status.py
+2
-2
No files found.
CONTRIBUTE.md
View file @
15e0532a
...
@@ -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
...
...
setup.py
View file @
15e0532a
...
@@ -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 "
]
},
},
)
)
src/surykatka/__init__.py
0 → 100644
View file @
15e0532a
s
urykatka_
bot.py
→
s
rc/surykatka/
bot.py
View file @
15e0532a
...
@@ -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
...
...
s
urykatka_
cli.py
→
s
rc/surykatka/
cli.py
View file @
15e0532a
...
@@ -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."
)
...
...
s
urykatka_
configuration.py
→
s
rc/surykatka/
configuration.py
View file @
15e0532a
File moved
s
urykatka_
db.py
→
s
rc/surykatka/
db.py
View file @
15e0532a
File moved
s
urykatka_
dns.py
→
s
rc/surykatka/
dns.py
View file @
15e0532a
...
@@ -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"
...
...
s
urykatka_
http.py
→
s
rc/surykatka/
http.py
View file @
15e0532a
File moved
s
urykatka_
network.py
→
s
rc/surykatka/
network.py
View file @
15e0532a
File moved
s
urykatka_
platform.py
→
s
rc/surykatka/
platform.py
View file @
15e0532a
File moved
s
urykatka_
status.py
→
s
rc/surykatka/
status.py
View file @
15e0532a
File moved
test
_surykatka
_bot.py
→
test
s/test
_bot.py
View file @
15e0532a
...
@@ -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"
)],
[]]
...
...
test
_surykatka
_db.py
→
test
s/test
_db.py
View file @
15e0532a
...
@@ -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
):
...
...
test
_surykatka
_dns.py
→
test
s/test
_dns.py
View file @
15e0532a
...
@@ -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"
)],
...
...
test
_surykatka
_http.py
→
test
s/test
_http.py
View file @
15e0532a
...
@@ -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
...
...
test
_surykatka
_network.py
→
test
s/test
_network.py
View file @
15e0532a
...
@@ -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
()
...
...
test
_surykatka
_status.py
→
test
s/test
_status.py
View file @
15e0532a
...
@@ -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
):
...
...
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