|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +import pytest |
| 4 | +from click import BadParameter, BadOptionUsage |
| 5 | +from typer.testing import CliRunner |
| 6 | + |
| 7 | +from fastapi_ccli.cloner.cloner_en import app_en |
| 8 | + |
| 9 | +runner = CliRunner() |
| 10 | + |
| 11 | + |
| 12 | +def test_en_version(): |
| 13 | + """ |
| 14 | + test cloner en version |
| 15 | + """ |
| 16 | + result = runner.invoke(app_en, ["--version"]) |
| 17 | + assert "FastAPI CCLI" in result.output |
| 18 | + assert result.exit_code == 0 |
| 19 | + result = runner.invoke(app_en, ["-V"]) |
| 20 | + assert "FastAPI CCLI" in result.output |
| 21 | + assert result.exit_code == 0 |
| 22 | + |
| 23 | + |
| 24 | +def test_en_orm_sqlalchemy(): |
| 25 | + """ |
| 26 | + test cloner en orm sqlalchemy |
| 27 | + """ |
| 28 | + result = runner.invoke(app_en, ["--orm", "sqlalchemy"]) |
| 29 | + assert result.output == "" |
| 30 | + assert result.exit_code == 0 |
| 31 | + |
| 32 | + |
| 33 | +def test_en_orm_tortoise(): |
| 34 | + """ |
| 35 | + test cloner en orm tortoise |
| 36 | + """ |
| 37 | + result = runner.invoke(app_en, ["--orm", "tortoise"]) |
| 38 | + assert result.output == "" |
| 39 | + assert result.exit_code == 0 |
| 40 | + |
| 41 | + |
| 42 | +def test_en_orm_sqlmodel(): |
| 43 | + """ |
| 44 | + test cloner en orm sqlmodel |
| 45 | + """ |
| 46 | + result = runner.invoke(app_en, ["--orm", "sqlmodel"]) |
| 47 | + assert result.output == "" |
| 48 | + assert result.exit_code == 0 |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.skip("Unknown reasons, invoke was unable to catch the exception") |
| 52 | +def test_en_orm_illegal_value(): |
| 53 | + """ |
| 54 | + test cloner en orm illegal value |
| 55 | + """ |
| 56 | + with pytest.raises(BadParameter) as exc_info: |
| 57 | + runner.invoke(app_en, ["--orm", "none"], catch_exceptions=False) |
| 58 | + assert exc_info.value.exit_code == 2 |
| 59 | + assert ( |
| 60 | + exc_info.value.message |
| 61 | + == "Invalid value: Enter unknown parameters, only allowed 'sqlalchemy' / 'tortoise' / 'sqlmodel'" |
| 62 | + ) |
| 63 | + |
| 64 | + |
| 65 | +@pytest.mark.skip("Unknown reasons, invoke was unable to catch the exception") |
| 66 | +def test_en_orm_no_argument(): |
| 67 | + """ |
| 68 | + test cloner en orm no argument |
| 69 | + """ |
| 70 | + with pytest.raises(BadOptionUsage) as exc_info: |
| 71 | + runner.invoke(app_en, ["--orm"], catch_exceptions=False) |
| 72 | + assert exc_info.value.exit_code == 2 |
| 73 | + assert exc_info.value.message == "Option '--orm' requires an argument." |
| 74 | + |
| 75 | + |
| 76 | +@pytest.mark.skip("Unknown reasons, invoke was unable to catch the exception") |
| 77 | +def test_en_project_path(): |
| 78 | + """ |
| 79 | + test cloner en project path |
| 80 | + """ |
| 81 | + with pytest.raises(BadParameter) as exc_info: |
| 82 | + runner.invoke(app_en, ["--path", "100"], catch_exceptions=False) |
| 83 | + assert exc_info.value.exit_code == 2 |
| 84 | + assert exc_info.value.message == "Invalid value: Wrong parameter input, please enter the correct path" |
0 commit comments