-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added docs and test for check_url_file()
- Loading branch information
1 parent
7f1c53f
commit 2c57f59
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
from source_app.utils import check_url_file | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
def test_check_url_file(config): | ||
|
||
assert check_url_file("nosuchfile", "whatever") is None | ||
|
||
try: | ||
def write_url_file(path, content): | ||
url_file = open(path, "w") | ||
url_file.write("{}\n".format(content)) | ||
|
||
url_path = "test_source_url" | ||
|
||
onion_test_url = "abcdabcdabcdabcd.onion" | ||
write_url_file(url_path, onion_test_url) | ||
assert check_url_file(url_path, r"^[a-z0-9]{16}\.onion$") == onion_test_url | ||
|
||
onion_test_url = "abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh.onion" | ||
write_url_file(url_path, onion_test_url) | ||
assert check_url_file(url_path, r"^[a-z0-9]{56}\.onion$") == onion_test_url | ||
|
||
write_url_file(url_path, "NO.onion") | ||
assert check_url_file(url_path, r"^[a-z0-9]{56}\.onion$") is None | ||
finally: | ||
if os.path.exists(url_path): | ||
os.unlink(url_path) |