Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
sbws
Commits
7a159324
Commit
7a159324
authored
Jun 01, 2018
by
Matt Traudt
Committed by
Matt Traudt
Jun 02, 2018
Browse files
Add integration tests, reorg tests
parent
636eead7
Changes
16
Hide whitespace changes
Inline
Side-by-side
sbws/util/stem.py
View file @
7a159324
...
...
@@ -83,6 +83,18 @@ def init_controller(port=None, path=None, set_custom_stream_settings=True):
return
c
,
''
def
is_bootstrapped
(
c
):
if
not
is_controller_okay
(
c
):
return
False
line
=
c
.
get_info
(
'status/bootstrap-phase'
)
state
,
_
,
progress
,
*
_
=
line
.
split
()
progress
=
int
(
progress
.
split
(
'='
)[
1
])
if
state
==
'NOTICE'
and
progress
==
100
:
return
True
log
.
debug
(
'Not bootstrapped. state={} progress={}'
.
format
(
state
,
progress
))
return
False
def
is_controller_okay
(
c
):
if
not
c
:
return
False
...
...
tests/integration/__touch__.py
0 → 100644
View file @
7a159324
tests/integration/conftest.py
0 → 100644
View file @
7a159324
import
pytest
from
tempfile
import
TemporaryDirectory
from
sbws.util.parser
import
create_parser
from
sbws.util.config
import
get_config
from
sbws.util.stem
import
launch_tor
import
sbws.core.init
@
pytest
.
fixture
(
scope
=
'session'
)
def
parser
():
return
create_parser
()
@
pytest
.
fixture
(
scope
=
'session'
)
def
persistent_empty_dotsbws
(
parser
):
'''
Creates a ~/.sbws with nothing in it but a config.ini
'''
d
=
TemporaryDirectory
()
args
=
parser
.
parse_args
(
'-d {} --log-level DEBUG init'
.
format
(
d
.
name
).
split
())
conf
=
get_config
(
args
)
sbws
.
core
.
init
.
main
(
args
,
conf
)
return
d
@
pytest
.
fixture
(
scope
=
'session'
)
def
persistent_launch_tor
(
parser
,
persistent_empty_dotsbws
):
d
=
persistent_empty_dotsbws
args
=
parser
.
parse_args
(
'-d {}'
.
format
(
d
.
name
).
split
())
conf
=
get_config
(
args
)
conf
[
'tor'
][
'extra_lines'
]
=
'''
DirAuthority auth1 orport=2002 no-v2 v3ident=D7DBC517EFD2BA1A5012CF1BD0BB38F17C8160BD 127.10.0.1:2003 AA45C13025C037F056E734169891878ED0880231
DirAuthority auth2 orport=2002 no-v2 v3ident=4EE103A081F400E6622F5461D51782B876BB5C24 127.10.0.2:2003 E7B3C9A0040D628DAC88B0251AE6334D28E8F531
DirAuthority auth3 orport=2002 no-v2 v3ident=8B85069C7FC0593801E6491A34100264FCE28980 127.10.0.3:2003 35E3B8BB71C81355649AEC5862ECB7ED7EFDBC5C
TestingTorNetwork 1
NumCPUs 1
LogTimeGranularity 1
SafeLogging 0
'''
cont
=
launch_tor
(
conf
)
return
cont
tests/integration/test_stem.py
0 → 100644
View file @
7a159324
import
sbws.util.stem
as
stem_utils
from
stem.descriptor.router_status_entry
import
RouterStatusEntryV3
def
test_foo
(
persistent_launch_tor
):
cont
=
persistent_launch_tor
assert
stem_utils
.
is_controller_okay
(
cont
)
assert
stem_utils
.
is_bootstrapped
(
cont
)
def
test_get_relay_from_fp
(
persistent_launch_tor
):
cont
=
persistent_launch_tor
# AA45C13025C037F056E734169891878ED0880231 is auth1
relay
=
stem_utils
.
fp_or_nick_to_relay
(
cont
,
'AA45C13025C037F056E734169891878ED0880231'
)
assert
isinstance
(
relay
,
RouterStatusEntryV3
)
assert
relay
.
fingerprint
==
'AA45C13025C037F056E734169891878ED0880231'
assert
relay
.
nickname
==
'auth1'
def
test_get_relay_from_nick
(
persistent_launch_tor
):
cont
=
persistent_launch_tor
# AA45C13025C037F056E734169891878ED0880231 is auth1
relay
=
stem_utils
.
fp_or_nick_to_relay
(
cont
,
'auth1'
)
assert
isinstance
(
relay
,
RouterStatusEntryV3
)
assert
relay
.
fingerprint
==
'AA45C13025C037F056E734169891878ED0880231'
assert
relay
.
nickname
==
'auth1'
tests/testnets/reproducible.tar
0 → 100644
View file @
7a159324
File added
tests/unit/__init__.py
0 → 100644
View file @
7a159324
tests/conftest.py
→
tests/
unit/
conftest.py
View file @
7a159324
File moved
tests/core/test_cleanup.py
→
tests/
unit/
core/test_cleanup.py
View file @
7a159324
from
sbws.util.config
import
get_config
from
sbws.globals
import
touch_file
import
sbws.core.cleanup
from
tests.globals
import
monotonic_time
from
tests.
unit.
globals
import
monotonic_time
from
unittest.mock
import
patch
import
logging
import
os
...
...
tests/core/test_generate.py
→
tests/
unit/
core/test_generate.py
View file @
7a159324
File moved
tests/core/test_stats.py
→
tests/
unit/
core/test_stats.py
View file @
7a159324
...
...
@@ -6,7 +6,7 @@ from sbws.lib.resultdump import Result
from
sbws.lib.resultdump
import
write_result_to_datadir
import
sbws.core.init
import
sbws.core.stats
from
tests.globals
import
monotonic_time
from
tests.
unit.
globals
import
monotonic_time
from
unittest.mock
import
patch
from
datetime
import
datetime
import
os
...
...
tests/globals.py
→
tests/
unit/
globals.py
View file @
7a159324
File moved
tests/lib/test_results.py
→
tests/
unit/
lib/test_results.py
View file @
7a159324
...
...
@@ -7,7 +7,7 @@ from sbws.lib.resultdump import ResultErrorAuth
from
sbws.lib.resultdump
import
ResultErrorCircuit
from
sbws.lib.resultdump
import
ResultErrorStream
from
sbws.lib.resultdump
import
_ResultType
from
tests.globals
import
monotonic_time
from
tests.
unit.
globals
import
monotonic_time
@
patch
(
'time.time'
)
...
...
tests/lib/test_v3bwfile.py
→
tests/
unit/
lib/test_v3bwfile.py
View file @
7a159324
File moved
tests/util/test_config.py
→
tests/
unit/
util/test_config.py
View file @
7a159324
File moved
tests/util/test_userquery.py
→
tests/
unit/
util/test_userquery.py
View file @
7a159324
File moved
tox.ini
View file @
7a159324
[tox]
skip_missing_interpreters
=
True
envlist
=
clean, lint, py34, py35, py36, stats
envlist
=
clean, lint, py34, py35, py36, stats
, integration
[travis]
python
=
3.4:
lint,
py34
3.4:
lint,
py34,
integration
3.5:
py35,
integration
3.6:
py36,
integration
[testenv:clean]
skip_install
=
True
...
...
@@ -14,6 +16,24 @@ deps =
commands
=
coverage
erase
[testenv:integration]
ignore_errors
=
True
deps
=
.[test]
whitelist_externals
=
rm
tar
time
bash
sleep
changedir
=
{toxinidir}/tests/testnets
commands
=
rm
-vrf
reproducible
tar
vxf
reproducible.tar
bash
./reproducible/start.sh
time
bash
-c
"python3
./reproducible/wait.py
./reproducible/{auth,relay,exit}*"
coverage
run
--rcfile
=
{toxinidir}/.coveragerc --source=sbws -m pytest -s {toxinidir}/tests/integration -vv
bash
./reproducible/stop.sh
[testenv:lint]
skip_install
=
True
deps
=
.[dev]
...
...
@@ -36,7 +56,7 @@ install_command =
pip
install
--process-dependency-links
{opts}
{packages}
deps
=
.[test]
commands
=
coverage
run
--rcfile
=
{toxinidir}/.coveragerc --source=sbws -m pytest -s {toxinidir}/tests -vv
coverage
run
--rcfile
=
{toxinidir}/.coveragerc --source=sbws -m pytest -s {toxinidir}/tests
/unit
-vv
passenv
=
TRAVIS
TRAVIS_JOB_ID
...
...
Write
Preview
Supports
Markdown
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