Skip to content

Commit 2ccaaef

Browse files
avara1986randomandersonbrettlangdon
authored
chore(ci): migrate Appsec fastapi tests (#12196)
## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Laplie Anderson <[email protected]> Co-authored-by: Brett Langdon <[email protected]>
1 parent eff3155 commit 2ccaaef

File tree

6 files changed

+87
-1
lines changed

6 files changed

+87
-1
lines changed

Diff for: hatch.toml

+39
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,45 @@ python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
400400
flask = ["~=3.0"]
401401

402402

403+
[envs.appsec_integrations_fastapi]
404+
template = "appsec_integrations_fastapi"
405+
dependencies = [
406+
"pytest",
407+
"pytest-cov",
408+
"requests",
409+
"hypothesis",
410+
"jinja2",
411+
"httpx<0.28.0",
412+
"anyio{matrix:anyio:}",
413+
"fastapi{matrix:fastapi}"
414+
]
415+
416+
[envs.appsec_integrations_fastapi.env-vars]
417+
CMAKE_BUILD_PARALLEL_LEVEL = "12"
418+
419+
[envs.appsec_integrations_fastapi.scripts]
420+
test = [
421+
"uname -a",
422+
"pip freeze",
423+
"DD_TRACE_AGENT_URL=\"http://testagent:9126\" DD_CIVISIBILITY_ITR_ENABLED=0 DD_IAST_REQUEST_SAMPLING=100 DD_IAST_DEDUPLICATION_ENABLED=false python -m pytest -vvv {args:tests/appsec/integrations/fastapi_tests/}",
424+
]
425+
426+
427+
# if you add or remove a version here, please also update the parallelism parameter
428+
# in .circleci/config.templ.yml
429+
[[envs.appsec_integrations_fastapi.matrix]]
430+
python = ["3.8", "3.10", "3.13"]
431+
fastapi = ["==0.86.0"]
432+
anyio = ["==3.7.1"]
433+
434+
[[envs.appsec_integrations_fastapi.matrix]]
435+
python = ["3.8", "3.10", "3.13"]
436+
fastapi = ["==0.94.1"]
437+
438+
[[envs.appsec_integrations_fastapi.matrix]]
439+
python = ["3.8", "3.10", "3.13"]
440+
fastapi = ["~=0.114.2"]
441+
403442

404443
## ASM FastAPI
405444

Diff for: tests/appsec/integrations/fastapi_tests/__init__.py

Whitespace-only changes.

Diff for: tests/appsec/integrations/fastapi_tests/app.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fastapi import FastAPI
2+
3+
4+
def get_app():
5+
app = FastAPI()
6+
return app

Diff for: tests/appsec/integrations/fastapi_tests/conftest.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from fastapi.testclient import TestClient
2+
import pytest
3+
4+
import ddtrace
5+
from ddtrace.contrib.internal.fastapi.patch import patch as fastapi_patch
6+
from ddtrace.contrib.internal.fastapi.patch import unpatch as fastapi_unpatch
7+
from tests.utils import DummyTracer
8+
from tests.utils import TracerSpanContainer
9+
10+
from . import app
11+
12+
13+
@pytest.fixture
14+
def tracer():
15+
original_tracer = ddtrace.tracer
16+
tracer = DummyTracer()
17+
18+
ddtrace.tracer = tracer
19+
fastapi_patch()
20+
yield tracer
21+
ddtrace.tracer = original_tracer
22+
fastapi_unpatch()
23+
24+
25+
@pytest.fixture
26+
def test_spans(tracer):
27+
container = TracerSpanContainer(tracer)
28+
yield container
29+
container.reset()
30+
31+
32+
@pytest.fixture
33+
def fastapi_application(tracer):
34+
application = app.get_app()
35+
yield application
36+
37+
38+
@pytest.fixture
39+
def client(tracer, fastapi_application):
40+
with TestClient(fastapi_application) as test_client:
41+
yield test_client

Diff for: tests/contrib/fastapi/test_fastapi_appsec_iast.py renamed to tests/appsec/integrations/fastapi_tests/test_fastapi_appsec_iast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from tests.utils import override_global_config
3636

3737

38-
TEST_FILE_PATH = "tests/contrib/fastapi/test_fastapi_appsec_iast.py"
38+
TEST_FILE_PATH = "tests/appsec/integrations/fastapi_tests/test_fastapi_appsec_iast.py"
3939

4040
fastapi_version = tuple([int(v) for v in _fastapi_version.split(".")])
4141

0 commit comments

Comments
 (0)