From ba6a8da69477d4222b7524119188499520af55d1 Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 22 Oct 2024 13:46:06 +0200 Subject: [PATCH 1/5] Remove CSRF mock and make use of pytest-mock --- poetry.lock | 184 ++++++++++++++++++------------ pyproject.toml | 1 + tests/api/routes/test_project.py | 4 +- tests/api/routes/test_projects.py | 12 +- tests/conftest.py | 8 -- 5 files changed, 121 insertions(+), 88 deletions(-) diff --git a/poetry.lock b/poetry.lock index 477ed0b3..99fb3a81 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "alembic" @@ -574,13 +574,13 @@ python-dateutil = ">=2.7" [[package]] name = "fsspec" -version = "2024.9.0" +version = "2024.10.0" description = "File-system specification" optional = false python-versions = ">=3.8" files = [ - {file = "fsspec-2024.9.0-py3-none-any.whl", hash = "sha256:a0947d552d8a6efa72cc2c730b12c41d043509156966cca4fb157b0f2a0c574b"}, - {file = "fsspec-2024.9.0.tar.gz", hash = "sha256:4b0afb90c2f21832df142f292649035d80b421f60a9e1c027802e5a0da2b04e8"}, + {file = "fsspec-2024.10.0-py3-none-any.whl", hash = "sha256:03b9a6785766a4de40368b88906366755e2819e758b83705c88cd7cb5fe81871"}, + {file = "fsspec-2024.10.0.tar.gz", hash = "sha256:eda2d8a4116d4f2429db8550f2457da57279247dd930bb12f821b58391359493"}, ] [package.extras] @@ -613,69 +613,84 @@ tqdm = ["tqdm"] [[package]] name = "greenlet" -version = "3.0.3" +version = "3.1.1" description = "Lightweight in-process concurrent programming" optional = false python-versions = ">=3.7" files = [ - {file = "greenlet-3.0.3-cp310-cp310-macosx_11_0_universal2.whl", hash = "sha256:9da2bd29ed9e4f15955dd1595ad7bc9320308a3b766ef7f837e23ad4b4aac31a"}, - {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d353cadd6083fdb056bb46ed07e4340b0869c305c8ca54ef9da3421acbdf6881"}, - {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:dca1e2f3ca00b84a396bc1bce13dd21f680f035314d2379c4160c98153b2059b"}, - {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3ed7fb269f15dc662787f4119ec300ad0702fa1b19d2135a37c2c4de6fadfd4a"}, - {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd4f49ae60e10adbc94b45c0b5e6a179acc1736cf7a90160b404076ee283cf83"}, - {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:73a411ef564e0e097dbe7e866bb2dda0f027e072b04da387282b02c308807405"}, - {file = "greenlet-3.0.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:7f362975f2d179f9e26928c5b517524e89dd48530a0202570d55ad6ca5d8a56f"}, - {file = "greenlet-3.0.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:649dde7de1a5eceb258f9cb00bdf50e978c9db1b996964cd80703614c86495eb"}, - {file = "greenlet-3.0.3-cp310-cp310-win_amd64.whl", hash = "sha256:68834da854554926fbedd38c76e60c4a2e3198c6fbed520b106a8986445caaf9"}, - {file = "greenlet-3.0.3-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:b1b5667cced97081bf57b8fa1d6bfca67814b0afd38208d52538316e9422fc61"}, - {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:52f59dd9c96ad2fc0d5724107444f76eb20aaccb675bf825df6435acb7703559"}, - {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:afaff6cf5200befd5cec055b07d1c0a5a06c040fe5ad148abcd11ba6ab9b114e"}, - {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fe754d231288e1e64323cfad462fcee8f0288654c10bdf4f603a39ed923bef33"}, - {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2797aa5aedac23af156bbb5a6aa2cd3427ada2972c828244eb7d1b9255846379"}, - {file = "greenlet-3.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b7f009caad047246ed379e1c4dbcb8b020f0a390667ea74d2387be2998f58a22"}, - {file = "greenlet-3.0.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:c5e1536de2aad7bf62e27baf79225d0d64360d4168cf2e6becb91baf1ed074f3"}, - {file = "greenlet-3.0.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:894393ce10ceac937e56ec00bb71c4c2f8209ad516e96033e4b3b1de270e200d"}, - {file = "greenlet-3.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:1ea188d4f49089fc6fb283845ab18a2518d279c7cd9da1065d7a84e991748728"}, - {file = "greenlet-3.0.3-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:70fb482fdf2c707765ab5f0b6655e9cfcf3780d8d87355a063547b41177599be"}, - {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d4d1ac74f5c0c0524e4a24335350edad7e5f03b9532da7ea4d3c54d527784f2e"}, - {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:149e94a2dd82d19838fe4b2259f1b6b9957d5ba1b25640d2380bea9c5df37676"}, - {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:15d79dd26056573940fcb8c7413d84118086f2ec1a8acdfa854631084393efcc"}, - {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:881b7db1ebff4ba09aaaeae6aa491daeb226c8150fc20e836ad00041bcb11230"}, - {file = "greenlet-3.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fcd2469d6a2cf298f198f0487e0a5b1a47a42ca0fa4dfd1b6862c999f018ebbf"}, - {file = "greenlet-3.0.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:1f672519db1796ca0d8753f9e78ec02355e862d0998193038c7073045899f305"}, - {file = "greenlet-3.0.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:2516a9957eed41dd8f1ec0c604f1cdc86758b587d964668b5b196a9db5bfcde6"}, - {file = "greenlet-3.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:bba5387a6975598857d86de9eac14210a49d554a77eb8261cc68b7d082f78ce2"}, - {file = "greenlet-3.0.3-cp37-cp37m-macosx_11_0_universal2.whl", hash = "sha256:5b51e85cb5ceda94e79d019ed36b35386e8c37d22f07d6a751cb659b180d5274"}, - {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:daf3cb43b7cf2ba96d614252ce1684c1bccee6b2183a01328c98d36fcd7d5cb0"}, - {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:99bf650dc5d69546e076f413a87481ee1d2d09aaaaaca058c9251b6d8c14783f"}, - {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2dd6e660effd852586b6a8478a1d244b8dc90ab5b1321751d2ea15deb49ed414"}, - {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e3391d1e16e2a5a1507d83e4a8b100f4ee626e8eca43cf2cadb543de69827c4c"}, - {file = "greenlet-3.0.3-cp37-cp37m-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e1f145462f1fa6e4a4ae3c0f782e580ce44d57c8f2c7aae1b6fa88c0b2efdb41"}, - {file = "greenlet-3.0.3-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:1a7191e42732df52cb5f39d3527217e7ab73cae2cb3694d241e18f53d84ea9a7"}, - {file = "greenlet-3.0.3-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:0448abc479fab28b00cb472d278828b3ccca164531daab4e970a0458786055d6"}, - {file = "greenlet-3.0.3-cp37-cp37m-win32.whl", hash = "sha256:b542be2440edc2d48547b5923c408cbe0fc94afb9f18741faa6ae970dbcb9b6d"}, - {file = "greenlet-3.0.3-cp37-cp37m-win_amd64.whl", hash = "sha256:01bc7ea167cf943b4c802068e178bbf70ae2e8c080467070d01bfa02f337ee67"}, - {file = "greenlet-3.0.3-cp38-cp38-macosx_11_0_universal2.whl", hash = "sha256:1996cb9306c8595335bb157d133daf5cf9f693ef413e7673cb07e3e5871379ca"}, - {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3ddc0f794e6ad661e321caa8d2f0a55ce01213c74722587256fb6566049a8b04"}, - {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c9db1c18f0eaad2f804728c67d6c610778456e3e1cc4ab4bbd5eeb8e6053c6fc"}, - {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7170375bcc99f1a2fbd9c306f5be8764eaf3ac6b5cb968862cad4c7057756506"}, - {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6b66c9c1e7ccabad3a7d037b2bcb740122a7b17a53734b7d72a344ce39882a1b"}, - {file = "greenlet-3.0.3-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:098d86f528c855ead3479afe84b49242e174ed262456c342d70fc7f972bc13c4"}, - {file = "greenlet-3.0.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:81bb9c6d52e8321f09c3d165b2a78c680506d9af285bfccbad9fb7ad5a5da3e5"}, - {file = "greenlet-3.0.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:fd096eb7ffef17c456cfa587523c5f92321ae02427ff955bebe9e3c63bc9f0da"}, - {file = "greenlet-3.0.3-cp38-cp38-win32.whl", hash = "sha256:d46677c85c5ba00a9cb6f7a00b2bfa6f812192d2c9f7d9c4f6a55b60216712f3"}, - {file = "greenlet-3.0.3-cp38-cp38-win_amd64.whl", hash = "sha256:419b386f84949bf0e7c73e6032e3457b82a787c1ab4a0e43732898a761cc9dbf"}, - {file = "greenlet-3.0.3-cp39-cp39-macosx_11_0_universal2.whl", hash = "sha256:da70d4d51c8b306bb7a031d5cff6cc25ad253affe89b70352af5f1cb68e74b53"}, - {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:086152f8fbc5955df88382e8a75984e2bb1c892ad2e3c80a2508954e52295257"}, - {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d73a9fe764d77f87f8ec26a0c85144d6a951a6c438dfe50487df5595c6373eac"}, - {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b7dcbe92cc99f08c8dd11f930de4d99ef756c3591a5377d1d9cd7dd5e896da71"}, - {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1551a8195c0d4a68fac7a4325efac0d541b48def35feb49d803674ac32582f61"}, - {file = "greenlet-3.0.3-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:64d7675ad83578e3fc149b617a444fab8efdafc9385471f868eb5ff83e446b8b"}, - {file = "greenlet-3.0.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:b37eef18ea55f2ffd8f00ff8fe7c8d3818abd3e25fb73fae2ca3b672e333a7a6"}, - {file = "greenlet-3.0.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:77457465d89b8263bca14759d7c1684df840b6811b2499838cc5b040a8b5b113"}, - {file = "greenlet-3.0.3-cp39-cp39-win32.whl", hash = "sha256:57e8974f23e47dac22b83436bdcf23080ade568ce77df33159e019d161ce1d1e"}, - {file = "greenlet-3.0.3-cp39-cp39-win_amd64.whl", hash = "sha256:c5ee858cfe08f34712f548c3c363e807e7186f03ad7a5039ebadb29e8c6be067"}, - {file = "greenlet-3.0.3.tar.gz", hash = "sha256:43374442353259554ce33599da8b692d5aa96f8976d567d4badf263371fbe491"}, + {file = "greenlet-3.1.1-cp310-cp310-macosx_11_0_universal2.whl", hash = "sha256:0bbae94a29c9e5c7e4a2b7f0aae5c17e8e90acbfd3bf6270eeba60c39fce3563"}, + {file = "greenlet-3.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0fde093fb93f35ca72a556cf72c92ea3ebfda3d79fc35bb19fbe685853869a83"}, + {file = "greenlet-3.1.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:36b89d13c49216cadb828db8dfa6ce86bbbc476a82d3a6c397f0efae0525bdd0"}, + {file = "greenlet-3.1.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:94b6150a85e1b33b40b1464a3f9988dcc5251d6ed06842abff82e42632fac120"}, + {file = "greenlet-3.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:93147c513fac16385d1036b7e5b102c7fbbdb163d556b791f0f11eada7ba65dc"}, + {file = "greenlet-3.1.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:da7a9bff22ce038e19bf62c4dd1ec8391062878710ded0a845bcf47cc0200617"}, + {file = "greenlet-3.1.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:b2795058c23988728eec1f36a4e5e4ebad22f8320c85f3587b539b9ac84128d7"}, + {file = "greenlet-3.1.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:ed10eac5830befbdd0c32f83e8aa6288361597550ba669b04c48f0f9a2c843c6"}, + {file = "greenlet-3.1.1-cp310-cp310-win_amd64.whl", hash = "sha256:77c386de38a60d1dfb8e55b8c1101d68c79dfdd25c7095d51fec2dd800892b80"}, + {file = "greenlet-3.1.1-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:e4d333e558953648ca09d64f13e6d8f0523fa705f51cae3f03b5983489958c70"}, + {file = "greenlet-3.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:09fc016b73c94e98e29af67ab7b9a879c307c6731a2c9da0db5a7d9b7edd1159"}, + {file = "greenlet-3.1.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d5e975ca70269d66d17dd995dafc06f1b06e8cb1ec1e9ed54c1d1e4a7c4cf26e"}, + {file = "greenlet-3.1.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3b2813dc3de8c1ee3f924e4d4227999285fd335d1bcc0d2be6dc3f1f6a318ec1"}, + {file = "greenlet-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e347b3bfcf985a05e8c0b7d462ba6f15b1ee1c909e2dcad795e49e91b152c383"}, + {file = "greenlet-3.1.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9e8f8c9cb53cdac7ba9793c276acd90168f416b9ce36799b9b885790f8ad6c0a"}, + {file = "greenlet-3.1.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:62ee94988d6b4722ce0028644418d93a52429e977d742ca2ccbe1c4f4a792511"}, + {file = "greenlet-3.1.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:1776fd7f989fc6b8d8c8cb8da1f6b82c5814957264d1f6cf818d475ec2bf6395"}, + {file = "greenlet-3.1.1-cp311-cp311-win_amd64.whl", hash = "sha256:48ca08c771c268a768087b408658e216133aecd835c0ded47ce955381105ba39"}, + {file = "greenlet-3.1.1-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:4afe7ea89de619adc868e087b4d2359282058479d7cfb94970adf4b55284574d"}, + {file = "greenlet-3.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f406b22b7c9a9b4f8aa9d2ab13d6ae0ac3e85c9a809bd590ad53fed2bf70dc79"}, + {file = "greenlet-3.1.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c3a701fe5a9695b238503ce5bbe8218e03c3bcccf7e204e455e7462d770268aa"}, + {file = "greenlet-3.1.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2846930c65b47d70b9d178e89c7e1a69c95c1f68ea5aa0a58646b7a96df12441"}, + {file = "greenlet-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:99cfaa2110534e2cf3ba31a7abcac9d328d1d9f1b95beede58294a60348fba36"}, + {file = "greenlet-3.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1443279c19fca463fc33e65ef2a935a5b09bb90f978beab37729e1c3c6c25fe9"}, + {file = "greenlet-3.1.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:b7cede291382a78f7bb5f04a529cb18e068dd29e0fb27376074b6d0317bf4dd0"}, + {file = "greenlet-3.1.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:23f20bb60ae298d7d8656c6ec6db134bca379ecefadb0b19ce6f19d1f232a942"}, + {file = "greenlet-3.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:7124e16b4c55d417577c2077be379514321916d5790fa287c9ed6f23bd2ffd01"}, + {file = "greenlet-3.1.1-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:05175c27cb459dcfc05d026c4232f9de8913ed006d42713cb8a5137bd49375f1"}, + {file = "greenlet-3.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:935e943ec47c4afab8965954bf49bfa639c05d4ccf9ef6e924188f762145c0ff"}, + {file = "greenlet-3.1.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:667a9706c970cb552ede35aee17339a18e8f2a87a51fba2ed39ceeeb1004798a"}, + {file = "greenlet-3.1.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b8a678974d1f3aa55f6cc34dc480169d58f2e6d8958895d68845fa4ab566509e"}, + {file = "greenlet-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:efc0f674aa41b92da8c49e0346318c6075d734994c3c4e4430b1c3f853e498e4"}, + {file = "greenlet-3.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0153404a4bb921f0ff1abeb5ce8a5131da56b953eda6e14b88dc6bbc04d2049e"}, + {file = "greenlet-3.1.1-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:275f72decf9932639c1c6dd1013a1bc266438eb32710016a1c742df5da6e60a1"}, + {file = "greenlet-3.1.1-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:c4aab7f6381f38a4b42f269057aee279ab0fc7bf2e929e3d4abfae97b682a12c"}, + {file = "greenlet-3.1.1-cp313-cp313-win_amd64.whl", hash = "sha256:b42703b1cf69f2aa1df7d1030b9d77d3e584a70755674d60e710f0af570f3761"}, + {file = "greenlet-3.1.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f1695e76146579f8c06c1509c7ce4dfe0706f49c6831a817ac04eebb2fd02011"}, + {file = "greenlet-3.1.1-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7876452af029456b3f3549b696bb36a06db7c90747740c5302f74a9e9fa14b13"}, + {file = "greenlet-3.1.1-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4ead44c85f8ab905852d3de8d86f6f8baf77109f9da589cb4fa142bd3b57b475"}, + {file = "greenlet-3.1.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8320f64b777d00dd7ccdade271eaf0cad6636343293a25074cc5566160e4de7b"}, + {file = "greenlet-3.1.1-cp313-cp313t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6510bf84a6b643dabba74d3049ead221257603a253d0a9873f55f6a59a65f822"}, + {file = "greenlet-3.1.1-cp313-cp313t-musllinux_1_1_aarch64.whl", hash = "sha256:04b013dc07c96f83134b1e99888e7a79979f1a247e2a9f59697fa14b5862ed01"}, + {file = "greenlet-3.1.1-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:411f015496fec93c1c8cd4e5238da364e1da7a124bcb293f085bf2860c32c6f6"}, + {file = "greenlet-3.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:47da355d8687fd65240c364c90a31569a133b7b60de111c255ef5b606f2ae291"}, + {file = "greenlet-3.1.1-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:98884ecf2ffb7d7fe6bd517e8eb99d31ff7855a840fa6d0d63cd07c037f6a981"}, + {file = "greenlet-3.1.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f1d4aeb8891338e60d1ab6127af1fe45def5259def8094b9c7e34690c8858803"}, + {file = "greenlet-3.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db32b5348615a04b82240cc67983cb315309e88d444a288934ee6ceaebcad6cc"}, + {file = "greenlet-3.1.1-cp37-cp37m-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:dcc62f31eae24de7f8dce72134c8651c58000d3b1868e01392baea7c32c247de"}, + {file = "greenlet-3.1.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:1d3755bcb2e02de341c55b4fca7a745a24a9e7212ac953f6b3a48d117d7257aa"}, + {file = "greenlet-3.1.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:b8da394b34370874b4572676f36acabac172602abf054cbc4ac910219f3340af"}, + {file = "greenlet-3.1.1-cp37-cp37m-win32.whl", hash = "sha256:a0dfc6c143b519113354e780a50381508139b07d2177cb6ad6a08278ec655798"}, + {file = "greenlet-3.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:54558ea205654b50c438029505def3834e80f0869a70fb15b871c29b4575ddef"}, + {file = "greenlet-3.1.1-cp38-cp38-macosx_11_0_universal2.whl", hash = "sha256:346bed03fe47414091be4ad44786d1bd8bef0c3fcad6ed3dee074a032ab408a9"}, + {file = "greenlet-3.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:dfc59d69fc48664bc693842bd57acfdd490acafda1ab52c7836e3fc75c90a111"}, + {file = "greenlet-3.1.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d21e10da6ec19b457b82636209cbe2331ff4306b54d06fa04b7c138ba18c8a81"}, + {file = "greenlet-3.1.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:37b9de5a96111fc15418819ab4c4432e4f3c2ede61e660b1e33971eba26ef9ba"}, + {file = "greenlet-3.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6ef9ea3f137e5711f0dbe5f9263e8c009b7069d8a1acea822bd5e9dae0ae49c8"}, + {file = "greenlet-3.1.1-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:85f3ff71e2e60bd4b4932a043fbbe0f499e263c628390b285cb599154a3b03b1"}, + {file = "greenlet-3.1.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:95ffcf719966dd7c453f908e208e14cde192e09fde6c7186c8f1896ef778d8cd"}, + {file = "greenlet-3.1.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:03a088b9de532cbfe2ba2034b2b85e82df37874681e8c470d6fb2f8c04d7e4b7"}, + {file = "greenlet-3.1.1-cp38-cp38-win32.whl", hash = "sha256:8b8b36671f10ba80e159378df9c4f15c14098c4fd73a36b9ad715f057272fbef"}, + {file = "greenlet-3.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:7017b2be767b9d43cc31416aba48aab0d2309ee31b4dbf10a1d38fb7972bdf9d"}, + {file = "greenlet-3.1.1-cp39-cp39-macosx_11_0_universal2.whl", hash = "sha256:396979749bd95f018296af156201d6211240e7a23090f50a8d5d18c370084dc3"}, + {file = "greenlet-3.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ca9d0ff5ad43e785350894d97e13633a66e2b50000e8a183a50a88d834752d42"}, + {file = "greenlet-3.1.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f6ff3b14f2df4c41660a7dec01045a045653998784bf8cfcb5a525bdffffbc8f"}, + {file = "greenlet-3.1.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:94ebba31df2aa506d7b14866fed00ac141a867e63143fe5bca82a8e503b36437"}, + {file = "greenlet-3.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:73aaad12ac0ff500f62cebed98d8789198ea0e6f233421059fa68a5aa7220145"}, + {file = "greenlet-3.1.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:63e4844797b975b9af3a3fb8f7866ff08775f5426925e1e0bbcfe7932059a12c"}, + {file = "greenlet-3.1.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:7939aa3ca7d2a1593596e7ac6d59391ff30281ef280d8632fa03d81f7c5f955e"}, + {file = "greenlet-3.1.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:d0028e725ee18175c6e422797c407874da24381ce0690d6b9396c204c7f7276e"}, + {file = "greenlet-3.1.1-cp39-cp39-win32.whl", hash = "sha256:5e06afd14cbaf9e00899fae69b24a32f2196c19de08fcb9f4779dd4f004e5e7c"}, + {file = "greenlet-3.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:3319aa75e0e0639bc15ff54ca327e8dc7a6fe404003496e3c6925cd3142e0e22"}, + {file = "greenlet-3.1.1.tar.gz", hash = "sha256:4ce3ac6cdb6adf7946475d7ef31777c26d94bccc377e070a7986bd2d5c515467"}, ] [package.extras] @@ -925,13 +940,13 @@ toml = "*" [[package]] name = "mako" -version = "1.3.5" +version = "1.3.6" description = "A super-fast templating language that borrows the best ideas from the existing templating languages." optional = false python-versions = ">=3.8" files = [ - {file = "Mako-1.3.5-py3-none-any.whl", hash = "sha256:260f1dbc3a519453a9c856dedfe4beb4e50bd5a26d96386cb6c80856556bb91a"}, - {file = "Mako-1.3.5.tar.gz", hash = "sha256:48dbc20568c1d276a2698b36d968fa76161bf127194907ea6fc594fa81f943bc"}, + {file = "Mako-1.3.6-py3-none-any.whl", hash = "sha256:a91198468092a2f1a0de86ca92690fb0cfc43ca90ee17e15d93662b4c04b241a"}, + {file = "mako-1.3.6.tar.gz", hash = "sha256:9ec3a1583713479fae654f83ed9fa8c9a4c16b7bb0daba0e6bbebff50c0d983d"}, ] [package.dependencies] @@ -1063,22 +1078,22 @@ type = ["mypy (>=1.11.2)"] [[package]] name = "playwright" -version = "1.47.0" +version = "1.48.0" description = "A high-level API to automate web browsers" optional = false python-versions = ">=3.8" files = [ - {file = "playwright-1.47.0-py3-none-macosx_10_13_x86_64.whl", hash = "sha256:f205df24edb925db1a4ab62f1ab0da06f14bb69e382efecfb0deedc4c7f4b8cd"}, - {file = "playwright-1.47.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:7fc820faf6885f69a52ba4ec94124e575d3c4a4003bf29200029b4a4f2b2d0ab"}, - {file = "playwright-1.47.0-py3-none-macosx_11_0_universal2.whl", hash = "sha256:8e212dc472ff19c7d46ed7e900191c7a786ce697556ac3f1615986ec3aa00341"}, - {file = "playwright-1.47.0-py3-none-manylinux1_x86_64.whl", hash = "sha256:a1935672531963e4b2a321de5aa59b982fb92463ee6e1032dd7326378e462955"}, - {file = "playwright-1.47.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e0a1b61473d6f7f39c5d77d4800b3cbefecb03344c90b98f3fbcae63294ad249"}, - {file = "playwright-1.47.0-py3-none-win32.whl", hash = "sha256:1b977ed81f6bba5582617684a21adab9bad5676d90a357ebf892db7bdf4a9974"}, - {file = "playwright-1.47.0-py3-none-win_amd64.whl", hash = "sha256:0ec1056042d2e86088795a503347407570bffa32cbe20748e5d4c93dba085280"}, + {file = "playwright-1.48.0-py3-none-macosx_10_13_x86_64.whl", hash = "sha256:082bce2739f1078acc7d0734da8cc0e23eb91b7fae553f3316d733276f09a6b1"}, + {file = "playwright-1.48.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:7da2eb51a19c7f3b523e9faa9d98e7af92e52eb983a099979ea79c9668e3cbf7"}, + {file = "playwright-1.48.0-py3-none-macosx_11_0_universal2.whl", hash = "sha256:115b988d1da322358b77bc3bf2d3cc90f8c881e691461538e7df91614c4833c9"}, + {file = "playwright-1.48.0-py3-none-manylinux1_x86_64.whl", hash = "sha256:8dabb80e62f667fe2640a8b694e26a7b884c0b4803f7514a3954fc849126227b"}, + {file = "playwright-1.48.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8ff8303409ebed76bed4c3d655340320b768817d900ba208b394fdd7d7939a5c"}, + {file = "playwright-1.48.0-py3-none-win32.whl", hash = "sha256:85598c360c590076d4f435525be991246d74a905b654ac19d26eab7ed9b98b2d"}, + {file = "playwright-1.48.0-py3-none-win_amd64.whl", hash = "sha256:e0e87b0c4dc8fce83c725dd851aec37bc4e882bb225ec8a96bd83cf32d4f1623"}, ] [package.dependencies] -greenlet = "3.0.3" +greenlet = "3.1.1" pyee = "12.0.0" [[package]] @@ -1449,6 +1464,23 @@ pytest = "==8.*" [package.extras] testing = ["pytest-asyncio (==0.24.*)", "pytest-cov (==5.*)"] +[[package]] +name = "pytest-mock" +version = "3.14.0" +description = "Thin-wrapper around the mock package for easier use with pytest" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-mock-3.14.0.tar.gz", hash = "sha256:2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0"}, + {file = "pytest_mock-3.14.0-py3-none-any.whl", hash = "sha256:0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f"}, +] + +[package.dependencies] +pytest = ">=6.2.5" + +[package.extras] +dev = ["pre-commit", "pytest-asyncio", "tox"] + [[package]] name = "pytest-playwright" version = "0.5.2" @@ -2320,4 +2352,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "8a20e80ea6ad4f182e0f57c6956647fb3c6a28618cf62e433deb9363d8beff09" +content-hash = "da036223de719ddbacfb13ef79aa4e952767cc3e3b7fdb1c46de75f0ab594b3e" diff --git a/pyproject.toml b/pyproject.toml index 5c45370e..97e4c54a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ sqlalchemy = "^2.0.36" sqlalchemy-utils = "^0.41.2" liccheck = "^0.9.2" authlib = "^1.3.2" +pytest-mock = "^3.14.0" [tool.poetry.group.test.dependencies] diff --git a/tests/api/routes/test_project.py b/tests/api/routes/test_project.py index 46ffc03b..902b6225 100644 --- a/tests/api/routes/test_project.py +++ b/tests/api/routes/test_project.py @@ -8,6 +8,7 @@ from tests.constants import default_project, default_task from tests.database_test_utils import DatabaseTestUtils +from fastapi_csrf_protect import CsrfProtect # type: ignore # noqa def test_get_unknown_project(client: TestClient) -> None: @@ -232,10 +233,11 @@ def test_get_project_cancel(client: TestClient, db: DatabaseTestUtils) -> None: assert b"lifecycle" in response.content -def test_get_project_update(client: TestClient, mock_csrf: Generator[None, None, None], db: DatabaseTestUtils) -> None: +def test_get_project_update(client: TestClient, mocker, db: DatabaseTestUtils) -> None: # given db.given([default_project("testproject1")]) client.cookies["fastapi-csrf-token"] = "1" + CsrfProtect.validate_csrf = mocker.AsyncMock() # when response = client.put("/algorithm-system/1/update/name", json={"value": "Test Name"}, headers={"X-CSRF-Token": "1"}) diff --git a/tests/api/routes/test_projects.py b/tests/api/routes/test_projects.py index 353ba92f..1d8c857f 100644 --- a/tests/api/routes/test_projects.py +++ b/tests/api/routes/test_projects.py @@ -67,7 +67,10 @@ def test_get_new_projects(client: TestClient, init_instruments: Generator[None, ) -def test_post_new_projects_bad_request(client: TestClient, mock_csrf: Generator[None, None, None]) -> None: +def test_post_new_projects_bad_request(client: TestClient, mocker) -> None: + # given + CsrfProtect.validate_csrf = mocker.AsyncMock() + # when client.cookies["fastapi-csrf-token"] = "1" response = client.post("/algorithm-systems/new", json={}, headers={"X-CSRF-Token": "1"}) @@ -79,7 +82,7 @@ def test_post_new_projects_bad_request(client: TestClient, mock_csrf: Generator[ def test_post_new_projects( - client: TestClient, mock_csrf: Generator[None, None, None], init_instruments: Generator[None, None, None] + client: TestClient, mocker, init_instruments: Generator[None, None, None] ) -> None: client.cookies["fastapi-csrf-token"] = "1" new_project = ProjectNew( @@ -92,6 +95,8 @@ def test_post_new_projects( transparency_obligations="geen transparantieverplichtingen", role="gebruiksverantwoordelijke", ) + # given + CsrfProtect.validate_csrf = mocker.AsyncMock() # when response = client.post("/algorithm-systems/new", json=new_project.model_dump(), headers={"X-CSRF-Token": "1"}) @@ -104,12 +109,13 @@ def test_post_new_projects( def test_post_new_projects_write_system_card( client: TestClient, - mock_csrf: Generator[None, None, None], + mocker, init_instruments: Generator[None, None, None], db: DatabaseTestUtils, ) -> None: # Given client.cookies["fastapi-csrf-token"] = "1" + CsrfProtect.validate_csrf = mocker.AsyncMock() name = "name1" project_new = ProjectNew( diff --git a/tests/conftest.py b/tests/conftest.py index 652af62c..8cb8c2e3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -191,11 +191,3 @@ def db( with Session(engine, expire_on_commit=False) as session: yield DatabaseTestUtils(session, database_file) - - -@pytest.fixture -def mock_csrf() -> Generator[None, None, None]: # noqa: PT004 - original = CsrfProtect.validate_csrf - CsrfProtect.validate_csrf = AsyncMock() - yield - CsrfProtect.validate_csrf = original From 58b10a18466ed505d5c083d037915ab9b572a099 Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 22 Oct 2024 14:34:07 +0200 Subject: [PATCH 2/5] Correctly patch with mocker --- amt/cli/check_state.py | 7 +++---- tests/cli/test_check_state.py | 37 ++++++++++------------------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/amt/cli/check_state.py b/amt/cli/check_state.py index 0ff8f19d..3107b36b 100644 --- a/amt/cli/check_state.py +++ b/amt/cli/check_state.py @@ -1,5 +1,4 @@ import logging -import sys from pathlib import Path from typing import Any @@ -44,8 +43,8 @@ def get_tasks_by_priority(urns: list[str], system_card_path: Path) -> None: click.echo(task.urn) except yaml.YAMLError as error: click.echo(f"Sorry, an error occurred; yaml could not be parsed: {error}", err=True) - sys.exit(1) + click.Abort() except Exception as error: click.echo(f"Sorry, an error occurred. {error}", err=True) - sys.exit(1) - sys.exit(0) + click.Abort() + return diff --git a/tests/cli/test_check_state.py b/tests/cli/test_check_state.py index 3aa71d08..9d8e5ad1 100644 --- a/tests/cli/test_check_state.py +++ b/tests/cli/test_check_state.py @@ -37,18 +37,10 @@ def system_card(system_card_data: dict[str, Any]) -> SystemCard: return system_card -def test_get_system_card(system_card: SystemCard, system_card_data: dict[str, Any]): - init_orig = StorageFactory.init - - storage_mock = Mock() - storage_mock.read.return_value = system_card_data - StorageFactory.init = Mock(return_value=storage_mock) - +def test_get_system_card(system_card: SystemCard, system_card_data: dict[str, Any], mocker): + mocker.patch('amt.services.storage.StorageFactory.init', return_value=mocker.Mock(read=mocker.Mock(return_value=system_card_data))) assert system_card == amt.cli.check_state.get_system_card(Path("dummy")) - StorageFactory.init = init_orig - - def test_get_requested_instruments(): instrument0 = default_instrument(urn="instrument0") instrument1 = default_instrument(urn="instrument1") @@ -58,9 +50,7 @@ def test_get_requested_instruments(): assert expected == get_requested_instruments(all_instruments_cards, ["instrument0", "instrument2"]) -def test_cli(capsys: pytest.CaptureFixture[str], system_card: SystemCard): - fetch_instruments_orig = InstrumentsService.fetch_instruments - get_system_card_orig = amt.cli.check_state.get_system_card +def test_cli(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker): instrument = default_instrument( urn="urn:instrument:assessment", tasks=[ @@ -69,35 +59,28 @@ def test_cli(capsys: pytest.CaptureFixture[str], system_card: SystemCard): ], ) - return_value = [instrument] - InstrumentsService.fetch_instruments = Mock(return_value=return_value) - amt.cli.check_state.get_system_card = Mock(return_value=system_card) + mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , return_value=[instrument]) + mocker.patch('amt.cli.check_state.get_system_card', return_value=system_card) runner = CliRunner() # workaround for https://github.com/pallets/click/issues/824 with capsys.disabled() as _: result = runner.invoke(get_tasks_by_priority, ["urn:instrument:assessment", "example/system_test_card.yaml"]) # type: ignore assert "urn:instrument:assessment:task2" in result.output - InstrumentsService.fetch_instruments = fetch_instruments_orig - amt.cli.check_state.get_system_card = get_system_card_orig -def test_cli_with_exception(capsys: pytest.CaptureFixture[str], system_card: SystemCard): - fetch_instruments_orig = InstrumentsService.fetch_instruments - InstrumentsService.fetch_instruments = Mock(side_effect=AMTInstrumentError()) +def test_cli_with_exception(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker): + mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments', side_effect=AMTInstrumentError()) runner = CliRunner() # workaround for https://github.com/pallets/click/issues/824 with capsys.disabled() as _: result = runner.invoke(get_tasks_by_priority, ["urn:instrument:assessment", "example/system_test_card.yaml"]) # type: ignore - assert "Sorry, an error occurre" in result.output - InstrumentsService.fetch_instruments = fetch_instruments_orig + assert "Sorry, an error occurred" in result.output -def test_cli_with_exception_yaml(capsys: pytest.CaptureFixture[str], system_card: SystemCard): - read_orig = FileSystemStorageService.read - FileSystemStorageService.read = Mock(side_effect=YAMLError("Test error message")) +def test_cli_with_exception_yaml(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker): + mocker.patch('amt.services.storage.FileSystemStorageService.read' , side_effect=YAMLError("Test error message")) runner = CliRunner() # workaround for https://github.com/pallets/click/issues/824 with capsys.disabled() as _: result = runner.invoke(get_tasks_by_priority, ["urn:instrument:assessment", "example/system_test_card.yaml"]) # type: ignore assert "Sorry, an error occurred; yaml could not be parsed:" in result.output - FileSystemStorageService.read = read_orig From 591bb0c7ad084a4dfbdc819a36793f2340f75d1f Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 22 Oct 2024 14:35:39 +0200 Subject: [PATCH 3/5] clean-up imports --- tests/cli/test_check_state.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/cli/test_check_state.py b/tests/cli/test_check_state.py index 9d8e5ad1..258ccbc4 100644 --- a/tests/cli/test_check_state.py +++ b/tests/cli/test_check_state.py @@ -1,7 +1,6 @@ # pyright: reportUnknownMemberType=false, reportUnknownVariableType=false, reportAttributeAccessIssue=false from pathlib import Path from typing import Any -from unittest.mock import Mock import amt.services.instruments_and_requirements_state import pytest @@ -9,8 +8,6 @@ from amt.core.exceptions import AMTInstrumentError from amt.schema.instrument import InstrumentTask from amt.schema.system_card import SystemCard -from amt.services.instruments import InstrumentsService -from amt.services.storage import FileSystemStorageService, StorageFactory from click.testing import CliRunner from tests.constants import default_instrument from yaml import YAMLError From d9e73d48d81fd3cdb3479382b02100fcfe3ada25 Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 22 Oct 2024 15:08:05 +0200 Subject: [PATCH 4/5] Correct usage mocker for CSRFValidator --- tests/api/routes/test_deps.py | 5 ++-- tests/api/routes/test_project.py | 4 +-- tests/api/routes/test_projects.py | 37 ++++++++++++------------- tests/api/test_http_browser_caching.py | 9 ++---- tests/core/test_db.py | 5 ++-- tests/core/test_internationalization.py | 9 +++--- tests/services/test_projects_service.py | 18 ++++++------ 7 files changed, 36 insertions(+), 51 deletions(-) diff --git a/tests/api/routes/test_deps.py b/tests/api/routes/test_deps.py index 8b926ff4..f8cc971f 100644 --- a/tests/api/routes/test_deps.py +++ b/tests/api/routes/test_deps.py @@ -1,6 +1,5 @@ from collections.abc import Callable from enum import Enum -from unittest.mock import Mock import pytest from amt.api.deps import ( @@ -18,8 +17,8 @@ from fastapi import Request -def test_custom_context_processor(): - request: Request = Mock() +def test_custom_context_processor(mocker): + request: Request = mocker.Mock() request.cookies.get.return_value = "nl" request.headers.get.return_value = "nl" result = custom_context_processor(request) diff --git a/tests/api/routes/test_project.py b/tests/api/routes/test_project.py index 902b6225..a3f41109 100644 --- a/tests/api/routes/test_project.py +++ b/tests/api/routes/test_project.py @@ -8,8 +8,6 @@ from tests.constants import default_project, default_task from tests.database_test_utils import DatabaseTestUtils -from fastapi_csrf_protect import CsrfProtect # type: ignore # noqa - def test_get_unknown_project(client: TestClient) -> None: # when @@ -237,7 +235,7 @@ def test_get_project_update(client: TestClient, mocker, db: DatabaseTestUtils) - # given db.given([default_project("testproject1")]) client.cookies["fastapi-csrf-token"] = "1" - CsrfProtect.validate_csrf = mocker.AsyncMock() + mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf' , new_callable=mocker.AsyncMock) # when response = client.put("/algorithm-system/1/update/name", json={"value": "Test Name"}, headers={"X-CSRF-Token": "1"}) diff --git a/tests/api/routes/test_projects.py b/tests/api/routes/test_projects.py index 1d8c857f..22f2c628 100644 --- a/tests/api/routes/test_projects.py +++ b/tests/api/routes/test_projects.py @@ -1,34 +1,20 @@ from collections.abc import Generator from typing import cast -from unittest.mock import Mock -import pytest from amt.api.routes.projects import get_localized_value from amt.models import Project from amt.models.base import Base from amt.schema.ai_act_profile import AiActProfile from amt.schema.project import ProjectNew from amt.schema.system_card import SystemCard -from amt.services.instruments import InstrumentsService from amt.services.task_registry import get_requirements_and_measures from fastapi.requests import Request from fastapi.testclient import TestClient -from fastapi_csrf_protect import CsrfProtect # type: ignore # noqa from tests.constants import default_instrument from tests.database_test_utils import DatabaseTestUtils -@pytest.fixture -def init_instruments() -> Generator[None, None, None]: # noqa: PT004 - origin = InstrumentsService.fetch_instruments - InstrumentsService.fetch_instruments = Mock( - return_value=[default_instrument(urn="urn1", name="name1"), default_instrument(urn="urn2", name="name2")] - ) - yield - InstrumentsService.fetch_instruments = origin - - def test_projects_get_root(client: TestClient) -> None: response = client.get("/algorithm-systems/") @@ -50,7 +36,12 @@ def test_projects_get_root_htmx(client: TestClient) -> None: assert b'' not in response.content -def test_get_new_projects(client: TestClient, init_instruments: Generator[None, None, None]) -> None: +def test_get_new_projects(client: TestClient, mocker) -> None: + # given + mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , + return_value=[default_instrument(urn="urn1" , name="name1") , + default_instrument(urn="urn2" , name="name2")]) + # when response = client.get("/algorithm-systems/new") assert response.status_code == 200 @@ -69,7 +60,7 @@ def test_get_new_projects(client: TestClient, init_instruments: Generator[None, def test_post_new_projects_bad_request(client: TestClient, mocker) -> None: # given - CsrfProtect.validate_csrf = mocker.AsyncMock() + mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf' , new_callable=mocker.AsyncMock) # when client.cookies["fastapi-csrf-token"] = "1" @@ -82,7 +73,7 @@ def test_post_new_projects_bad_request(client: TestClient, mocker) -> None: def test_post_new_projects( - client: TestClient, mocker, init_instruments: Generator[None, None, None] + client: TestClient, mocker ) -> None: client.cookies["fastapi-csrf-token"] = "1" new_project = ProjectNew( @@ -96,7 +87,10 @@ def test_post_new_projects( role="gebruiksverantwoordelijke", ) # given - CsrfProtect.validate_csrf = mocker.AsyncMock() + mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf' , new_callable=mocker.AsyncMock) + mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , + return_value=[default_instrument(urn="urn1" , name="name1") , + default_instrument(urn="urn2" , name="name2")]) # when response = client.post("/algorithm-systems/new", json=new_project.model_dump(), headers={"X-CSRF-Token": "1"}) @@ -110,12 +104,15 @@ def test_post_new_projects( def test_post_new_projects_write_system_card( client: TestClient, mocker, - init_instruments: Generator[None, None, None], db: DatabaseTestUtils, ) -> None: # Given client.cookies["fastapi-csrf-token"] = "1" - CsrfProtect.validate_csrf = mocker.AsyncMock() + mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf', new_callable=mocker.AsyncMock) + mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , + return_value=[default_instrument(urn="urn1" , name="name1") , + default_instrument(urn="urn2" , name="name2")]) + name = "name1" project_new = ProjectNew( diff --git a/tests/api/test_http_browser_caching.py b/tests/api/test_http_browser_caching.py index e2e51565..a5f32f76 100644 --- a/tests/api/test_http_browser_caching.py +++ b/tests/api/test_http_browser_caching.py @@ -1,7 +1,6 @@ import os from pathlib import Path from typing import NamedTuple -from unittest.mock import Mock import pytest from amt.api import http_browser_caching @@ -24,24 +23,20 @@ def test_url_for_cache_file_not_found(): http_browser_caching.url_for_cache("static", path="this/does/not/exist") -def test_url_for_cache_file_happy_flow(tmp_path: Path): +def test_url_for_cache_file_happy_flow(tmp_path: Path, mocker): class MockStatResult(NamedTuple): st_mtime: int st_size: int - lookup_path_orig = http_browser_caching.static_files.lookup_path (tmp_path / "testfile").write_text("This is a test", encoding="utf-8") http_browser_caching.static_files = http_browser_caching.StaticFilesCache(directory=Path(tmp_path)) - http_browser_caching.static_files.lookup_path = Mock(os.stat_result, return_value=(None, MockStatResult(1, 2))) + mocker.patch('amt.api.http_browser_caching.static_files.lookup_path', return_value=(None, MockStatResult(1, 2))) result = http_browser_caching.url_for_cache("static", path="testfile") assert result == "/static/testfile?etag=98c6f2c2287f4c73cea3d40ae7ec3ff2" # also test with a query param result = http_browser_caching.url_for_cache("static", path="testfile?queryparam1=true") assert result == "/static/testfile?queryparam1=true&etag=98c6f2c2287f4c73cea3d40ae7ec3ff2" - http_browser_caching.static_files.lookup_path = lookup_path_orig - - def test_static_files_class_immutable(tmp_path: Path): testfile = tmp_path / "testfile" testfile.write_text("This is a test", encoding="utf-8") diff --git a/tests/core/test_db.py b/tests/core/test_db.py index 1bf2773e..fd07cea3 100644 --- a/tests/core/test_db.py +++ b/tests/core/test_db.py @@ -1,6 +1,5 @@ import logging from pathlib import Path -from unittest.mock import MagicMock import pytest from amt.core.db import ( @@ -12,11 +11,11 @@ logger = logging.getLogger(__name__) -def test_check_database(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): +def test_check_database(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, mocker): database_file = tmp_path / "database.sqlite3" monkeypatch.setenv("APP_DATABASE_FILE", str(database_file)) org_exec = Session.execute - Session.execute = MagicMock() + Session.execute = mocker.MagicMock() check_db() assert Session.execute.call_args is not None diff --git a/tests/core/test_internationalization.py b/tests/core/test_internationalization.py index a8e7cba5..2d607692 100644 --- a/tests/core/test_internationalization.py +++ b/tests/core/test_internationalization.py @@ -1,5 +1,4 @@ from datetime import UTC, datetime, timedelta, timezone -from unittest.mock import Mock import pytest from amt.core.internationalization import ( @@ -87,15 +86,15 @@ def test_time_ago(): assert time_ago(past_date, locale) == expected -def test_get_requested_language(): - request: Request = Mock() +def test_get_requested_language(mocker): + request: Request = mocker.Mock() request.cookies.get.return_value = "nl" request.headers.get.return_value = "nl" assert get_requested_language(request) == "nl" -def test_fallback_get_requested_language(): - request: Request = Mock() +def test_fallback_get_requested_language(mocker): + request: Request = mocker.Mock() request.headers.get.return_value = "en" request.cookies = {} assert get_requested_language(request) == "en" diff --git a/tests/services/test_projects_service.py b/tests/services/test_projects_service.py index 5771d64a..15993e14 100644 --- a/tests/services/test_projects_service.py +++ b/tests/services/test_projects_service.py @@ -1,5 +1,3 @@ -from unittest.mock import Mock - from amt.models.project import Project from amt.repositories.projects import ProjectsRepository from amt.schema.project import ProjectNew @@ -10,15 +8,15 @@ from tests.constants import default_instrument -def test_get_project(): +def test_get_project(mocker): # Given project_id = 1 project_name = "Project 1" project_lifecycle = "development" projects_service = ProjectsService( - repository=Mock(spec=ProjectsRepository), - task_service=Mock(spec=TasksService), - instrument_service=Mock(spec=InstrumentsService), + repository=mocker.Mock(spec=ProjectsRepository), + task_service=mocker.Mock(spec=TasksService), + instrument_service=mocker.Mock(spec=InstrumentsService), ) projects_service.repository.find_by_id.return_value = Project( # type: ignore id=project_id, name=project_name, lifecycle=project_lifecycle @@ -34,16 +32,16 @@ def test_get_project(): projects_service.repository.find_by_id.assert_called_once_with(project_id) # type: ignore -def test_create_project(): +def test_create_project(mocker): project_id = 1 project_name = "Project 1" project_lifecycle = "development" system_card = SystemCard(name=project_name) projects_service = ProjectsService( - repository=Mock(spec=ProjectsRepository), - task_service=Mock(spec=TasksService), - instrument_service=Mock(spec=InstrumentsService), + repository=mocker.Mock(spec=ProjectsRepository), + task_service=mocker.Mock(spec=TasksService), + instrument_service=mocker.Mock(spec=InstrumentsService), ) projects_service.repository.save.return_value = Project( # type: ignore id=project_id, name=project_name, lifecycle=project_lifecycle, system_card=system_card From 95fa417f5eb50860f333e21f7a7d7a184be12356 Mon Sep 17 00:00:00 2001 From: Laurens Weijs Date: Tue, 22 Oct 2024 15:14:59 +0200 Subject: [PATCH 5/5] Cleanup --- tests/api/routes/test_deps.py | 3 +- tests/api/routes/test_project.py | 7 +++-- tests/api/routes/test_projects.py | 40 ++++++++++++------------- tests/api/test_http_browser_caching.py | 6 ++-- tests/cli/test_check_state.py | 23 ++++++++------ tests/conftest.py | 2 -- tests/core/test_db.py | 3 +- tests/core/test_internationalization.py | 5 ++-- tests/services/test_projects_service.py | 5 ++-- 9 files changed, 52 insertions(+), 42 deletions(-) diff --git a/tests/api/routes/test_deps.py b/tests/api/routes/test_deps.py index f8cc971f..45010b33 100644 --- a/tests/api/routes/test_deps.py +++ b/tests/api/routes/test_deps.py @@ -15,9 +15,10 @@ from amt.core.internationalization import supported_translations from amt.schema.localized_value_item import LocalizedValueItem from fastapi import Request +from pytest_mock import MockerFixture -def test_custom_context_processor(mocker): +def test_custom_context_processor(mocker: MockerFixture): request: Request = mocker.Mock() request.cookies.get.return_value = "nl" request.headers.get.return_value = "nl" diff --git a/tests/api/routes/test_project.py b/tests/api/routes/test_project.py index a3f41109..463ba775 100644 --- a/tests/api/routes/test_project.py +++ b/tests/api/routes/test_project.py @@ -1,14 +1,15 @@ -from collections.abc import Generator from typing import Any import pytest from amt.api.routes.project import set_path from amt.models import Project from fastapi.testclient import TestClient +from pytest_mock import MockFixture from tests.constants import default_project, default_task from tests.database_test_utils import DatabaseTestUtils + def test_get_unknown_project(client: TestClient) -> None: # when response = client.get("/algorithm-system/1") @@ -231,11 +232,11 @@ def test_get_project_cancel(client: TestClient, db: DatabaseTestUtils) -> None: assert b"lifecycle" in response.content -def test_get_project_update(client: TestClient, mocker, db: DatabaseTestUtils) -> None: +def test_get_project_update(client: TestClient, mocker: MockFixture, db: DatabaseTestUtils) -> None: # given db.given([default_project("testproject1")]) client.cookies["fastapi-csrf-token"] = "1" - mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf' , new_callable=mocker.AsyncMock) + mocker.patch("fastapi_csrf_protect.CsrfProtect.validate_csrf", new_callable=mocker.AsyncMock) # when response = client.put("/algorithm-system/1/update/name", json={"value": "Test Name"}, headers={"X-CSRF-Token": "1"}) diff --git a/tests/api/routes/test_projects.py b/tests/api/routes/test_projects.py index 22f2c628..e1bf9dee 100644 --- a/tests/api/routes/test_projects.py +++ b/tests/api/routes/test_projects.py @@ -1,4 +1,3 @@ -from collections.abc import Generator from typing import cast from amt.api.routes.projects import get_localized_value @@ -10,6 +9,7 @@ from amt.services.task_registry import get_requirements_and_measures from fastapi.requests import Request from fastapi.testclient import TestClient +from pytest_mock import MockFixture from tests.constants import default_instrument from tests.database_test_utils import DatabaseTestUtils @@ -36,11 +36,12 @@ def test_projects_get_root_htmx(client: TestClient) -> None: assert b'
' not in response.content -def test_get_new_projects(client: TestClient, mocker) -> None: +def test_get_new_projects(client: TestClient, mocker: MockFixture) -> None: # given - mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , - return_value=[default_instrument(urn="urn1" , name="name1") , - default_instrument(urn="urn2" , name="name2")]) + mocker.patch( + "amt.services.instruments.InstrumentsService.fetch_instruments", + return_value=[default_instrument(urn="urn1", name="name1"), default_instrument(urn="urn2", name="name2")], + ) # when response = client.get("/algorithm-systems/new") @@ -58,9 +59,9 @@ def test_get_new_projects(client: TestClient, mocker) -> None: ) -def test_post_new_projects_bad_request(client: TestClient, mocker) -> None: +def test_post_new_projects_bad_request(client: TestClient, mocker: MockFixture) -> None: # given - mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf' , new_callable=mocker.AsyncMock) + mocker.patch("fastapi_csrf_protect.CsrfProtect.validate_csrf", new_callable=mocker.AsyncMock) # when client.cookies["fastapi-csrf-token"] = "1" @@ -72,9 +73,7 @@ def test_post_new_projects_bad_request(client: TestClient, mocker) -> None: assert b"name: Field required" in response.content -def test_post_new_projects( - client: TestClient, mocker -) -> None: +def test_post_new_projects(client: TestClient, mocker: MockFixture) -> None: client.cookies["fastapi-csrf-token"] = "1" new_project = ProjectNew( name="default project", @@ -87,10 +86,11 @@ def test_post_new_projects( role="gebruiksverantwoordelijke", ) # given - mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf' , new_callable=mocker.AsyncMock) - mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , - return_value=[default_instrument(urn="urn1" , name="name1") , - default_instrument(urn="urn2" , name="name2")]) + mocker.patch("fastapi_csrf_protect.CsrfProtect.validate_csrf", new_callable=mocker.AsyncMock) + mocker.patch( + "amt.services.instruments.InstrumentsService.fetch_instruments", + return_value=[default_instrument(urn="urn1", name="name1"), default_instrument(urn="urn2", name="name2")], + ) # when response = client.post("/algorithm-systems/new", json=new_project.model_dump(), headers={"X-CSRF-Token": "1"}) @@ -103,16 +103,16 @@ def test_post_new_projects( def test_post_new_projects_write_system_card( client: TestClient, - mocker, + mocker: MockFixture, db: DatabaseTestUtils, ) -> None: # Given client.cookies["fastapi-csrf-token"] = "1" - mocker.patch('fastapi_csrf_protect.CsrfProtect.validate_csrf', new_callable=mocker.AsyncMock) - mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , - return_value=[default_instrument(urn="urn1" , name="name1") , - default_instrument(urn="urn2" , name="name2")]) - + mocker.patch("fastapi_csrf_protect.CsrfProtect.validate_csrf", new_callable=mocker.AsyncMock) + mocker.patch( + "amt.services.instruments.InstrumentsService.fetch_instruments", + return_value=[default_instrument(urn="urn1", name="name1"), default_instrument(urn="urn2", name="name2")], + ) name = "name1" project_new = ProjectNew( diff --git a/tests/api/test_http_browser_caching.py b/tests/api/test_http_browser_caching.py index a5f32f76..97d00a00 100644 --- a/tests/api/test_http_browser_caching.py +++ b/tests/api/test_http_browser_caching.py @@ -5,6 +5,7 @@ import pytest from amt.api import http_browser_caching from amt.core.exceptions import AMTNotFound, AMTOnlyStatic +from pytest_mock import MockerFixture from starlette.responses import Response @@ -23,20 +24,21 @@ def test_url_for_cache_file_not_found(): http_browser_caching.url_for_cache("static", path="this/does/not/exist") -def test_url_for_cache_file_happy_flow(tmp_path: Path, mocker): +def test_url_for_cache_file_happy_flow(tmp_path: Path, mocker: MockerFixture): class MockStatResult(NamedTuple): st_mtime: int st_size: int (tmp_path / "testfile").write_text("This is a test", encoding="utf-8") http_browser_caching.static_files = http_browser_caching.StaticFilesCache(directory=Path(tmp_path)) - mocker.patch('amt.api.http_browser_caching.static_files.lookup_path', return_value=(None, MockStatResult(1, 2))) + mocker.patch("amt.api.http_browser_caching.static_files.lookup_path", return_value=(None, MockStatResult(1, 2))) result = http_browser_caching.url_for_cache("static", path="testfile") assert result == "/static/testfile?etag=98c6f2c2287f4c73cea3d40ae7ec3ff2" # also test with a query param result = http_browser_caching.url_for_cache("static", path="testfile?queryparam1=true") assert result == "/static/testfile?queryparam1=true&etag=98c6f2c2287f4c73cea3d40ae7ec3ff2" + def test_static_files_class_immutable(tmp_path: Path): testfile = tmp_path / "testfile" testfile.write_text("This is a test", encoding="utf-8") diff --git a/tests/cli/test_check_state.py b/tests/cli/test_check_state.py index 258ccbc4..22bfa973 100644 --- a/tests/cli/test_check_state.py +++ b/tests/cli/test_check_state.py @@ -9,6 +9,7 @@ from amt.schema.instrument import InstrumentTask from amt.schema.system_card import SystemCard from click.testing import CliRunner +from pytest_mock import MockerFixture from tests.constants import default_instrument from yaml import YAMLError @@ -34,10 +35,14 @@ def system_card(system_card_data: dict[str, Any]) -> SystemCard: return system_card -def test_get_system_card(system_card: SystemCard, system_card_data: dict[str, Any], mocker): - mocker.patch('amt.services.storage.StorageFactory.init', return_value=mocker.Mock(read=mocker.Mock(return_value=system_card_data))) +def test_get_system_card(system_card: SystemCard, system_card_data: dict[str, Any], mocker: MockerFixture): + mocker.patch( + "amt.services.storage.StorageFactory.init", + return_value=mocker.Mock(read=mocker.Mock(return_value=system_card_data)), + ) assert system_card == amt.cli.check_state.get_system_card(Path("dummy")) + def test_get_requested_instruments(): instrument0 = default_instrument(urn="instrument0") instrument1 = default_instrument(urn="instrument1") @@ -47,7 +52,7 @@ def test_get_requested_instruments(): assert expected == get_requested_instruments(all_instruments_cards, ["instrument0", "instrument2"]) -def test_cli(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker): +def test_cli(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker: MockerFixture): instrument = default_instrument( urn="urn:instrument:assessment", tasks=[ @@ -56,8 +61,8 @@ def test_cli(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker ], ) - mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments' , return_value=[instrument]) - mocker.patch('amt.cli.check_state.get_system_card', return_value=system_card) + mocker.patch("amt.services.instruments.InstrumentsService.fetch_instruments", return_value=[instrument]) + mocker.patch("amt.cli.check_state.get_system_card", return_value=system_card) runner = CliRunner() # workaround for https://github.com/pallets/click/issues/824 with capsys.disabled() as _: @@ -65,8 +70,8 @@ def test_cli(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker assert "urn:instrument:assessment:task2" in result.output -def test_cli_with_exception(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker): - mocker.patch('amt.services.instruments.InstrumentsService.fetch_instruments', side_effect=AMTInstrumentError()) +def test_cli_with_exception(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker: MockerFixture): + mocker.patch("amt.services.instruments.InstrumentsService.fetch_instruments", side_effect=AMTInstrumentError()) runner = CliRunner() # workaround for https://github.com/pallets/click/issues/824 with capsys.disabled() as _: @@ -74,8 +79,8 @@ def test_cli_with_exception(capsys: pytest.CaptureFixture[str], system_card: Sys assert "Sorry, an error occurred" in result.output -def test_cli_with_exception_yaml(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker): - mocker.patch('amt.services.storage.FileSystemStorageService.read' , side_effect=YAMLError("Test error message")) +def test_cli_with_exception_yaml(capsys: pytest.CaptureFixture[str], system_card: SystemCard, mocker: MockerFixture): + mocker.patch("amt.services.storage.FileSystemStorageService.read", side_effect=YAMLError("Test error message")) runner = CliRunner() # workaround for https://github.com/pallets/click/issues/824 with capsys.disabled() as _: diff --git a/tests/conftest.py b/tests/conftest.py index 8cb8c2e3..25b57bde 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,6 @@ from multiprocessing import Process from pathlib import Path from typing import Any -from unittest.mock import AsyncMock import httpx import pytest @@ -13,7 +12,6 @@ from amt.models.base import Base from amt.server import create_app from fastapi.testclient import TestClient -from fastapi_csrf_protect import CsrfProtect # type: ignore from playwright.sync_api import Browser from sqlalchemy import create_engine, text from sqlalchemy.orm import Session diff --git a/tests/core/test_db.py b/tests/core/test_db.py index fd07cea3..83036149 100644 --- a/tests/core/test_db.py +++ b/tests/core/test_db.py @@ -5,13 +5,14 @@ from amt.core.db import ( check_db, ) +from pytest_mock import MockFixture from sqlalchemy import select from sqlalchemy.orm import Session logger = logging.getLogger(__name__) -def test_check_database(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, mocker): +def test_check_database(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, mocker: MockFixture): database_file = tmp_path / "database.sqlite3" monkeypatch.setenv("APP_DATABASE_FILE", str(database_file)) org_exec = Session.execute diff --git a/tests/core/test_internationalization.py b/tests/core/test_internationalization.py index 2d607692..3cb634ef 100644 --- a/tests/core/test_internationalization.py +++ b/tests/core/test_internationalization.py @@ -13,6 +13,7 @@ from babel.support import Translations from fastapi import Request from freezegun import freeze_time +from pytest_mock import MockFixture def test_get_supported_translations(): @@ -86,14 +87,14 @@ def test_time_ago(): assert time_ago(past_date, locale) == expected -def test_get_requested_language(mocker): +def test_get_requested_language(mocker: MockFixture): request: Request = mocker.Mock() request.cookies.get.return_value = "nl" request.headers.get.return_value = "nl" assert get_requested_language(request) == "nl" -def test_fallback_get_requested_language(mocker): +def test_fallback_get_requested_language(mocker: MockFixture): request: Request = mocker.Mock() request.headers.get.return_value = "en" request.cookies = {} diff --git a/tests/services/test_projects_service.py b/tests/services/test_projects_service.py index 15993e14..8efc584e 100644 --- a/tests/services/test_projects_service.py +++ b/tests/services/test_projects_service.py @@ -5,10 +5,11 @@ from amt.services.instruments import InstrumentsService from amt.services.projects import ProjectsService from amt.services.tasks import TasksService +from pytest_mock import MockFixture from tests.constants import default_instrument -def test_get_project(mocker): +def test_get_project(mocker: MockFixture): # Given project_id = 1 project_name = "Project 1" @@ -32,7 +33,7 @@ def test_get_project(mocker): projects_service.repository.find_by_id.assert_called_once_with(project_id) # type: ignore -def test_create_project(mocker): +def test_create_project(mocker: MockFixture): project_id = 1 project_name = "Project 1" project_lifecycle = "development"