Skip to content

Commit 5ede100

Browse files
authored
INTPYTHON-449 Use local atlas for testing (#36)
1 parent 6047a6e commit 5ede100

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

.github/workflows/_release.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,14 @@ jobs:
165165
run: make tests
166166
working-directory: ${{ inputs.working-directory }}
167167

168+
- name: Start local Atlas
169+
run: bash scripts/start_local_atlas.sh
170+
171+
- name: Get MongoDB URI
172+
run: cat .local_atlas_uri >> $GITHUB_ENV
173+
168174
- name: Run integration tests
169175
env:
170-
MONGODB_URI: ${{ secrets.MONGODB_ATLAS_URI }}
171176
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
172177
run: make integration_tests
173178
working-directory: ${{ inputs.working-directory }}

.github/workflows/_test.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@ jobs:
4747
run: |
4848
make test
4949
50+
- name: Start local Atlas
51+
working-directory: .
52+
run: bash scripts/start_local_atlas.sh
53+
54+
- name: Get MongoDB URI
55+
working-directory: .
56+
run: cat .local_atlas_uri >> $GITHUB_ENV
57+
5058
- name: Run integration tests
5159
env:
52-
MONGODB_URI: ${{ secrets.MONGODB_ATLAS_URI }}
5360
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
54-
run: |
55-
if [[ "${{ github.event_name }}" == "push" ]]; then
56-
# Only run on the min python version.
57-
if [[ "${{ matrix.python-version }}" == "3.9" ]]; then
58-
make integration_tests
59-
fi
60-
fi
61+
run: make integration_tests
6162
working-directory: ${{ inputs.working-directory }}
6263

6364
- name: Ensure the tests did not create any additional files

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ __pycache__
55
.mypy_cache_test
66
.env
77
.venv*
8+
.local_atlas_uri

libs/mongodb/tests/integration_tests/test_chain_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def collection() -> Collection:
5151

5252

5353
@pytest.mark.skipif(
54-
"OPENAI_API_KEY" not in os.environ, reason="Requires OpenAI for chat responses."
54+
os.environ.get("OPENAI_API_KEY") is not None, reason="Requires OpenAI for chat responses."
5555
)
5656
def test_chain(
5757
collection: Collection,

libs/mongodb/tests/integration_tests/test_retrievers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def embedding_openai() -> Embeddings:
5555
model="text-embedding-3-small",
5656
)
5757
except Exception:
58-
pytest.fail("test_retrievers expects OPENAI_API_KEY in os.environ")
58+
pytest.skip("test_retrievers expects OPENAI_API_KEY in os.environ")
5959

6060

6161
@pytest.fixture(scope="module")

scripts/start_local_atlas.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
echo "Starting the container"
5+
6+
IMAGE=mongodb/mongodb-atlas-local:latest
7+
podman pull $IMAGE
8+
9+
CONTAINER_ID=$(podman run --rm -d -e DO_NOT_TRACK=1 --name mongodb_atlas_local -P $IMAGE)
10+
11+
function wait() {
12+
CONTAINER_ID=$1
13+
echo "waiting for container to become healthy..."
14+
podman logs mongodb_atlas_local
15+
}
16+
17+
wait "$CONTAINER_ID"
18+
19+
EXPOSED_PORT=$(podman inspect --format='{{ (index (index .NetworkSettings.Ports "27017/tcp") 0).HostPort }}' "$CONTAINER_ID")
20+
export CONN_STRING="mongodb://127.0.0.1:$EXPOSED_PORT/?directConnection=true"
21+
SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})")
22+
ROOT_DIR=$(dirname $SCRIPT_DIR)
23+
echo "MONGODB_URI=mongodb://127.0.0.1:$EXPOSED_PORT/?directConnection=true" > $ROOT_DIR/.local_atlas_uri

0 commit comments

Comments
 (0)