Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
3b50bb10
Commit
3b50bb10
authored
Dec 14, 2012
by
JINMEI Tatuya
Browse files
[2380] test run()
parent
9e2d7b9b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/bin/loadzone/loadzone.py.in
View file @
3b50bb10
...
...
@@ -55,7 +55,9 @@ the zone in. Example:
help="RR class of the zone; currently must be 'IN'")
class LoadZoneRunner:
'''TBD
'''Main logic for the loadzone.
This is implemented as a class mainly for the convenience of tests.
'''
def __init__(self, command_args):
...
...
@@ -146,12 +148,15 @@ class LoadZoneRunner:
try:
self._parse_args()
self._do_load()
return 0
except BadArgument as ex:
logger.error(LOADZONE_ARGUMENT_ERROR, ex)
except LoadFailure as ex:
logger.error(LOADZONE_LOAD_ERROR, self._zone_name,
self._zone_class, ex)
return 0
except Exception as ex:
logger.error(LOADZONE_UNEXPECTED_FAILURE, ex)
return 1
if '__main__' == __name__:
runner = LoadZoneRunner(sys.argv[1:])
...
...
src/bin/loadzone/loadzone_messages.mes
View file @
3b50bb10
...
...
@@ -23,3 +23,5 @@
% LOADZONE_LOAD_ERROR Failed to load zone %1/%2: %3
% LOADZONE_CANCEL_CREATE_ZONE Creation of new zone %1/%2 was canceled
% LOADZONE_UNEXPECTED_FAILURE Unexpected exception: ex
src/bin/loadzone/tests/loadzone_test.py
View file @
3b50bb10
...
...
@@ -49,7 +49,7 @@ class TestLoadZoneRunner(unittest.TestCase):
shutil
.
copyfile
(
READ_ZONE_DB_FILE
,
WRITE_ZONE_DB_FILE
)
# default command line arguments
self
.
__args
=
[
'-c'
,
DATASRC_CONFIG
,
'example.org'
,
'example.zone'
]
self
.
__args
=
[
'-c'
,
DATASRC_CONFIG
,
'example.org'
,
NEW_ZONE_TXT_FILE
]
self
.
__runner
=
LoadZoneRunner
(
self
.
__args
)
def
tearDown
(
self
):
...
...
@@ -69,7 +69,7 @@ class TestLoadZoneRunner(unittest.TestCase):
def
test_parse_args
(
self
):
self
.
__runner
.
_parse_args
()
self
.
assertEqual
(
TEST_ZONE_NAME
,
self
.
__runner
.
_zone_name
)
self
.
assertEqual
(
'example.zone'
,
self
.
__runner
.
_zone_file
)
self
.
assertEqual
(
NEW_ZONE_TXT_FILE
,
self
.
__runner
.
_zone_file
)
self
.
assertEqual
(
DATASRC_CONFIG
,
self
.
__runner
.
_datasrc_config
)
self
.
assertEqual
(
'sqlite3'
,
self
.
__runner
.
_datasrc_type
)
# default
self
.
assertEqual
(
RRClass
.
IN
(),
self
.
__runner
.
_zone_class
)
# default
...
...
@@ -178,6 +178,31 @@ class TestLoadZoneRunner(unittest.TestCase):
# _do_load() should have once created the zone but then canceled it.
self
.
__check_zone_soa
(
None
,
zone_name
=
Name
(
'example.com'
))
def
test_run_success
(
self
):
'''Check for the top-level method.
Detailed behavior is tested in other tests. We only check the
return value of run(), and the zone is successfully loaded.
'''
self
.
__check_zone_soa
(
ORIG_SOA_TXT
)
self
.
assertEqual
(
0
,
self
.
__runner
.
run
())
self
.
__check_zone_soa
(
NEW_SOA_TXT
)
def
test_run_fail
(
self
):
'''Check for the top-level method, failure case.
Similar to the success test, but loading will fail, and return
value should be 1.
'''
runner
=
LoadZoneRunner
([
'-c'
,
DATASRC_CONFIG
,
'example.org'
,
LOCAL_TESTDATA_PATH
+
'/broken-example.org.zone'
])
self
.
__check_zone_soa
(
ORIG_SOA_TXT
)
self
.
assertEqual
(
1
,
runner
.
run
())
self
.
__check_zone_soa
(
ORIG_SOA_TXT
)
if
__name__
==
"__main__"
:
isc
.
log
.
resetUnitTestRootLogger
()
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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