Skip to content

HR System - Vacation API

Badge Badge Badge Badge

The Vacation API is responsible for querying and managing employee vacation data in the context of the organization's people management. The API was created out of the need for the human resources system, but it was designed to be used by other systems and services that require employee vacation information.

Dependencies

  • Python 3.7.3
  • Flask 1.1.1

Configuration

Vacation API configuration is done through operating system environment variables. Therefore the configuration must be done on the host or must be passed to the container environment.

The available settings are:

  • HTTP_PORT: HTTP port number on which the service will be available.
  • DATABASE_HOST: Database server network address.
  • DATABASE_PORT: Port on which database service is available.
  • DATABASE_NAME: Schema name available for the service.
  • DATABASE_USER: Username for database authentication.
  • DATABASE_PASSWORD: User password for database authentication.
  • CALENDAR_API_URL: API URL providing dates handled for vacation appointments.

If you have questions about how to set environment variables check these links:

Observation: The system was developed to run in Linux and Docker environments. No official support for Windows.

Development

Installing VirtualEnvWrapper

We recommend using a virtual environment created by the virtualenvwrapper module. There is a virtual site with English instructions for installation that can be accessed here. But you can also follow these steps below for installing the environment:

sudo python3 -m pip install -U pip             # Update pip
sudo python3 -m pip install virtualenvwrapper  # Install virtualenvwrapper module

Observation: If you do not have administrator access on the machine remove sudo from the beginning of the command and add the flag --user to the end of the command.

Now configure your shell to use virtualenvwrapper by adding these two lines to your shell initialization file (e.g. .bashrc,.profile, etc.)

export WORKON_HOME=\$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

If you want to add a specific project location (will automatically go to the project folder when the virtual environment is activated) just add a third line with the following export:

export PROJECT_HOME=/path/to/project

Run the shell startup file for the changes to take effect, for example:

source ~/.bashrc

Now create a virtual environment with the following command (entering the name you want for the environment), in this example I will use the name vacation:

mkvirtualenv -p $(which python3) vacation

To use it:

workon vacation
sudo python3 -m pip install pipenv
pipenv install # Will install all of the project dependencies

Observaion: Again, if necessary, add the flag --user to make the pipenv package installation for the local user.

Local Execution

For local system execution, run the following command in the project root folder (assuming virtualenv is already active):

python src/main.py

This will run the system on localhost and will be available on the HTTP_PORT port configured for the system. This way you can test new implementations.

Tests

To run the Vacation API tests follow the script below:

  1. Enable virtualenv vacation;
  2. Ensure that the dependencies are installed, especially:

    pytest
    pytest-coverage
    flake8
    
  3. Run the commands below:

export PYTHONPATH=$(pwd)                       # Set the python path as the project folder
pytest src/                                    # Performs the tests
pytest --cov=vacation src/                     # Performs tests evaluating coverage
pytest --cov=vacation --cov-report xml src/    # Generate the XML report of coverage
flake8 src/                                    # Run PEP8 linter
unset PYTHONPATH                               # Unset PYTHONPATH variable

During the tests the terminal will display a output with the test report (failures, skips and successes) and the system test coverage. For other configurations and supplemental documentation go to pytest and coverage.

During the lint process the terminal will report a bug report and warnings from the PEP8 style guide, for more configurations and additional documentation go to flake8 and PEP8

Build

To build the API Vacation service just follow the script below:

docker build -t api-vacation:<version> .

Setting the version on <version>. E.g.: latest, stable, alpha, 1.0.0 and etc.

Make sure you have logged in to the docker hub service. If you do not, run the docker login command.

docker push api-vacation:<version>

Finally, if the system will be executed by the built container docker, execute:

docker run -d --name api-vacation -e .env api-vacation

Observation: Assumes that the settings are listed in the .env file. For more settings, execution options, and supplemental documentation, go to Docker