Basic Automated Testing using PostMan
- Postman Automated Testing is done using JavaScript.
- Lets write a basic test for the GetAllRecipes Testcase to check for status 200
- In the same way lets try to check for status for all the other test cases
- Now lets try to run the tests
- The Test Results
- Refer Here for the changes done to implement the status code tests.
Manipulating a Database with SQLAlchemy
-
Till now we were only storing our data in application memory
-
We need to persist our data into database
-
Lets try to use PostgreSQL, We wil be install Postgres database on our local machine.
-
We will be using pgAdmin to interact with Postgres.
-
ORM (Object Relational Mapping) package SQLAlchemy using which we would interact with the database using python objects instead of SQL queries.
-
ORM is a programming technique that allows developers to map objects in programming language to the data model in a database.
-
The mapping works along the following lines
- Class in Python => The table schema in the database
- Attributes in the Class => fields in the table schema
- Objects => rows of data in the table.
-
SQLAlchemy is the most popular ORM in python community
-
Installation:
- Windows => Refer Here
- Mac => Refer Here
- On other OS => Refer Here
- Installers Refer Here
-
Follow the installation steps and connect to the local database as shown in the class or follow recording.
-
Lets Create a role in PostgreSQL. A role is concept that Postgres uses to manage access
- Instructions
- Follow as done in the Class
- Instructions
-
Lets Create a New database instacook and select the role which we have created as owner
-
As the Database is created, Now we need to create our models
- Recipe Model:
- id: The identity of recipe
- name: The name of the recipe. Max Length = 100 chars, This cannot be null
- description: The description of recipe, Max Length = 256 chars
- num_of_servings: The number of servings, This needs to be integer
- cook_time: The cooking time in minutes. This field only accept an integer
- directions: The directions of the recipe. This can have max length of 1000 characters
- is_publish: This is to indicate whether the recipe is published or not, set to False by default
- created_at: The creation time of the recipe
- updated_at: The last update time of the recipe
- Recipe Model:
-
We need to install the following python packages
- Flask-SQLAlchemy: This is very popular ORM package that allows us to access objects rather than tables for data. With ORM, we need not rely on SQL
- Flask-Migrate: This is a package for database migrations, it works on top of Almebic
- Psycopg2-binary: This is the adapter for the Postgres database
-
Refer Here for the requirements.txt updated
-
Now to create connection with database we need to create database uri Refer Here