Skip to content

Commit

Permalink
Merge pull request #1 from happer64bit/dev
Browse files Browse the repository at this point in the history
(app): v1.0.3
  • Loading branch information
happer64bit authored Aug 4, 2024
2 parents 03b58d8 + 61d18d7 commit 61a2424
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 24 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/pypi.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish to PyPI

on:
push:
branches:
- dev

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build distribution
run: |
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.PYPI_TEST_TOKEN }}
59 changes: 41 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Hyperscript

**Hyperscript** is a powerful and flexible script for handling complex configurations and requests. It supports various HTTP methods including GET, POST, PUT, and DELETE, and provides extensive options for validating responses against specified conditions.
**Hyperscript** is a tool for testing HTTP requests with flexible configuration and validation.

## Features

- **Support for Multiple HTTP Methods**: Easily configure and test GET, POST, PUT, and DELETE requests.
- **Flexible Validation**: Validate responses based on status codes, content types, and specific body content.
- **Customizable Conditions**: Check if response bodies contain certain values, or if numeric fields are within specified ranges.
- **Detailed Reporting**: Get detailed success and failure messages, with optional verbose output.
- **HTTP Methods**: Test GET, POST, PUT, and DELETE requests.
- **Validation**: Check status codes, content types, and body content.
- **Conditions**: Validate if responses contain specific values or if numeric fields meet criteria.
- **Reporting**: Detailed success and failure messages, with optional verbose output.

## Installation

To install Hyperscript, use pip:
Install with pip:

```bash
pip install hyperscript-cli
```

## Usage
## Configuration

Create a YAML configuration file (`config.yaml`) to specify your tests. Here's an example configuration:
Create a YAML file (`config.yaml`) for your tests. Example:

```yaml
global:
Expand Down Expand Up @@ -51,32 +51,55 @@ run:
color: Silver
```
To run the tests, use the command line:
### Environment Variables
You can use environment variables in your configuration. For example, use `{{VARIABLE_NAME}}` syntax to reference environment variables.

Set environment variables before running your tests:

```bash
hyperscript path/to/config.yaml
export BASE_URL=https://freetestapi.com
export CAR_ID=1
```

### Command Line Options
Update `config.yaml` to use these variables:

```yaml
global:
url: "{{BASE_URL}}"
- `--skip-error`: Skip error handling and continue with the next test.
run:
- name: Get Single Car
path: /api/v1/cars/{{CAR_ID}}
expect:
contentType: application/json
status:
- value: 200
- value: 201
```

### Example
## Usage

Here’s how you can run the tests with verbose output:
Run tests:

```bash
hyperscript path/to/config.yaml --verbose
hyperscript path/to/config.yaml
```

### Options

- `--skip-error`: Continue with the next test on error.
- `--verbose`: Enable detailed logging.

## Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes.
Fork the repository and submit a pull request with your changes.

## License

Hyperscript is released under the MIT License. See the [LICENSE](LICENSE) file for more details.
MIT License. See the [LICENSE](LICENSE) file.

## Contact

For any questions or feedback, please contact [happer64bit@gmail.com](mailto:happer64bit@gmail.com).
For questions, email [happer64bit@gmail.com](mailto:happer64bit@gmail.com).

4 changes: 2 additions & 2 deletions hyperscript_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse
from .parser import parse_config, TestRunner
from .parser import parse_config, Parser
from colorama import Fore

def main():
Expand All @@ -11,7 +11,7 @@ def main():

try:
config = parse_config(args.config_file)
runner = TestRunner(config, args.skip_error, args.verbose)
runner = Parser(config, args.skip_error, args.verbose)
runner.run_test()
runner.show_summary()
except Exception as e:
Expand Down
19 changes: 17 additions & 2 deletions hyperscript_cli/parser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from colorama import Fore, init
import requests
import yaml
import os
import re

init(autoreset=True)

class TestRunner:
class Parser:
def __init__(self, config, skip_error, verbose=False):
self.config = config
self.config = self._process_env_vars(config)
self.skip_error = skip_error
self.verbose = verbose
self.success_count = 0
Expand Down Expand Up @@ -140,6 +142,19 @@ def show_summary(self):
f"{Fore.RED}FAILURE: {self.fail_count}{Fore.RESET}, "
f"{Fore.WHITE}TOTAL: {total_tests}{Fore.RESET}\n")

def _process_env_vars(self, config):
"""Replace placeholders in the config with environment variable values."""
def replace_env_vars(value):
if isinstance(value, str):
return re.sub(r'\{\{(\w+)\}\}', lambda match: os.getenv(match.group(1), match.group(0)), value)
elif isinstance(value, dict):
return {k: replace_env_vars(v) for k, v in value.items()}
elif isinstance(value, list):
return [replace_env_vars(v) for v in value]
return value

return replace_env_vars(config)

def parse_config(config_file):
try:
with open(config_file, 'r') as file:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

setup(
name='hyperscript-cli',
version='1.0.2',
version='1.0.3',
description='Powerful HTTP Request Tester',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
author='Happer',
author_email='happer64bit@gmail.com',
url='https://github.com/happer64bit/hyperscript', # URL to the project repository
url='https://github.com/happer64bit/hyperscript',
packages=find_packages(),
install_requires=[
'requests', # Fixed typo
Expand Down

0 comments on commit 61a2424

Please sign in to comment.