HR System - Paycheck API
The Payments API is responsible for querying and processing employee pay data in the context of the organization's people management. The API was created out of the human resources system's need, but it was designed to allow access to query services by other systems and services that require employee payroll information.
Dependencies
- Python 3.7.3
- Flask 1.1.1
Configuration
The Paycheck API configuration is 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.DECIMAL_PLACES: Number of decimal places to display calculations.PAYCHECK_CURRENCY: Which are the currency for the payment amounts. AvailableBRL (R$)andUSD (US$).
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 paycheck:
mkvirtualenv -p $(which python3) paycheck
To use it:
workon paycheck
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 Paycheck API tests follow the script below:
- Enable virtualenv paycheck;
-
Ensure that the dependencies are installed, especially:
pytest pytest-coverage flake8 -
Run the commands below:
export PYTHONPATH=$(pwd) # Set the python path as the project folder
pytest src/ # Performs the tests
pytest --cov=paycheck src/ # Performs tests evaluating coverage
pytest --cov=paycheck --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 Paycheck service just follow the script below:
docker build -t api-paycheck:<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-paycheck:<version>
Finally, if the system will be executed by the built container docker, execute:
docker run -d --name api-paycheck -e .env api-paycheck
Observation: Assumes that the settings are listed in the .env file. For more settings, execution options, and supplemental documentation, go to Docker