Skip to content

Commit

Permalink
Created first test
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoLuka committed Aug 8, 2023
1 parent 3fc9e91 commit d7fe2c5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
__pycache__
venv
venv
.pytest_cache
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ An API that turns your shell into a powerful and customisable backend with just
- 1 CPU core (depending on the programs that are called)

### Usage
To start the program just type `python cliserver.py /path/to/config/file.json`
To start the program, run `python cliserver.py /path/to/config/file.json`

To start the program using docker, run `docker run -p 9999:9999 -v /path/to/config/file.json:/config.json ghcr.io/NekoLuka/CliServer:main`
To start the program using docker, run `docker run -p 9999:9999 -v /path/to/config/file.json:/config.json ghcr.io/nekoluka/cliserver:main`

### Configuration

Expand Down Expand Up @@ -84,6 +84,9 @@ The first command is equal to `echo {message} | base64`.
- type (string): A string literal that identifies to use the 'text' field to generate output for the code (required).
- text (str): The text that is put in the response body (required).

## Testing
To run all tests, run `python tests.py`

## Roadmap

- Put the program into a docker image.
Expand All @@ -93,3 +96,4 @@ The first command is equal to `echo {message} | base64`.
- Sanitize input to prevent command injections.
- Add possible authentication to endpoints
- Add testing cases
- Add ctrl+C exit functionality
Binary file modified requirements.txt
Binary file not shown.
3 changes: 3 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.main()
22 changes: 22 additions & 0 deletions tests/test_backward_compatibility_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from configParser import Config


def test_backwards_compatibility_routes():
config = {"/hello": {"commands": [{"command": "echo hello world"}]}}
response = Config()._parse_command(config)
route_body = response.get("/hello")

assert route_body is not None, "No route body found in output"
assert type(route_body["method"]) is str, "method should be str"
assert type(route_body["params"]) is list, "params should be a list"
assert type(route_body["return_stdout"]) is bool, "return_stdout should be a bool"
assert type(route_body["commands"]) is list, "commands should be a list"

command_body = route_body["commands"][0]

assert command_body is not None, "Command body should not be empty"
assert type(command_body["command"]) is str, "command should be str"
assert type(command_body["stdin"]) is str or command_body["stdin"] is None, "stdin should be a str"
assert type(command_body["pipe_to_stdin"]) is bool, "pipe_to_stdin should be str"
assert type(command_body["expected_return_code"]) is int, "expected_return_code should be int"
assert type(command_body["return_stderr_on_error"]) is bool, "return_stderr_on_error should be bool"

0 comments on commit d7fe2c5

Please sign in to comment.