Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
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
zhifan huang
re6stnet
Commits
afa77741
Commit
afa77741
authored
May 05, 2022
by
zhifan huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add registry.getBootstrap
parent
1aa76589
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
3 deletions
+47
-3
re6st/tests/test_unit/test_registry.py
re6st/tests/test_unit/test_registry.py
+47
-3
No files found.
re6st/tests/test_unit/test_registry.py
View file @
afa77741
...
...
@@ -17,9 +17,9 @@ from re6st import registry
from
re6st
import
ctl
from
re6st.tests.tools
import
*
# TODO test for request_dump, requestToken, getNetworkConfig, getBoostrapPeer
# getIPV4Information
# TODO test for request_dump, requestToken, getNetworkConfig, getIPv6Address
# getIPV4Information seems useless
def
load_config
(
filename
=
"registry.json"
):
with
open
(
filename
)
as
f
:
...
...
@@ -53,7 +53,10 @@ def select_side_effect(rlist, wlist, elist, timeout):
select_side_effect
.
i
=
0
# TODO function for get a unique prefix
def
new_prefix
(
length
=
16
):
new_prefix
.
i
+=
1
return
format
(
new_prefix
.
i
,
"0%ib"
%
length
)
new_prefix
.
i
=
0
class
TestRegistryServer
(
unittest
.
TestCase
):
@
classmethod
...
...
@@ -337,6 +340,47 @@ class TestRegistryServer(unittest.TestCase):
self
.
assertEqual
(
res
,
"other msg"
)
@
patch
(
"re6st.registry.RegistryServer._queryAddress"
)
@
patch
(
"re6st.registry.RegistryServer.request_dump"
,
Mock
())
def
test_getBootstrapPeer
(
self
,
query
):
"""call request dump situation"""
assert
hasattr
(
self
.
server
,
"peers"
)
peers_back
=
self
.
server
.
peers
self
.
server
.
peers
=
0
,
None
cn
=
new_prefix
()
pkey
,
_
=
insert_cert
(
self
.
server
.
db
,
self
.
server
.
cert
,
cn
)
self
.
server
.
sessions
[
cn
]
=
[(
0
,
7
)]
query
.
return_value
=
expect_msg
=
"address"
self
.
server
.
ctl
.
neighbours
=
neigh
=
{}
# peers while looke like [0, 1, 2, 3, 4], have 5 peer
for
i
in
1
,
2
,
3
,
4
:
neigh
[
i
]
=
(
i
,
{
format
(
i
,
"016b"
):
i
})
msg
=
self
.
server
.
getBootstrapPeer
(
cn
)
msg
=
decrypt
(
pkey
,
msg
)
peer
,
msg
=
msg
.
split
()
self
.
assertEqual
(
msg
,
expect_msg
)
self
.
assertNotIn
(
peer
,
self
.
server
.
peers
)
self
.
assertEqual
(
len
(
self
.
server
.
peers
[
1
]),
4
)
self
.
peers
=
peers_back
@
patch
(
"re6st.registry.RegistryServer._queryAddress"
)
def
test_getBoostgetBootstrapPeer_not_dump
(
self
,
query
):
"""skip the request dump situation, and msg is None"""
assert
hasattr
(
self
.
server
,
"peers"
)
peers_back
=
self
.
server
.
peers
self
.
server
.
peers
=
time
.
time
()
+
60
,
[
self
.
server
.
prefix
]
cn
=
new_prefix
()
query
.
return_value
=
None
res
=
self
.
server
.
getBootstrapPeer
(
cn
)
self
.
assertIsNone
(
res
)
query
.
assert_called_once_with
(
self
.
server
.
prefix
)
self
.
peers
=
peers_back
@
patch
(
're6st.registry.RegistryServer.updateNetworkConfig'
)
def
test_revoke
(
self
,
mock_func
):
# case: no ValueError
...
...
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