README.md 1.94 KB
Newer Older
Andreas Ellewsen's avatar
Andreas Ellewsen committed
1 2
# cim-client

trond.aasan's avatar
trond.aasan committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
[![pipeline status](https://git.app.uib.no/it-bott-integrasjoner/cim-client/badges/master/pipeline.svg)](https://git.app.uib.no/it-bott-integrasjoner/cim-client/-/commits/master)
[![coverage report](https://git.app.uib.no/it-bott-integrasjoner/cim-client/badges/master/coverage.svg)](https://git.app.uib.no/it-bott-integrasjoner/cim-client/-/commits/master)

## Set up development environment

### Virtual environment

#### Create

```bash
virtualenv --python=python3 venv
```

#### Activate

```bash
source venv/bin/activate
```

### Install dependencies

```bash
pip install -r requirements.txt -r requirements-dev.txt -r requirements-test.txt
```

This should install all dependencies, including development dependencies (code formatter, linters etc).

## Running the tests

### Run all tests

Use [tox](https://tox.readthedocs.io/) to run all tests and linters.

```bash
tox
```

### Run pytest

```bash
python -m pytest
```

### Type check

We use static type checker [mypy](http://mypy-lang.org/).

```bash
python -m mypy -p cim_client
```

## Example

56 57 58
Python client for accessing the CIM-API. 

```python
trond.aasan's avatar
trond.aasan committed
59
from cim_client import CimClient, CimEndpoints
trond.aasan's avatar
trond.aasan committed
60
from cim_client.models import PersonBase, PersonList
trond.aasan's avatar
trond.aasan committed
61
c = CimClient(
62 63 64 65 66 67
    CimEndpoints(
        url='https://example.com',
        upsert_persons_url='/_webservices/?ws=contacts/upsert/1.0',
        delete_persons_url='/_webservices/?ws=contacts/delete/1.0',
    ),
)
68

69 70
upd_schema = c.get_upsert_persons_schema()
del_schema = c.get_delete_persons_schema()
71

trond.aasan's avatar
trond.aasan committed
72
person = PersonBase.from_dict({'username': 'foo', 'firstname': 'John', 'lastname': 'Doe'})
73
response1 = c.upsert_persons(person)
74

trond.aasan's avatar
trond.aasan committed
75
person2 = PersonBase.from_dict({'username': 'bar', 'firstname': 'Petter', 'lastname': 'Smart'})
76 77 78
persons = [person, person2] 
personlist = PersonList(persons=persons)
# Note that delete_person supports both PersonList and [Person, Person, ...]
79 80
response2 = c.upsert_persons(personlist)
response3 = c.delete_persons(person.username)
81
```