Skip to content

A simple toy system for the course PA1417 Basic System Verification

License

Notifications You must be signed in to change notification settings

JulianFrattini/bsv-chef

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiny Chef

GitHub

This repository contains a simple, work-in-progress web-based system for testing purposes. It currently consists of a backend implemented in Flask and is connected to a MongoDB database. A frontend is anticipated according to the requirements, but not yet implemented.

Structure

This repository is structured as follows:

  • .github\workflows\pytest.yml : continuous integration pipeline that runs all tests containing the marker demo and unit
  • backend: Directory containing the backend
    • src: Source code of the backend
    • test: Location for all test files
    • .env: Environment variables
    • Dockerfile: Definition of a docker image
    • main.py: Main starting point of the backend, to be started with python -m main
    • pytest.ini: Pytest configuration
    • requirements.txt: Libraries required by the backend, to be installed via pip install -r requirements.txt
  • documentation: Markdown-files containing the context and requirements specification.

Using the System

You can setup and run the system to familiarize yourself with its functionality.

Setup

To set up the system, you have two choices: you can either run the system locally or run the dockerized version.

Local Setup

Make sure that Python 3.10 and MongoDB are available on your system. Then, perform the following steps for preparation:

  1. Make sure that the data base path data\db exists in the root folder of this repository.
  2. Install the requirementens in the backend folder by running python -m pip install -r requirements.txt.

Finally, get the system running with the following commands (each executed in its own shell):

  1. To start the data base, run mongod --port 27017 --dbpath data\db from the root folder in a console with admin rights (make sure that the direction of the slashes matches your operating system).
  2. To start the the server, run python -m main from the backend folder.

Dockerized Setup

Make sure that Docker is available on your system. Then, perform the following steps:

  1. With Docker Desktop running, execute docker-compose up from the root folder in a console with admin rights.

Accessing the System

Once the system is running, you can interact with it for example using Postman. Verify that the system is running by executing GET http://localhost:5000/ which should return a heartbeat in the form of a version string { "version" : "v0.5.0" }.

The database stores pantry items, which you can view via GET http://localhost:5000/items/all. At the beginning, the database is empty and this REST call should return an empty array []. Populate the database by running POST http://localhost:5000/populate, which will take the dummy data and adds them to the database. Now, GET http://localhost:5000/items/all should list several items. You can create further items via POST http://localhost:5000/items/create, where the body must contain the name, quantity, and unit field.

Finally, you can explore the main functionality of the system by running GET http://localhost:5000/recipes (containing the diet and usage_mode fields in the body as specified in the method description), which generates a random recipe. For example, calling the aforementioned request with diet = normal and usage_mode = optimal should - if the populate function had been run - return a recipe for banana bread, while changing diet = vegan should return a recipe for whole grain bread.

You can retrace the database by connecting to it using MongoDB Compass. Connect on the url mongodb://localhost:27017/ (if you are using a local setup) or mongodb://root:root@localhost:27017/ (if you are using a dockerized setup). In the tinychef database, you will find the item collection, where all the items are stored.

Testing the system

To execute Pytest test cases in this repository, make sure to have all dependencies from the backend/requirements.txt installed. Then, navigate a console to the backend folder and execute python -m pytest -m <marker>. You find a list of available markers in the backend/pytest.ini file.

Alternatively, you can make use of the alread set-up Github workflow, which will execute all test cases with the staging and unit marker: for this, push your code to your fork of the remote repository and evaluate the Github actions output under your repositories "Action" tab.

Make sure that

  1. your test cases are marked, i.e., they are preceeded by a @pytest.mark.unit marker similar to the demo test case, and
  2. you inspect the right step of the Github action, as the action will execute test cases with different markers at different stages.

License

Copyright © 2023 by Julian Frattini. This work (source code) is available under GPL 3.0 license.

About

A simple toy system for the course PA1417 Basic System Verification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published