Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Dec 1, 2019
1 parent 71c997d commit 546043e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ Or simply do:
update_tld_names()
Note, that this will update all registered TLD source parsers (not only the
list of TLD names taken from Mozilla). In order to update a run the update
for a single parser, specify the ``--parser-uid`` argument.
list of TLD names taken from Mozilla). In order to run the update for a single
parser, append ``uid`` of that parser as argument.
.. code-block:: sh
update-tld-names --parser-uid=mozilla
update-tld-names mozilla
Custom list of TLD names
========================
Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ Or simply do:
update_tld_names()
Note, that this will update all registered TLD source parsers (not only the
list of TLD names taken from Mozilla). In order to update a run the update
for a single parser, specify the ``--parser-uid`` argument.
list of TLD names taken from Mozilla). In order to run the update for a single
parser, append ``uid`` of that parser as argument.
.. code-block:: sh
update-tld-names --parser-uid=mozilla
update-tld-names mozilla
Custom list of TLD names
========================
Expand Down
9 changes: 8 additions & 1 deletion src/tld/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ def setUp(self):
@log_info
def test_1_update_tld_names_command(self):
"""Test updating the tld names (re-fetch mozilla source)."""
res = subprocess.check_output('update-tld-names').strip()
res = subprocess.check_output(['update-tld-names']).strip()
self.assertEqual(res, b'')
return res

@internet_available_only
@log_info
def test_1_update_tld_names_mozilla_command(self):
"""Test updating the tld names (re-fetch mozilla source)."""
res = subprocess.check_output(['update-tld-names', 'mozilla']).strip()
self.assertEqual(res, b'')
return res

if __name__ == '__main__':
unittest.main()
15 changes: 12 additions & 3 deletions src/tld/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import unicode_literals
import argparse
import codecs
import sys
from typing import Dict, Type, Union, Tuple

from urllib.parse import urlsplit, SplitResult
# from urllib.request import urlopen

from .conf import get_setting
from .base import BaseTLDSourceParser
Expand Down Expand Up @@ -157,7 +157,16 @@ def update_tld_names_cli() -> int:
Since update_tld_names returns True on success, we need to negate the
result to match CLI semantics.
"""
return int(not update_tld_names())
parser = argparse.ArgumentParser(description='Update TLD names')
parser.add_argument(
'parser_uid',
nargs='?',
default=None,
help="UID of the parser to update TLD names for.",
)
args = parser.parse_args(sys.argv[1:])
parser_uid = args.parser_uid
return int(not update_tld_names(parser_uid=parser_uid))


def get_tld_names(
Expand Down

0 comments on commit 546043e

Please sign in to comment.