-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: read FAVORS_HOME from env, config save to FAVORS_HOME, defa…
…ult FAVORS_HOME is ~/.favorites_crawler
- Loading branch information
Showing
4 changed files
with
64 additions
and
20 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
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,39 @@ | ||
from typer.testing import CliRunner | ||
|
||
from favorites_crawler.commands.login import app | ||
from favorites_crawler.utils.config import load_config | ||
|
||
runner = CliRunner() | ||
|
||
|
||
class TestLoginNhentai: | ||
def test_login_nhentai_success(self, tmp_path): | ||
favors_home = tmp_path / 'home' | ||
cookie = tmp_path / 'cookie.txt' | ||
cookie.touch() | ||
user_agent = 'Test-User-Agent' | ||
|
||
result = runner.invoke( | ||
app, ['nhentai', '-c', str(cookie), '-u', user_agent], | ||
env={'FAVORS_HOME': str(favors_home)} | ||
) | ||
|
||
assert result.exit_code == 0 | ||
assert "success" in result.stdout | ||
assert (favors_home / 'cookie.txt').exists() | ||
assert (favors_home / 'config.yml').exists() | ||
config = load_config(favors_home) | ||
assert config['nhentai']['USER_AGENT'] == user_agent | ||
|
||
def test_login_nhentai_failed(self, tmp_path): | ||
favors_home = tmp_path / 'home' | ||
cookie = tmp_path / 'cookie.txt' | ||
user_agent = 'Test-User-Agent' | ||
|
||
result = runner.invoke( | ||
app, ['nhentai', '-c', str(cookie), '-u', user_agent], | ||
env={'FAVORS_HOME': str(favors_home)} | ||
) | ||
|
||
assert result.exit_code == 1 | ||
assert "Failed" in result.stdout |