Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
surykatka
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
surykatka
Commits
ebd2504a
Commit
ebd2504a
authored
Dec 13, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test empty status
parent
6fef2bb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
24 deletions
+63
-24
src/surykatka/bot.py
src/surykatka/bot.py
+32
-24
tests/test_bot.py
tests/test_bot.py
+31
-0
No files found.
src/surykatka/bot.py
View file @
ebd2504a
...
@@ -152,11 +152,15 @@ class WebBot:
...
@@ -152,11 +152,15 @@ class WebBot:
result_dict
=
OrderedDict
()
result_dict
=
OrderedDict
()
# Report the bot status
# Report the bot status
status
=
reportStatus
(
self
.
_db
).
get
()
result_dict
[
"bot_status"
]
=
[]
result_dict
[
"bot_status"
]
=
[]
result_dict
[
"bot_status"
].
append
(
try
:
{
"text"
:
status
.
text
,
"date"
:
rfc822
(
status
.
timestamp
)}
status
=
reportStatus
(
self
.
_db
).
get
()
)
except
self
.
_db
.
Status
.
DoesNotExist
:
pass
else
:
result_dict
[
"bot_status"
].
append
(
{
"text"
:
status
.
text
,
"date"
:
rfc822
(
status
.
timestamp
)}
)
# Report the list of DNS server status
# Report the list of DNS server status
query
=
reportNetwork
(
query
=
reportNetwork
(
...
@@ -286,25 +290,7 @@ class WebBot:
...
@@ -286,25 +290,7 @@ class WebBot:
}
}
)
)
if
self
.
config
[
"FORMAT"
]
==
"json"
:
return
result_dict
print
(
json
.
dumps
(
result_dict
))
else
:
for
table_key
in
result_dict
:
print
(
"# %s"
%
table_key
)
print
(
""
)
table
=
result_dict
[
table_key
]
if
table
:
# Print the header
table_key_list
=
[
x
for
x
in
table
[
0
].
keys
()]
table_key_list
.
sort
()
print
(
" | "
.
join
(
table_key_list
))
for
line
in
table
:
print
(
" | "
.
join
(
[
"%s"
%
(
line
[
x
])
for
x
in
table_key_list
]
)
)
print
(
""
)
def
stop
(
self
):
def
stop
(
self
):
self
.
_running
=
False
self
.
_running
=
False
...
@@ -331,6 +317,7 @@ class WebBot:
...
@@ -331,6 +317,7 @@ class WebBot:
raise
raise
def
run
(
self
,
mode
):
def
run
(
self
,
mode
):
status_dict
=
None
if
mode
not
in
[
"crawl"
,
"status"
]:
if
mode
not
in
[
"crawl"
,
"status"
]:
raise
NotImplementedError
(
"Unexpected mode: %s"
%
mode
)
raise
NotImplementedError
(
"Unexpected mode: %s"
%
mode
)
...
@@ -344,13 +331,34 @@ class WebBot:
...
@@ -344,13 +331,34 @@ class WebBot:
if
mode
in
[
"crawl"
,
"all"
]:
if
mode
in
[
"crawl"
,
"all"
]:
self
.
crawl
()
self
.
crawl
()
if
mode
in
[
"status"
,
"all"
]:
if
mode
in
[
"status"
,
"all"
]:
self
.
status
()
s
tatus_dict
=
s
elf
.
status
()
except
:
except
:
self
.
closeDB
()
self
.
closeDB
()
raise
raise
else
:
else
:
self
.
closeDB
()
self
.
closeDB
()
if
status_dict
is
not
None
:
if
self
.
config
[
"FORMAT"
]
==
"json"
:
print
(
json
.
dumps
(
status_dict
))
else
:
for
table_key
in
status_dict
:
print
(
"# %s"
%
table_key
)
print
(
""
)
table
=
status_dict
[
table_key
]
if
table
:
# Print the header
table_key_list
=
[
x
for
x
in
table
[
0
].
keys
()]
table_key_list
.
sort
()
print
(
" | "
.
join
(
table_key_list
))
for
line
in
table
:
print
(
" | "
.
join
(
[
"%s"
%
(
line
[
x
])
for
x
in
table_key_list
]
)
)
print
(
""
)
def
create_bot
(
**
kw
):
def
create_bot
(
**
kw
):
return
WebBot
(
**
kw
)
return
WebBot
(
**
kw
)
tests/test_bot.py
View file @
ebd2504a
...
@@ -530,6 +530,37 @@ class SurykatkaBotTestCase(unittest.TestCase):
...
@@ -530,6 +530,37 @@ class SurykatkaBotTestCase(unittest.TestCase):
checkHttpCodeChange
(
bot
,
[])
checkHttpCodeChange
(
bot
,
[])
def
test_status_emptyConfiguration
(
self
):
resolver_ip
=
"192.168.0.254"
resolver
=
surykatka
.
dns
.
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
with
mock
.
patch
(
"surykatka.configuration.get_default_resolver"
)
as
mock_get_default_resolver
:
mock_get_default_resolver
.
return_value
=
resolver
bot
=
WebBot
(
mapping
=
{
"SQLITE"
:
":memory:"
})
bot
.
initDB
()
result
=
bot
.
status
()
assert
bot
.
_db
.
Status
.
select
().
count
()
==
0
checkNetworkChange
(
bot
,
[])
checkDnsChange
(
bot
,
[])
checkSslChange
(
bot
,
[])
checkHttpCodeChange
(
bot
,
[])
assert
result
==
{
"bot_status"
:
[],
"dns_server"
:
[],
"dns_query"
:
[],
"http_server"
:
[],
"ssl_certificate"
:
[],
"http_query"
:
[],
}
def
suite
():
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
...
...
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