-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.sh
More file actions
143 lines (102 loc) · 2.96 KB
/
commands.sh
File metadata and controls
143 lines (102 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# Lab 11 - Queryable Job History API with Tests
# Commands executed during the lab
# Update package manager
sudo apt update
# Install Python and pip
sudo apt install -y python3 python3-pip python3-venv
# Create project directory
mkdir -p ~/job-history-api
cd ~/job-history-api
pwd
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install flask flask-sqlalchemy pytest pytest-flask requests pytest-cov
# Create requirements.txt
nano requirements.txt
# Project Structure
mkdir -p app tests
touch app/__init__.py app/models.py app/routes.py app/config.py
touch tests/__init__.py tests/test_api.py
touch run.py populate_data.py
ls -R
# Step 1: Configure Database Models
nano app/models.py
# Step 2: Create Application Configuration
nano app/config.py
# Step 3: Initialize Flask Application
nano app/__init__.py
# Step 4: Implement API Routes with Filters
nano app/routes.py
# Step 5: Create Application Entry Point
nano run.py
# Step 6: Populate Sample Data
nano populate_data.py
# Step 1: Create Test Configuration
nano tests/test_api.py
# Step 4: Run Tests
source venv/bin/activate
# Step 4: Run Tests
pytest tests/ -v
# Step 4: Run Tests
pytest tests/ --cov=app --cov-report=term-missing
# Step 4: Run Tests
pytest tests/test_api.py::test_filter_by_status -v
# Step 1: Start the Application
python3 populate_data.py
# Step 1: Start the Application
python3 run.py
# Create a new job
curl -X POST http://localhost:5000/jobs \
-H "Content-Type: application/json" \
-d '{
"job_name": "test-job",
"status": "running",
"user": "testuser",
"environment": "dev"
}'
# Get all jobs
curl http://localhost:5000/jobs
# Filter by status
curl "http://localhost:5000/jobs?status=success"
# Filter by environment
curl "http://localhost:5000/jobs?environment=prod"
# Get statistics
curl http://localhost:5000/jobs/stats
# Update job status
curl -X PUT http://localhost:5000/jobs/1 \
-H "Content-Type: application/json" \
-d '{
"status": "success",
"end_time": "2024-01-15T10:30:00"
}'
# Get a specific job
curl http://localhost:5000/jobs/1
# Filter by user
curl "http://localhost:5000/jobs?user=admin"
# Filter by job name
curl "http://localhost:5000/jobs?job_name=backup-database"
# Filter by date range
curl "http://localhost:5000/jobs?start_date=2024-01-01&end_date=2024-12-31"
# Step 3: Verify Test Coverage
pytest tests/ -v --cov=app --cov-report=html
# Step 3: Verify Test Coverage
python3 -m http.server 8080 --directory htmlcov
# Check database file creation
ls -lh *.db
# Check project files
find . -maxdepth 2 -type f | sort
# Database locked error
rm -f job_history.db test_job_history.db
# Import errors
pip install -r requirements.txt
# Tests fail with 404
grep -n "register_blueprint" -n app/__init__.py
# Filter returns no results
sqlite3 job_history.db "SELECT COUNT(*) FROM job_history;"
# Flask app not starting
ss -tulpn | grep 5000
# Flask app not starting
pkill -f "python3 run.py"