WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions miraheze/mediawiki/mwimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def parse_args(input_args: list | None = None, check_paths: bool = True) -> argp
parser.add_argument('wiki', help='Database name of the wiki to import to')

args = parser.parse_args(input_args)
if not args.wiki.endswith('wiki') and not args.wiki.endswith('wikibeta'):
raise ValueError('<wiki> must be a proper database name')

if not args.xml and not args.images:
raise ValueError('--xml and/or --images must be passed')
if args.images and not args.images_comment:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_mwimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ def test_parse_args_username_prefix():
assert args.username_prefix == 'w'


def test_parse_args_beta_database_name():
args = mwimport.parse_args([
'--xml=dump.xml',
'examplewikibeta',
], False)
assert args.wiki == 'examplewikibeta'


def test_parse_args_invalid_database_name():
with pytest.raises(ValueError, match='<wiki> must be a proper database name'):
mwimport.parse_args([
'--xml=dump.xml',
'example',
])


def test_parse_args_need_xml_or_images():
with pytest.raises(ValueError, match='--xml and/or --images must be passed'):
mwimport.parse_args([
Expand Down