Skip to content

Commit 37df459

Browse files
authored
Feat: Add sample sanic-postgres app for the samples python repository (#35)
* Add sample postgres app Signed-off-by: slashexx <[email protected]> * Add sanic app (keploy#2337) * Add readme Signed-off-by: slashexx <[email protected]> --------- Signed-off-by: slashexx <[email protected]>
1 parent f4aebd4 commit 37df459

File tree

19 files changed

+2574
-0
lines changed

19 files changed

+2574
-0
lines changed

sanic-postgres/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FLASK_ENV=development
2+
DATABASE_URL=postgresql://myuser:mypassword@localhost:5432/mydatabase

sanic-postgres/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
myenv/

sanic-postgres/README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Employee Management API
2+
3+
This application is a simple employee management API built using Python's Sanic framework and PostgreSQL for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on employee records.
4+
5+
## Table of Contents
6+
7+
- [Introduction](#introduction)
8+
- [Pre-Requisites](#pre-requisites)
9+
- [Installation](#installation)
10+
- [API Endpoints](#api-endpoints)
11+
- [Create Employee](#create-employee)
12+
- [Get All Employees](#get-all-employees)
13+
- [Get Employee by ID](#get-employee-by-id)
14+
- [Update Employee](#update-employee)
15+
- [Delete Employee](#delete-employee)
16+
- [Testing](#testing)
17+
- [Wrapping it up](#wrapping-it-up)
18+
19+
## Introduction
20+
21+
🪄 Dive into the world of Employee Management and see how seamlessly Keploy integrated with Sanic and PostgreSQL. Buckle up, it's gonna be a fun ride! 🎢
22+
23+
## Pre-Requisites 🛠️
24+
25+
Before you begin, ensure you have the following installed:
26+
27+
- **Python 3.x**: The programming language used for this application. You can download it from [python.org](https://www.python.org/downloads/).
28+
- **PostgreSQL**: The database system used for storing employee data. You can download it from [postgresql.org](https://www.postgresql.org/download/).
29+
30+
## Installation 📥
31+
32+
Once you have the prerequisites set up, follow these steps:
33+
34+
1. Clone the repository:
35+
36+
```bash
37+
git clone https://github.com/keploy/sample-python.git
38+
cd sample-python
39+
Install the required Python packages:
40+
41+
```bash
42+
pip install -r requirements.txt
43+
```
44+
45+
Set up your PostgreSQL database and update the connection settings in your application as needed.
46+
47+
Install the latest Keploy binary:
48+
49+
```bash
50+
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
51+
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
52+
```
53+
Add alias for Keploy:
54+
55+
```bash
56+
alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v '"$HOME"'/.keploy-config:/root/.keploy-config -v '"$HOME"'/.keploy:/root/.keploy --rm ghcr.io/keploy/keploy'
57+
```
58+
Install the dependencies:
59+
60+
```bash
61+
pip3 install -r requirements.txt
62+
```
63+
API Endpoints
64+
Create Employee
65+
To add a new employee:
66+
67+
```bash
68+
curl -X POST http://localhost:8000/employees \
69+
-H "Content-Type: application/json" \
70+
-d '{
71+
"first_name": "John",
72+
"last_name": "Doe",
73+
"email": "[email protected]",
74+
"position": "Developer",
75+
"salary": 60000
76+
}'
77+
```
78+
Get All Employees
79+
To retrieve all employees:
80+
81+
```bash
82+
curl -X GET http://localhost:8000/employees
83+
```
84+
85+
Get Employee by ID
86+
To retrieve a specific employee by ID:
87+
88+
```bash
89+
curl -X GET http://localhost:8000/employees/1
90+
```
91+
Update Employee
92+
To update an existing employee's details:
93+
94+
```bash
95+
curl -X PUT http://localhost:8000/employees/1 \
96+
-H "Content-Type: application/json" \
97+
-d '{
98+
"first_name": "Jane",
99+
"last_name": "Doe",
100+
"email": "[email protected]",
101+
"position": "Senior Developer",
102+
"salary": 80000
103+
}'
104+
```
105+
Delete Employee
106+
To delete an employee:
107+
108+
```bash
109+
curl -X DELETE http://localhost:8000/employees/1
110+
```
111+
Testing
112+
Capture Test Cases
113+
Capture the test cases using Keploy:
114+
115+
```bash
116+
keploy record -c "python3 server.py"
117+
```
118+
Run Tests
119+
Run the tests:
120+
121+
```bash
122+
keploy test -c "python3 server.py"
123+
```
124+
Wrapping it up 🎉
125+
Congrats on the journey so far! You've seen how to manage employees seamlessly with Keploy, Sanic, and PostgreSQL. Keep exploring, innovating, and creating! With the right tools, anything's possible. 😊🚀
126+
127+
Happy coding! ✨👩‍💻👨‍💻✨

sanic-postgres/keploy.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
path: ""
2+
appId: 0
3+
appName: sanic-postgres
4+
command: python3 server.py
5+
templatize:
6+
testSets: []
7+
port: 0
8+
dnsPort: 26789
9+
proxyPort: 16789
10+
debug: false
11+
disableTele: false
12+
disableANSI: false
13+
containerName: ""
14+
networkName: ""
15+
buildDelay: 30
16+
test:
17+
selectedTests: {}
18+
globalNoise:
19+
global: {}
20+
test-sets: {}
21+
delay: 5
22+
host: ""
23+
port: 0
24+
apiTimeout: 5
25+
skipCoverage: false
26+
coverageReportPath: ""
27+
ignoreOrdering: true
28+
mongoPassword: default@123
29+
language: ""
30+
removeUnusedMocks: false
31+
fallBackOnMiss: false
32+
jacocoAgentPath: ""
33+
basePath: ""
34+
mocking: true
35+
ignoredTests: {}
36+
disableLineCoverage: false
37+
disableMockUpload: true
38+
useLocalMock: false
39+
updateTemplate: false
40+
record:
41+
filters: []
42+
recordTimer: 0s
43+
configPath: ""
44+
bypassRules: []
45+
generateGithubActions: false
46+
keployContainer: keploy-v2
47+
keployNetwork: keploy-network
48+
cmdType: native
49+
contract:
50+
services: []
51+
tests: []
52+
path: ""
53+
download: false
54+
generate: false
55+
driven: consumer
56+
mappings:
57+
servicesMapping: {}
58+
self: ""
59+
inCi: false
60+
61+
# Visit [https://keploy.io/docs/running-keploy/configuration-file/] to learn about using keploy through configration file.

sanic-postgres/keploy/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
/reports/

0 commit comments

Comments
 (0)