Metadata-Version: 2.1
Name: fild-api-hub
Version: 0.0.5
Summary: Library to operate api with help of fild contracts
Home-page: https://github.com/elenakulgavaya/fild-api-hub
Author: Elena Kulgavaya
Author-email: elena.kulgavaya@gmail.com
Project-URL: Bug Tracker, https://github.com/elenakulgavaya/fild-api-hub/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: deepdiff>=6.5.1
Requires-Dist: fild>=0.0.9
Requires-Dist: requests>=2.31.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: waiting>=1.4.1

# fild-api-hub

The FILD Api Hub is a set of tools enabling using FILD described contracts
in tests. 

Configure your project with yaml files in `etc/config.yaml` containing
```yaml
App:
  url: http://localhost:8000
MockServer:
  host: localhost
  port: 8088
```

Override any local configuration variables by adding `etc/local.yaml`
```yaml
MockServer:
  port: 8080
```

Use `ApiMethod` to describe the API 
```python
from fild.sdk import Dictionary, Int, String, Uuid
from fildapi import ApiMethod, HttpMethod


SERVICE = 'customer_api'
BASE_URL = 'http://mydomain.customerapi'


class CreateUserRequest(Dictionary):
    Name = String(name='name')
    Email = String(name='email')
    Age = Int(name='age', min_val=18, max_val=120)

    
class CreateUserResponse(Dictionary):
    Id = Uuid(name='id')

    
class CreateUser(ApiMethod):
    method = HttpMethod.POST
    url = 'api/users'
    req_body = CreateUserRequest
    resp_body = CreateUserResponse
```

Use `ApiMethod` for mocking and verifying integrations
```python
from customer_api import CreateUser


def test_failed_to_create_user():
    CreateUser.reply(status=400)
    # Test action to check error


def test_verify_call_to_customer_api():
    CreateUser.reply()
    # Some test action
    CreateUser.verify_called()
```

Use `ApiCaller` to test the api:
```python
from fildapi import ApiCaller
from customer_api import CreateUser


class CreateUserCall(ApiCaller):
    method = CreateUser


def test_create_user():
    CreateUserCall().request().verify_response()
```
