Add CLI source code and update .gitignore
This commit is contained in:
232
cli_anything/codimd/tests/TEST.md
Normal file
232
cli_anything/codimd/tests/TEST.md
Normal file
@@ -0,0 +1,232 @@
|
||||
# CodiMD CLI - Test Plan and Results
|
||||
|
||||
## Test Plan
|
||||
|
||||
### Unit Tests (`test_core.py`)
|
||||
|
||||
#### Config Tests
|
||||
- Test default configuration values
|
||||
- Test configuration persistence
|
||||
- Test configuration updates (server, timeout, verify_ssl)
|
||||
|
||||
#### Session Tests
|
||||
- Test session creation
|
||||
- Test cookie storage and retrieval
|
||||
- Test user data storage
|
||||
- Test session expiration
|
||||
- Test session clearing
|
||||
|
||||
#### Client Tests
|
||||
- Test URL building
|
||||
- Test HTTP methods (GET, POST, PUT, DELETE)
|
||||
- Test cookie management
|
||||
- Test SSL verification setting
|
||||
|
||||
#### Note Manager Tests
|
||||
- Test note ID encoding/decoding (UUID to base64url)
|
||||
- Test note list parsing
|
||||
- Test note creation request formatting
|
||||
- Test note update request formatting
|
||||
|
||||
#### Export Manager Tests
|
||||
- Test markdown export
|
||||
- Test export with file output
|
||||
- Test error handling for unauthorized exports
|
||||
|
||||
### E2E Tests (`test_full_e2e.py`)
|
||||
|
||||
#### Configuration Tests
|
||||
- Test CLI configuration with `--server` flag
|
||||
- Test JSON output mode with `--json` flag
|
||||
|
||||
#### Note Command Tests
|
||||
- Test `note list` command
|
||||
- Test `note create` command
|
||||
- Test `note get` command
|
||||
- Test `note info` command
|
||||
|
||||
#### Export Command Tests
|
||||
- Test `export markdown` command
|
||||
- Test `export html` command
|
||||
|
||||
#### User Command Tests
|
||||
- Test `user me` command
|
||||
- Test `user logout` command
|
||||
|
||||
### Subprocess Tests
|
||||
- Test installed CLI via `_resolve_cli()` method
|
||||
- Test with `CLI_ANYTHING_FORCE_INSTALLED=1` environment variable
|
||||
- Verify CLI is available in PATH
|
||||
|
||||
## Test Requirements
|
||||
|
||||
- Python 3.7+
|
||||
- pytest for test execution
|
||||
- requests-mock for HTTP mocking
|
||||
- pytest-subprocess for subprocess testing
|
||||
|
||||
## Mock Data
|
||||
|
||||
### Mock User
|
||||
```json
|
||||
{
|
||||
"id": "12345678-1234-1234-1234-123456789012",
|
||||
"profile": {
|
||||
"name": "Test User",
|
||||
"email": "test@example.com"
|
||||
},
|
||||
"email": "test@example.com"
|
||||
}
|
||||
```
|
||||
|
||||
### Mock Note List
|
||||
```json
|
||||
{
|
||||
"myNotes": [
|
||||
{
|
||||
"id": "VXDECB3HEXDPHWHGHFDGWEDFBM",
|
||||
"text": "Test Note 1",
|
||||
"shortId": "abc123",
|
||||
"createdAt": "2024-01-01T00:00:00.000Z",
|
||||
"lastchangeAt": "2024-01-01T01:00:00.000Z",
|
||||
"tags": ["test"]
|
||||
},
|
||||
{
|
||||
"id": "YTECB3HEXDPHWHGHFDGWEDFBZ",
|
||||
"text": "Test Note 2",
|
||||
"shortId": "def456",
|
||||
"createdAt": "2024-01-02T00:00:00.000Z",
|
||||
"lastchangeAt": "2024-01-02T01:00:00.000Z",
|
||||
"tags": []
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Test Execution
|
||||
|
||||
Run all tests:
|
||||
```bash
|
||||
pytest -v --tb=no
|
||||
```
|
||||
|
||||
Run only unit tests:
|
||||
```bash
|
||||
pytest test_core.py -v
|
||||
```
|
||||
|
||||
Run only E2E tests:
|
||||
```bash
|
||||
pytest test_full_e2e.py -v
|
||||
```
|
||||
|
||||
## Test Results
|
||||
|
||||
### Test Execution Summary
|
||||
|
||||
```
|
||||
============================= test session starts ==============================
|
||||
platform darwin -- Python 3.12.2, pytest-9.0.2, pluggy-1.6.0
|
||||
collected 46 items
|
||||
|
||||
cli_anything/codimd/tests/test_core.py::TestConfig::test_default_config PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestConfig::test_config_persistence PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestConfig::test_set_server PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestConfig::test_set_timeout PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestConfig::test_set_verify_ssl PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestSession::test_session_creation PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestSession::test_set_cookies PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestSession::test_set_user PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestSession::test_session_clear PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestCodiMDClient::test_url_building PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestCodiMDClient::test_url_trailing_slash PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestCodiMDClient::test_session_cookies PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestCodiMDClient::test_update_cookies PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestCodiMDClient::test_ssl_setting PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestNoteManager::test_encode_note_id PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestNoteManager::test_decode_note_id PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestNoteManager::test_encode_decode_roundtrip PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestNoteManager::test_list_notes_success PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestNoteManager::test_list_notes_unauthorized PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestNoteManager::test_create_note_with_content PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestNoteManager::test_delete_note_success PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestUserManager::test_get_me_success PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestUserManager::test_get_me_unauthorized PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestUserManager::test_export_data_success PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestExportManager::test_export_markdown_success PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestExportManager::test_export_markdown_to_file PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestExportManager::test_export_markdown_not_found PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestExportManager::test_export_pdf_disabled PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestRevisionManager::test_list_revisions_success PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestRevisionManager::test_list_revisions_empty PASSED
|
||||
cli_anything/codimd/tests/test_core.py::TestRevisionManager::test_get_revision_at_time PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestCLISubprocess::test_cli_help PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestCLISubprocess::test_cli_version PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_config_get_command PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_config_set_command PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_help_command PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_version_command PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_note_help PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_user_help PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_export_help PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EClickRunner::test_json_output_mode PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2ENoteCommands::test_note_list_authenticated PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2ENoteCommands::test_note_create PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EExportCommands::test_export_markdown_to_file PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EUserCommands::test_user_logout PASSED
|
||||
cli_anything/codimd/tests/test_full_e2e.py::TestE2EUserCommands::test_user_me_unauthenticated PASSED
|
||||
|
||||
============================== 46 passed in 0.66s ==============================
|
||||
```
|
||||
|
||||
### Test Coverage Summary
|
||||
|
||||
- **Total Tests**: 46
|
||||
- **Passed**: 46 (100%)
|
||||
- **Failed**: 0
|
||||
|
||||
#### Unit Tests (test_core.py)
|
||||
- Config: 5/5 passed
|
||||
- Session: 4/4 passed
|
||||
- Client: 5/5 passed
|
||||
- Note Manager: 6/6 passed
|
||||
- User Manager: 3/3 passed
|
||||
- Export Manager: 4/4 passed
|
||||
- Revision Manager: 3/3 passed
|
||||
|
||||
#### E2E Tests (test_full_e2e.py)
|
||||
- Subprocess tests: 2/2 passed
|
||||
- Click Runner tests: 8/8 passed
|
||||
- Note Commands: 2/2 passed
|
||||
- Export Commands: 1/1 passed
|
||||
- User Commands: 2/2 passed
|
||||
|
||||
### CLI Verification
|
||||
|
||||
```bash
|
||||
$ which cli-anything-codimd
|
||||
/Users/timmy/.pyenv/versions/3.12.2/bin/cli-anything-codimd
|
||||
|
||||
$ cli-anything-codimd --version
|
||||
CodiMD CLI v0.1.0
|
||||
|
||||
$ cli-anything-codimd --help
|
||||
Usage: cli-anything-codimd [OPTIONS] COMMAND [ARGS]...
|
||||
|
||||
CodiMD CLI - Collaborative markdown notes.
|
||||
|
||||
Options:
|
||||
--version Show version and exit.
|
||||
--json Output in JSON format
|
||||
--server TEXT CodiMD server URL
|
||||
--help Show this message and exit.
|
||||
|
||||
Commands:
|
||||
config Configuration commands.
|
||||
export Export operations.
|
||||
note Note operations.
|
||||
registry Registry operations.
|
||||
repl Start interactive REPL mode.
|
||||
revision Revision operations.
|
||||
user User operations.
|
||||
```
|
||||
Reference in New Issue
Block a user