-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
127 additions
and
23 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
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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import os | ||
import sys | ||
from app.utils import ( | ||
parser, Shortener, | ||
URLExistsError, URLNotFoundError | ||
) | ||
from app.db import DB_PATH, init_db | ||
|
||
|
||
|
||
from app.utils import parser | ||
def main(): | ||
if not os.path.exists(DB_PATH): | ||
init_db(DB_PATH) | ||
args = parser().parse_args() | ||
print(args) | ||
if not args.generate: | ||
try: | ||
Shortener.get_long_url(args.url) | ||
except URLNotFoundError: | ||
print("URL does not exists", file=sys.stderr) | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = parser() | ||
args = parser.parse_args() | ||
print(args) | ||
main() |
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
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,29 @@ | ||
from main import main | ||
from pytest_mock import mocker | ||
import pytest | ||
from argparse import Namespace | ||
from test_db import script | ||
from unittest import mock | ||
from app.db import get_db, close_db, init_db | ||
from argparse import ArgumentParser | ||
import re | ||
|
||
|
||
|
||
def test_main_noparams(db_path, mocker): | ||
mocker.patch('main.DB_PATH', db_path) | ||
with pytest.raises(SystemExit): | ||
main() | ||
|
||
def test_main_short_url(db_path, argparser, mocker, capsys): | ||
mocker.patch('main.DB_PATH', db_path) | ||
init_db(db_path=db_path) | ||
with mock.patch('app.db.DB_PATH', db_path): | ||
db = get_db() | ||
db.executescript(script) | ||
args = argparser.parse_args(['on.ln']) | ||
parser = mocker.patch('argparse.ArgumentParser.parse_args', return_value=args) | ||
main() | ||
captured = capsys.readouterr() | ||
print(captured) | ||
assert 'URL does not exists\n' == captured.err |
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