This application and library allow you to efficiently track cloud usage for customers. The library simplifies the process by taking a customer ID as input and generating a bill with usage details and the total price owed for the current month. First here's some links to navigate this README:
The usage_app
is a Django-based web service that handles usage data and provides an API endpoint for recording usage. To run the app locally:
Use this bash script
Run this bash script
chmod +x setup_script.sh
./setup_script.sh
OR run this manually
- Clone the repository:
git clone https://github.com/your-username/usage_app.git
cd UsageTracker
- Set up a virtual environment (optional but recommended):
python3 -m venv venv
source venv/bin/activate
-
Create and apply database migrations:
pip install -r requirements.txt
-
Seed the database with initial data:
python manage.py makemigrations python manage.py migrate python manage.py loaddata customer_data.json python manage.py loaddata usage_data.json
-
Run development server
python manage.py runserver
The usage client takes in the id of a customer. When we use the method, it fires a post request that will add to that customer's current bill based on their usage.
-
Install the usage_client library (make sure you are still in the virtualenv or changed it if you are running it): ``pip install .`
-
To test, open up your terminal and launch a python:
python3
from usage_client import UsageAPIClient
client = UsageAPIClient("http://localhost:8000") # Adjust the URL as needed
client.create_usage(123)
{'message': {'message': 'No accumulated usage record or usage records found for customer Alice.'}}
{'message': {'id': 1, 'month': 8, 'year': 2023, 'accumulated_price': '16.61', 'price_in_dollars': '$16.61', 'customer': 456}}
{'message': {'message': 'Entry has already been processed for customer Bob.', 'data': {'total_price': '$16.61'}}}
{'message': 'No accumulated usage record or usage records found for customer.'}
python manage.py test usage_app.test_usage_app
python manage.py test tests.test_usage_client