This repository is for inventory group in NYU-DevOps-2022sp class
The inventory resource keeps track of how many of each product we have in our warehouse. Now, it can reference a product, the quantity and the condition of the item (i.e., new, open box, used)on hand. Inventory will also track restock levels in the future. Restock levels will help us know when to order more products.
Version 1.0 overview:
- Define the object model in inventory as products with attributes as id/product_name/quantity/status .
- Implement the CREATE/READ/UPDATE/DELETE/LIST API.
- Allow the microservice root URL ('/') to return some useful information about the service like the name, version, and what our resource URL is.
- Have a portable environment for development.
- Apply nosetests in development process and get coverage of 97%.
- Use Docker and a docker-compose.yml file with the Remote Containers extensions for services like PostgreSQL. So that they are running in Docker.
This microservice uses Docker and Visual Studio Code with the Remote Containers extension to provide a consistent repeatable disposable development environment. You will need the following software installed:
- Docker Desktop
- Visual Studio Code
- Remote Containers extension from the Visual Studio Marketplace
All of these can be installed manually by clicking on the links above or you can use a package manager like Homebrew on Mac of Chocolatey on Windows.
To bring up the development environment you should clone this repo, change into the repo directory:
$ git clone https://github.com/nyu-devops-2022sp-inventory/inventory.git
$ cd inventory
$ code .
Run the tests using nosetests
.
- If you are using Windows OS, try
$ nosetests --exe
- For MacOS, try
$ nosetests
Nose is also configured to automatically run the coverage
tool and you should see a percentage-of-coverage report at the end of your tests. If you want to see what lines of code were not tested use:
$ coverage report -m
This is particularly useful because it reports the line numbers for the code that have not been covered so you know which lines you want to target with new test cases to get higher code coverage.
To start the service simply use:
$ honcho start
You should be able to reach the service at: http://localhost:8080. The port that is used is controlled by an environment variable defined in the .flaskenv
file which Flask uses to load it's configuration from the environment by default.
After entering the root, you can see a json file return to you with content:
{
"list_path": "http://127.0.0.1:8080/inventory",
"name": "Inventory REST API Service",
"version": "1.0"
}
That means you sucessfully start the microservice.
With the service running, open a second bash
terminal and issue the following curl
commands:
List all products:
curl -X GET http://127.0.0.1:8080/inventory
Create a product:
curl -X POST \
http://127.0.0.1:8080/inventory \
-H 'content-type: application/json' \
-d '{"name":"apple", "quantity":2, "status":"NEW"}'
Read a product(hint: change the <product_id> into a real id number):
curl -X GET \
http://127.0.0.1:8080/inventory/<product_id>
Update a product:
curl -X PUT \
http://127.0.0.1:8080/inventory/<product_id> \
-H 'content-type: application/json' \
-d '{"name":"Green apple", "quantity":2, "status":"NEW"}'
Delete a product:
curl -X DELETE http://127.0.0.1:8080/inventory/<product_id>
There is no need to manually bring the development environment down. When you close Visual Studio Code it will wait a while to see if you load it back up and if you don't it will stop the Docker containers. When you come back again, it will start them up and resume where you left off.