# XiVO confd

XiVO CONFD is a web server that provides a [RESTful](http://en.wikipedia.org/wiki/Representational_state_transfer)
service for configuring and managing a XiVO server.


## Installing xivo-confd

The server is already provided as a part of [XiVO](http://documentation.xivo.solutions).
Please refer to [the documentation](https://documentation.xivo.solutions/en/stable/xivo/installation/installation.html) for
further details on installing one.


## Running unit tests


1. Run the latest version of the debian-builder container mounting the project directories (HOME by default)
``` 
docker run --rm -it --user "`id -u`:`id -g`" \
 -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro \
 -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:rw \
 -v /etc/shadow:/etc/shadow:ro -v "$HOME":"$HOME" \
 -w "`pwd`" -e HOME=$HOME xivoxc/debian-builder:2021.13.latestdev
```
2. Launch all of them with tox :
```
tox --recreate -e py37
```

## Running integration tests

Below the new procedure to run integration tests :
1. go to the integration_tests folder
   ```
   cd integration_tests
   ```
2. If your dev is linked to a branch in provd, db or rabbitmq, export the branch in an env variable (by default it will default to master) respectively:
   - DB_TEST_BRANCH
   - PROVD_TEST_BRANCH
   - RABBITMQ_TEST_BRANCH
   - CONFIG_TEST_BRANCH
   - for example if you need branch *4436_user_advanced_search* for db:
   ```
   export DB_TEST_BRANCH=4436_user_advanced_search
   ```
3. Then launch the test setup (it will build all the containers):
   ```
   make test-setup
   ```
4. Then you can run *all the tests* **or** only *some tests*
   * Run all the tests:
     ```
     make test
     ```
   * **or** Run only one suite (you must be inside the container):
     1. run an instance of the debian-builder container, mounting the docker socket, the network and the project directories (HOME by default)
        ```
        make run-docker-builder
        ```
     2. (**Inside the container**) create and activate the venv:
        ```
        python3 -m venv /tmp/venv && source /tmp/venv/bin/activate
        ```
     3. (**Inside the container**) Install tests requirements:
        ```
        make test-req
        ```
     4. (**Inside the container**) Then you can run all the tests or only some tests:
        * Run all the tests:
          ```
          make run-test
          ```
        * **or** Run only one suite (you must be inside the container):
          ```
          nosetests -v suite/base/test_users.py
          nosetests -v suite/base/test_users.py:test_create_user_with_all_parameters
          ```
5.  Then you can clean the test environment:
   1. **exit** from the container:
      ```
      exit
      ```
   2. and run the clean command:
      ```
      make distclean
      ```

## Development

### xivo-dao

In case you need to mount xivo_dao inside the xivo-confd container, add the
following line in confd volumes in
integration_tests/assets/base/docker-compose.yml

```
- "/path/to/xivo_dao:/usr/local/lib/python2.7/site-packages/xivo_dao"
```

### Modified database

If you need to run tests against a modified database schema, run:

```
make update-db DB_DIR=../../xivo-db DB_VERSION=2019.12.latest
```

### Quick multiple runs

If you need to run tests more than once (e.g. when developing):

```
make stop
make start
DOCKER=0 nosetests suite
```

You can also just run one test suite:
```
cd integration_tests
nosetests suite/base/test_users.py
```
