-
Notifications
You must be signed in to change notification settings - Fork 6
141 lines (122 loc) · 4.89 KB
/
run-python-tests.yml
File metadata and controls
141 lines (122 loc) · 4.89 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
name: Run Python Tests
on:
pull_request:
branches:
- development
paths:
- 'mflix/server/python-fastapi/**'
push:
branches:
- development
paths:
- 'mflix/server/python-fastapi/**'
jobs:
test:
name: Run Python Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Atlas CLI
run: |
curl https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.47.0_linux_x86_64.deb --output atlas-cli.deb
sudo apt install ./atlas-cli.deb
- name: Set up a local deployment using Atlas CLI
run: |
atlas deployments setup myLocalRs1 --type local --port 27017 --force
- name: Install MongoDB Database Tools to load sample data
run: |
curl https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.13.0.deb --output mdb-db-tools.deb
sudo apt install ./mdb-db-tools.deb
- name: Download sample data
run: curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive
- name: Add sample data to database
run: mongorestore --archive=sampledata.archive --port=27017
- name: Setup Database (Data & Indexes)
run: |
# ---------------------------------------------------------
# 1. Prepare the Search Index Definition
# ---------------------------------------------------------
echo '{
"mappings": {
"dynamic": false,
"fields": {
"plot": {"type": "string", "analyzer": "lucene.standard"},
"fullplot": {"type": "string", "analyzer": "lucene.standard"},
"directors": {"type": "string", "analyzer": "lucene.standard"},
"writers": {"type": "string", "analyzer": "lucene.standard"},
"cast": {"type": "string", "analyzer": "lucene.standard"}
}
}
}' > search_index.json
# 3. Create the Search Index
atlas deployments search indexes create movieSearchIndex \
--deploymentName myLocalRs1 \
--db sample_mflix \
--collection movies \
--file search_index.json
# ---------------------------------------------------------
# 2. Prepare the Vector Index Definition
# ---------------------------------------------------------
echo '{
"fields": [
{
"type": "vector",
"path": "plot_embedding_voyage_3_large",
"numDimensions": 2048,
"similarity": "cosine"
}
]
}' > vector_index.json
# 4. Create the Vector Index
atlas deployments search indexes create vector_index \
--deploymentName myLocalRs1 \
--db sample_mflix \
--collection embedded_movies \
--type vectorSearch \
--file vector_index.json
# ---------------------------------------------------------
# 6. Wait for indexes to build
# ---------------------------------------------------------
echo "Waiting for indexes to build..."
sleep 20
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
cache-dependency-path: mflix/server/python-fastapi/requirements.txt
- name: Install dependencies
working-directory: mflix/server/python-fastapi
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run unit tests
working-directory: mflix/server/python-fastapi
run: pytest -m unit --verbose --tb=short --junit-xml=test-results-unit.xml
env:
MONGO_URI: mongodb://localhost:27017
MONGO_DB: sample_mflix
- name: Run integration tests
working-directory: mflix/server/python-fastapi
run: pytest -m integration --verbose --tb=short --junit-xml=test-results-integration.xml || true
env:
MONGO_URI: mongodb://localhost:27017/?directConnection=true
MONGO_DB: sample_mflix
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: |
mflix/server/python-fastapi/test-results-unit.xml
mflix/server/python-fastapi/test-results-integration.xml
mflix/server/python-fastapi/htmlcov/
retention-days: 30
- name: Generate Test Summary
if: always()
run: |
chmod +x .github/scripts/generate-test-summary-pytest.sh
.github/scripts/generate-test-summary-pytest.sh \
mflix/server/python-fastapi/test-results-unit.xml \
mflix/server/python-fastapi/test-results-integration.xml